贴下我的程序,麻烦高手看下:
int fd;
char run[]="\x1b\x40This is a test for printer,I hope this test will be success:) ";
struct termios newtio,oldtio;
if((fd=open( "/dev/tts/0", O_RDWR)<0))
perror("open_port error");
else
// printf("open success"); //// open the serio
if ( tcgetattr( fd,&oldtio) != 0) {
perror("SetupSerial 1");
//return -1;
} ///save the former seri
bzero( &newtio, sizeof( newtio ) );
newtio.c_cflag |= CLOCAL | CREAD;
newtio.c_cflag &= ~CSIZE;
newtio.c_cflag |= CS8;
newtio.c_cflag |= B9600;
newtio.c_cflag &= ~PARENB;
newtio.c_cflag &= ~CSTOPB;
cfsetispeed(&newtio, B9600);
cfsetospeed(&newtio, B9600);
newtio.c_cc[VTIME] = 0;
newtio.c_cc[VMIN] = 1;
tcflush(fd,TCIFLUSH);
if((tcsetattr(fd,TCSANOW,&newtio))!=0)
{
perror("com set error");
}
// printf("set done!\n"); ////// set the serio
write(fd,run,(sizeof(run)-1));
// write(fd,qie,(sizeof(qie)-1));
// tcflush(fd,TCOFLUSH);
tcsetattr(fd,TCSANOW,&oldtio);
::close(fd);