user-0 提问: 串口打印程序

回复:
user: user-0
content: 引用 10 楼 zhao4zhong1 的回复: EXAMPLES    Writing from a Buffer The following example writes data from the buffer pointed to by buf to the file associated with the file descriptor fd.     #include <sys/types.h> #include <string.h> ... char buf[20]; size_t nbytes; ssize_t bytes_written; int fd; ... strcpy(buf, "This is a test\n"); nbytes = strlen(buf);   bytes_written = write(fd, buf, nbytes); ...    再次表示感谢，我得先好好研究一下代码，谢谢您花时间来解答我的问题

user: user-1
content: EXAMPLES    Writing from a Buffer The following example writes data from the buffer pointed to by buf to the file associated with the file descriptor fd.     #include <sys/types.h> #include <string.h> ... char buf[20]; size_t nbytes; ssize_t bytes_written; int fd; ... strcpy(buf, "This is a test\n"); nbytes = strlen(buf);   bytes_written = write(fd, buf, nbytes); ...

user: user-1
content: read改成write即可。 WRITE Section: Linux Programmer's Manual (2) Updated: 2001-12-13  --------------------------------------------------------------------------------    NAME write - write to a file descriptor    SYNOPSIS #include <unistd.h>  ssize_t write(int fd, const void *buf, size_t count);     DESCRIPTION write writes up to count bytes to the file referenced by the file descriptor fd from the buffer starting at buf. POSIX requires that a read() which can be proved to occur after a write() has returned returns the new data. Note that not all file systems are POSIX conforming.    RETURN VALUE On success, the number of bytes written are returned (zero indicates nothing was written). On error, -1 is returned, and errno is set appropriately. If count is zero and the file descriptor refers to a regular file, 0 will be returned without causing any other effect. For a special file, the results are not portable.    ERRORS EAGAIN  Non-blocking I/O has been selected using O_NONBLOCK and the write would block.  EBADF  fd is not a valid file descriptor or is not open for writing.  EFAULT  buf is outside your accessible address space.  EFBIG  An attempt was made to write a file that exceeds the implementation-defined maximum file size or the process' file size limit, or to write at a position past than the maximum allowed offset.  EINTR  The call was interrupted by a signal before any data was written.  EINVAL  fd is attached to an object which is unsuitable for writing.  EIO  A low-level I/O error occurred while modifying the inode.  ENOSPC  The device containing the file referred to by fd has no room for the data.  EPIPE  fd is connected to a pipe or socket whose reading end is closed. When this happens the writing process will also receive a SIGPIPE signal. (Thus, the write return value is seen only if the program catches, blocks or ignores this signal.)  Other errors may occur, depending on the object connected to fd.     CONFORMING TO SVr4, SVID, POSIX, X/OPEN, 4.3BSD. SVr4 documents additional error conditions EDEADLK, ENOLCK, ENOLNK, ENOSR, ENXIO, or ERANGE. Under SVr4 a write may be interrupted and return EINTR at any point, not just before any data is written.    NOTES A successful return from write does not make any guarantee that data has been committed to disk. In fact, on some buggy implementations, it does not even guarantee that space has successfully been reserved for the data. The only way to be sure is to call fsync(2) after you are done writing all your data.    SEE ALSO close(2), fcntl(2), fsync(2), ioctl(2), lseek(2), open(2), read(2), select(2), fwrite(3), writev(3)  --------------------------------------------------------------------------------

user: user-0
content: 引用 7 楼 dailulu13 的回复:[quote=引用 5 楼 zhao4zhong1 的回复:] 没看到你说已经有汉字集了。 仅供参考：#include     <stdio.h>      /*标准输入输出定义*/ #include     <stdlib.h>     /*标准函数库定义*/ #include     <unistd.h>     /*Unix标准函数定义*/ #include     <sys/types.h>  /**/ #include     <sys/stat.h>   /**/ #include     <fcntl.h>      /*文件控制定义*/ #include     <termios.h>    /*PPSIX终端控制定义*/ #include     <errno.h>      /*错误号定义*/ int name_arr[]={B0,B50,B75,B110,B134,B150,B200,B300,B600,B1200,B1800,B2400,B4800,B9600,B19200,B38400,B57600,B115200,B230400}; int speed_arr[]={0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400}; void set_speed(int fd, int speed) {//设置串口通信速率。fd-打开串口的文件句柄;speed-串口速度     int             i;     int             status;     struct termios  Opt;      tcgetattr(fd, &Opt);     for (i=0;i<sizeof(speed_arr)/sizeof(int);i++) {         if  (speed==speed_arr[i]) {             tcflush(fd, TCIOFLUSH);             cfsetispeed(&Opt, name_arr[i]);             cfsetospeed(&Opt, name_arr[i]);             status = tcsetattr(fd, TCSANOW, &Opt);             if  (status != 0) perror("tcsetattr fd1");             return;         }         tcflush(fd,TCIOFLUSH);     } } int set_Parity(int fd,int databits,int stopbits,int parity) {//设置串口数据位，停止位和效验位。fd-打开的串口文件句柄;databits-数据位,取值为7或者8;stopbits-停止位,取值为1或者2;parity-效验类型,取值为N,E,O,,S     struct termios options;      if  (tcgetattr(fd,&options)!=0) {         perror("SetupSerial 1");         return(FALSE);     }     options.c_cflag &= ~CSIZE;     switch (databits) {/*设置数据位数*/     case 7:         options.c_cflag |= CS7;     break;     case 8:         options.c_cflag |= CS8;     break;     default:         fprintf(stderr,"Unsupported data size\n");         return (FALSE);     }     switch (parity) {     case 'n':     case 'N':         options.c_cflag &= ~PARENB;     /* Clear parity enable */         options.c_iflag &= ~INPCK;      /* Enable parity checking */     break;     case 'o':     case 'O':         options.c_cflag |= (PARODD | PARENB);   /* 设置为奇效验*/         options.c_iflag |= INPCK;               /* Disnable parity checking */     break;     case 'e':     case 'E':         options.c_cflag |= PARENB;      /* Enable parity */         options.c_cflag &= ~PARODD;     /* 转换为偶效验*/         options.c_iflag |= INPCK;       /* Disnable parity checking */     break;     case 'S':     case 's':  /*as no parity*/         options.c_cflag &= ~PARENB;         options.c_cflag &= ~CSTOPB;     break;     default:         fprintf(stderr,"Unsupported parity\n");         return (FALSE);     }     switch (stopbits) {/* 设置停止位*/     case 1:         options.c_cflag &= ~CSTOPB;     break;     case 2:         options.c_cflag |= CSTOPB;     break;     default:         fprintf(stderr,"Unsupported stop bits\n");         return (FALSE);     }     /* Set input parity option */     if (parity != 'n') options.c_iflag |= INPCK;     options.c_cc[VTIME] = 150; // 15 seconds     options.c_cc[VMIN] = 0;      tcflush(fd,TCIFLUSH); /* Update the options and do it NOW */     if (tcsetattr(fd,TCSANOW,&options) != 0) {         perror("SetupSerial 3");         return (FALSE);     }     return (TRUE); } int OpenDev(char *Dev) {     int fd = open( Dev, O_RDWR );         //| O_NOCTTY | O_NDELAY     if (-1 == fd) { /*设置数据位数*/         perror("Can't Open Serial Port");         return -1;     } else {         return fd;     } } int main(int argc, char **argv) {     int     fd;     int     nread;     char    buff[512];     char   *dev ="/dev/ttyS1";      fd = OpenDev(dev);     if (fd>0) {         set_speed(fd,115200);     } else {         printf("Can't Open Serial Port!\n");         exit(0);     }     if (set_Parity(fd,8,1,'N')== FALSE) {         printf("Set Parity Error\n");         exit(1);     }     while(1) {         while ((nread = read(fd,buff,512))>0) {             printf("\nLen %d\n",nread);             buff[nread+1]='\0';             printf("\n%s",buff);         }     } //  close(fd); //  exit(0); }  打印机里面有汉字集，我现在就是要把控制打印机的指令发送过去，ASCII码形式的，十六进制也行

user: user-0
content: 引用 5 楼 zhao4zhong1 的回复:没看到你说已经有汉字集了。 仅供参考：#include     <stdio.h>      /*标准输入输出定义*/ #include     <stdlib.h>     /*标准函数库定义*/ #include     <unistd.h>     /*Unix标准函数定义*/ #include     <sys/types.h>  /**/ #include     <sys/stat.h>   /**/ #include     <fcntl.h>      /*文件控制定义*/ #include     <termios.h>    /*PPSIX终端控制定义*/ #include     <errno.h>      /*错误号定义*/ int name_arr[]={B0,B50,B75,B110,B134,B150,B200,B300,B600,B1200,B1800,B2400,B4800,B9600,B19200,B38400,B57600,B115200,B230400}; int speed_arr[]={0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400}; void set_speed(int fd, int speed) {//设置串口通信速率。fd-打开串口的文件句柄;speed-串口速度     int             i;     int             status;     struct termios  Opt;      tcgetattr(fd, &Opt);     for (i=0;i<sizeof(speed_arr)/sizeof(int);i++) {         if  (speed==speed_arr[i]) {             tcflush(fd, TCIOFLUSH);             cfsetispeed(&Opt, name_arr[i]);             cfsetospeed(&Opt, name_arr[i]);             status = tcsetattr(fd, TCSANOW, &Opt);             if  (status != 0) perror("tcsetattr fd1");             return;         }         tcflush(fd,TCIOFLUSH);     } } int set_Parity(int fd,int databits,int stopbits,int parity) {//设置串口数据位，停止位和效验位。fd-打开的串口文件句柄;databits-数据位,取值为7或者8;stopbits-停止位,取值为1或者2;parity-效验类型,取值为N,E,O,,S     struct termios options;      if  (tcgetattr(fd,&options)!=0) {         perror("SetupSerial 1");         return(FALSE);     }     options.c_cflag &= ~CSIZE;     switch (databits) {/*设置数据位数*/     case 7:         options.c_cflag |= CS7;     break;     case 8:         options.c_cflag |= CS8;     break;     default:         fprintf(stderr,"Unsupported data size\n");         return (FALSE);     }     switch (parity) {     case 'n':     case 'N':         options.c_cflag &= ~PARENB;     /* Clear parity enable */         options.c_iflag &= ~INPCK;      /* Enable parity checking */     break;     case 'o':     case 'O':         options.c_cflag |= (PARODD | PARENB);   /* 设置为奇效验*/         options.c_iflag |= INPCK;               /* Disnable parity checking */     break;     case 'e':     case 'E':         options.c_cflag |= PARENB;      /* Enable parity */         options.c_cflag &= ~PARODD;     /* 转换为偶效验*/         options.c_iflag |= INPCK;       /* Disnable parity checking */     break;     case 'S':     case 's':  /*as no parity*/         options.c_cflag &= ~PARENB;         options.c_cflag &= ~CSTOPB;     break;     default:         fprintf(stderr,"Unsupported parity\n");         return (FALSE);     }     switch (stopbits) {/* 设置停止位*/     case 1:         options.c_cflag &= ~CSTOPB;     break;     case 2:         options.c_cflag |= CSTOPB;     break;     default:         fprintf(stderr,"Unsupported stop bits\n");         return (FALSE);     }     /* Set input parity option */     if (parity != 'n') options.c_iflag |= INPCK;     options.c_cc[VTIME] = 150; // 15 seconds     options.c_cc[VMIN] = 0;      tcflush(fd,TCIFLUSH); /* Update the options and do it NOW */     if (tcsetattr(fd,TCSANOW,&options) != 0) {         perror("SetupSerial 3");         return (FALSE);     }     return (TRUE); } int OpenDev(char *Dev) {     int fd = open( Dev, O_RDWR );         //| O_NOCTTY | O_NDELAY     if (-1 == fd) { /*设置数据位数*/         perror("Can't Open Serial Port");         return -1;     } else {         return fd;     } } int main(int argc, char **argv) {     int     fd;     int     nread;     char    buff[512];     char   *dev ="/dev/ttyS1";      fd = OpenDev(dev);     if (fd>0) {         set_speed(fd,115200);     } else {         printf("Can't Open Serial Port!\n");         exit(0);     }     if (set_Parity(fd,8,1,'N')== FALSE) {         printf("Set Parity Error\n");         exit(1);     }     while(1) {         while ((nread = read(fd,buff,512))>0) {             printf("\nLen %d\n",nread);             buff[nread+1]='\0';             printf("\n%s",buff);         }     } //  close(fd); //  exit(0); }  非常感谢

user: user-1
content: 搜“Linux下串口编程入门”

user: user-1
content: 没看到你说已经有汉字集了。 仅供参考：#include     <stdio.h>      /*标准输入输出定义*/ #include     <stdlib.h>     /*标准函数库定义*/ #include     <unistd.h>     /*Unix标准函数定义*/ #include     <sys/types.h>  /**/ #include     <sys/stat.h>   /**/ #include     <fcntl.h>      /*文件控制定义*/ #include     <termios.h>    /*PPSIX终端控制定义*/ #include     <errno.h>      /*错误号定义*/ int name_arr[]={B0,B50,B75,B110,B134,B150,B200,B300,B600,B1200,B1800,B2400,B4800,B9600,B19200,B38400,B57600,B115200,B230400}; int speed_arr[]={0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400}; void set_speed(int fd, int speed) {//设置串口通信速率。fd-打开串口的文件句柄;speed-串口速度     int             i;     int             status;     struct termios  Opt;      tcgetattr(fd, &Opt);     for (i=0;i<sizeof(speed_arr)/sizeof(int);i++) {         if  (speed==speed_arr[i]) {             tcflush(fd, TCIOFLUSH);             cfsetispeed(&Opt, name_arr[i]);             cfsetospeed(&Opt, name_arr[i]);             status = tcsetattr(fd, TCSANOW, &Opt);             if  (status != 0) perror("tcsetattr fd1");             return;         }         tcflush(fd,TCIOFLUSH);     } } int set_Parity(int fd,int databits,int stopbits,int parity) {//设置串口数据位，停止位和效验位。fd-打开的串口文件句柄;databits-数据位,取值为7或者8;stopbits-停止位,取值为1或者2;parity-效验类型,取值为N,E,O,,S     struct termios options;      if  (tcgetattr(fd,&options)!=0) {         perror("SetupSerial 1");         return(FALSE);     }     options.c_cflag &= ~CSIZE;     switch (databits) {/*设置数据位数*/     case 7:         options.c_cflag |= CS7;     break;     case 8:         options.c_cflag |= CS8;     break;     default:         fprintf(stderr,"Unsupported data size\n");         return (FALSE);     }     switch (parity) {     case 'n':     case 'N':         options.c_cflag &= ~PARENB;     /* Clear parity enable */         options.c_iflag &= ~INPCK;      /* Enable parity checking */     break;     case 'o':     case 'O':         options.c_cflag |= (PARODD | PARENB);   /* 设置为奇效验*/         options.c_iflag |= INPCK;               /* Disnable parity checking */     break;     case 'e':     case 'E':         options.c_cflag |= PARENB;      /* Enable parity */         options.c_cflag &= ~PARODD;     /* 转换为偶效验*/         options.c_iflag |= INPCK;       /* Disnable parity checking */     break;     case 'S':     case 's':  /*as no parity*/         options.c_cflag &= ~PARENB;         options.c_cflag &= ~CSTOPB;     break;     default:         fprintf(stderr,"Unsupported parity\n");         return (FALSE);     }     switch (stopbits) {/* 设置停止位*/     case 1:         options.c_cflag &= ~CSTOPB;     break;     case 2:         options.c_cflag |= CSTOPB;     break;     default:         fprintf(stderr,"Unsupported stop bits\n");         return (FALSE);     }     /* Set input parity option */     if (parity != 'n') options.c_iflag |= INPCK;     options.c_cc[VTIME] = 150; // 15 seconds     options.c_cc[VMIN] = 0;      tcflush(fd,TCIFLUSH); /* Update the options and do it NOW */     if (tcsetattr(fd,TCSANOW,&options) != 0) {         perror("SetupSerial 3");         return (FALSE);     }     return (TRUE); } int OpenDev(char *Dev) {     int fd = open( Dev, O_RDWR );         //| O_NOCTTY | O_NDELAY     if (-1 == fd) { /*设置数据位数*/         perror("Can't Open Serial Port");         return -1;     } else {         return fd;     } } int main(int argc, char **argv) {     int     fd;     int     nread;     char    buff[512];     char   *dev ="/dev/ttyS1";      fd = OpenDev(dev);     if (fd>0) {         set_speed(fd,115200);     } else {         printf("Can't Open Serial Port!\n");         exit(0);     }     if (set_Parity(fd,8,1,'N')== FALSE) {         printf("Set Parity Error\n");         exit(1);     }     while(1) {         while ((nread = read(fd,buff,512))>0) {             printf("\nLen %d\n",nread);             buff[nread+1]='\0';             printf("\n%s",buff);         }     } //  close(fd); //  exit(0); }

user: user-0
content: 引用 3 楼 zhao4zhong1 的回复:[quote=引用 2 楼 dailulu13 的回复:] [quote=引用 1 楼 lgbxyz 的回复:] 这是 驱动 干的事, 所以得先了解这个打印机的驱动, 或许驱动是共通性的,那你也得了解 打印的通信流程  就是没有linux下的驱动，我想通过串口来打印，可是不知道怎么控制打印机打印出汉字来[/quote] 逐针控制。 仅供参考：#include <mem.h> #include <stdlib.h> #include <stdio.h> #include <conio.h> #include <graphics.h> const unsigned char bit[8]={128,64,32,16,8,4,2,1}; //-------------------------------------------------------- void dis(xoff,code) 	unsigned int xoff,code; { 	unsigned char *buffer; 	FILE *hzk; 	unsigned long offset; 	unsigned int q,w; 	int	x,y,width;  	buffer=calloc(32,1); 	if ((code&0xFF00)!=0) { 		w=(code&0x00FF)-0xA1; 		q=((code>>8)&0x00FF)-0xA1; 		offset=q*0x5E+w; 		offset*=32; 		if ((hzk=fopen("HZK16","rb"))==NULL) { 			closegraph(); 			printf("Can not open HZK16\r\n"); 			exit(1); 		} 		fseek(hzk,offset,SEEK_SET); 		fread(buffer,1,32,hzk); 		fclose(hzk); 		width=2; 	} 	else { 		if ((hzk=fopen("ASC16","rb"))==NULL) { 			closegraph(); 			printf("Can not open ASC16\r\n"); 			exit(1); 		} 		offset=code*16; 		fseek(hzk,offset,SEEK_SET); 		fread(buffer,1,16,hzk); 		fclose(hzk); 		width=1; 	} 	for	(y=0;y<16;y++) for (x=0;x<8*width;x++) { 		if (buffer[y*width+x/8]&bit[x%8]) putpixel(xoff+x,y,15); 	} 	free(buffer); } //-------------------------------------------------------- void display(p) 	unsigned char *p; {    int i;   unsigned int qw;    i=0;   while (1) { 	if (p[i]==0x0D||p[i]==0x1A)	break; 	if (p[i]>0xA0) { 		qw=((unsigned int)p[i]<<8)|((unsigned int)p[i+1]&0x00FF); 		dis(8*i,qw); 		i+=2; 	} 	else { 		qw=(unsigned int)p[i]&0x00FF; 		dis(8*i,qw); 		i++; 	}   }  } //-------------------------------------------------------- void main() { 	int	gdriver	= DETECT, gmode, errorcode; 	long fl; 	FILE *hz; 	unsigned char *p;  	initgraph(&gdriver,	&gmode,	"c:\\borlandc\\bgi"); 	errorcode =	graphresult(); 	if (errorcode != grOk) { 	   printf("Graphics error: %s\n", grapherrormsg(errorcode)); 	   exit(1); 	} 	hz=fopen("hz","rb"); 	fseek(hz,0,SEEK_END); 	fl=ftell(hz); 	p=calloc((int)fl,sizeof(unsigned char)); 	rewind(hz); 	fread(p,1,(int)fl,hz); 	fclose(hz); 	display(p); 	free(p); 	getch(); 	closegraph(); } [/quote]  引用 3 楼 zhao4zhong1 的回复:[quote=引用 2 楼 dailulu13 的回复:] [quote=引用 1 楼 lgbxyz 的回复:] 这是 驱动 干的事, 所以得先了解这个打印机的驱动, 或许驱动是共通性的,那你也得了解 打印的通信流程  就是没有linux下的驱动，我想通过串口来打印，可是不知道怎么控制打印机打印出汉字来[/quote] 逐针控制。 仅供参考：#include <mem.h> #include <stdlib.h> #include <stdio.h> #include <conio.h> #include <graphics.h> const unsigned char bit[8]={128,64,32,16,8,4,2,1}; //-------------------------------------------------------- void dis(xoff,code) 	unsigned int xoff,code; { 	unsigned char *buffer; 	FILE *hzk; 	unsigned long offset; 	unsigned int q,w; 	int	x,y,width;  	buffer=calloc(32,1); 	if ((code&0xFF00)!=0) { 		w=(code&0x00FF)-0xA1; 		q=((code>>8)&0x00FF)-0xA1; 		offset=q*0x5E+w; 		offset*=32; 		if ((hzk=fopen("HZK16","rb"))==NULL) { 			closegraph(); 			printf("Can not open HZK16\r\n"); 			exit(1); 		} 		fseek(hzk,offset,SEEK_SET); 		fread(buffer,1,32,hzk); 		fclose(hzk); 		width=2; 	} 	else { 		if ((hzk=fopen("ASC16","rb"))==NULL) { 			closegraph(); 			printf("Can not open ASC16\r\n"); 			exit(1); 		} 		offset=code*16; 		fseek(hzk,offset,SEEK_SET); 		fread(buffer,1,16,hzk); 		fclose(hzk); 		width=1; 	} 	for	(y=0;y<16;y++) for (x=0;x<8*width;x++) { 		if (buffer[y*width+x/8]&bit[x%8]) putpixel(xoff+x,y,15); 	} 	free(buffer); } //-------------------------------------------------------- void display(p) 	unsigned char *p; {    int i;   unsigned int qw;    i=0;   while (1) { 	if (p[i]==0x0D||p[i]==0x1A)	break; 	if (p[i]>0xA0) { 		qw=((unsigned int)p[i]<<8)|((unsigned int)p[i+1]&0x00FF); 		dis(8*i,qw); 		i+=2; 	} 	else { 		qw=(unsigned int)p[i]&0x00FF; 		dis(8*i,qw); 		i++; 	}   }  } //-------------------------------------------------------- void main() { 	int	gdriver	= DETECT, gmode, errorcode; 	long fl; 	FILE *hz; 	unsigned char *p;  	initgraph(&gdriver,	&gmode,	"c:\\borlandc\\bgi"); 	errorcode =	graphresult(); 	if (errorcode != grOk) { 	   printf("Graphics error: %s\n", grapherrormsg(errorcode)); 	   exit(1); 	} 	hz=fopen("hz","rb"); 	fseek(hz,0,SEEK_END); 	fl=ftell(hz); 	p=calloc((int)fl,sizeof(unsigned char)); 	rewind(hz); 	fread(p,1,(int)fl,hz); 	fclose(hz); 	display(p); 	free(p); 	getch(); 	closegraph(); } [/quote] 非常感谢，代码有些不懂，能不能注解一下，谢谢了

user: user-1
content: 引用 2 楼 dailulu13 的回复:[quote=引用 1 楼 lgbxyz 的回复:] 这是 驱动 干的事, 所以得先了解这个打印机的驱动, 或许驱动是共通性的,那你也得了解 打印的通信流程  就是没有linux下的驱动，我想通过串口来打印，可是不知道怎么控制打印机打印出汉字来[/quote] 逐针控制。 仅供参考：#include <mem.h> #include <stdlib.h> #include <stdio.h> #include <conio.h> #include <graphics.h> const unsigned char bit[8]={128,64,32,16,8,4,2,1}; //-------------------------------------------------------- void dis(xoff,code) 	unsigned int xoff,code; { 	unsigned char *buffer; 	FILE *hzk; 	unsigned long offset; 	unsigned int q,w; 	int	x,y,width;  	buffer=calloc(32,1); 	if ((code&0xFF00)!=0) { 		w=(code&0x00FF)-0xA1; 		q=((code>>8)&0x00FF)-0xA1; 		offset=q*0x5E+w; 		offset*=32; 		if ((hzk=fopen("HZK16","rb"))==NULL) { 			closegraph(); 			printf("Can not open HZK16\r\n"); 			exit(1); 		} 		fseek(hzk,offset,SEEK_SET); 		fread(buffer,1,32,hzk); 		fclose(hzk); 		width=2; 	} 	else { 		if ((hzk=fopen("ASC16","rb"))==NULL) { 			closegraph(); 			printf("Can not open ASC16\r\n"); 			exit(1); 		} 		offset=code*16; 		fseek(hzk,offset,SEEK_SET); 		fread(buffer,1,16,hzk); 		fclose(hzk); 		width=1; 	} 	for	(y=0;y<16;y++) for (x=0;x<8*width;x++) { 		if (buffer[y*width+x/8]&bit[x%8]) putpixel(xoff+x,y,15); 	} 	free(buffer); } //-------------------------------------------------------- void display(p) 	unsigned char *p; {    int i;   unsigned int qw;    i=0;   while (1) { 	if (p[i]==0x0D||p[i]==0x1A)	break; 	if (p[i]>0xA0) { 		qw=((unsigned int)p[i]<<8)|((unsigned int)p[i+1]&0x00FF); 		dis(8*i,qw); 		i+=2; 	} 	else { 		qw=(unsigned int)p[i]&0x00FF; 		dis(8*i,qw); 		i++; 	}   }  } //-------------------------------------------------------- void main() { 	int	gdriver	= DETECT, gmode, errorcode; 	long fl; 	FILE *hz; 	unsigned char *p;  	initgraph(&gdriver,	&gmode,	"c:\\borlandc\\bgi"); 	errorcode =	graphresult(); 	if (errorcode != grOk) { 	   printf("Graphics error: %s\n", grapherrormsg(errorcode)); 	   exit(1); 	} 	hz=fopen("hz","rb"); 	fseek(hz,0,SEEK_END); 	fl=ftell(hz); 	p=calloc((int)fl,sizeof(unsigned char)); 	rewind(hz); 	fread(p,1,(int)fl,hz); 	fclose(hz); 	display(p); 	free(p); 	getch(); 	closegraph(); }

user: user-0
content: 引用 1 楼 lgbxyz 的回复:这是 驱动 干的事, 所以得先了解这个打印机的驱动, 或许驱动是共通性的,那你也得了解 打印的通信流程  就是没有linux下的驱动，我想通过串口来打印，可是不知道怎么控制打印机打印出汉字来

user: user-2
content: 这是 驱动 干的事, 所以得先了解这个打印机的驱动, 或许驱动是共通性的,那你也得了解 打印的通信流程