炜煌系列热敏微型打印机linux应用程序

  • V7_211855
    了解作者
  • 2.8KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-04-16 08:03
    上传日期
炜煌系列热敏微型打印机的ARM开发板的linux应用程序
print.rar
  • print.c
    11.1KB
内容介绍
/** * uart_test.c * * Copyright (C) 2007 Mengrz */ #include <stdio.h> /*标准输入输出定义*/ #include <unistd.h> /*Unix标准函数定义*/ #include <sys/types.h> /**/ #include <sys/stat.h> /**/ #include <fcntl.h> /*文件控制定义*/ #include <termios.h> /*PPSIX终端控制定义*/ #include <errno.h> /*错误号定义*/ #include <sys/ioctl.h> /** * @brief 设置串口通信速率 * @param fd 类型 int 打开串口的文件句柄 * @param speed 类型 int 串口速度 * @return void */ #define FALSE 1 #define TRUE 0 #define MAX_UART 5 //char *recchr="We received:\""; int speed_arr[] = { B921600, B460800, B230400, B115200, B57600, B38400, B19200, B9600, B4800, B2400, B1200, B300, B38400, B19200, B9600, B4800, B2400, B1200, B300, }; int name_arr[] = {921600, 460800, 230400, 115200, 57600, 38400, 19200, 9600, 4800, 2400, 1200, 300, 38400, 19200, 9600, 4800, 2400, 1200, 300, }; void set_speed(int fd, int speed) { int i; int status; struct termios Opt; tcgetattr(fd, &Opt); for ( i= 0; i < sizeof(speed_arr) / sizeof(int); i++) { if (speed == name_arr[i]) { tcflush(fd, TCIOFLUSH); cfsetispeed(&Opt, speed_arr[i]); cfsetospeed(&Opt, speed_arr[i]); status = tcsetattr(fd, TCSANOW, &Opt); if (status != 0) perror("tcsetattr fd1"); return; } tcflush(fd,TCIOFLUSH); } } /** * @brief 设置串口数据位,停止位和效验位 * @param fd 类型 int 打开的串口文件句柄* * @param databits 类型 int 数据位 取值 为 7 或者8* * @param stopbits 类型 int 停止位 取值为 1 或者2* * @param parity 类型 int 效验类型 取值为N,E,O,,S */ int set_Parity(int fd,int databits,int stopbits,int parity) { 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); } /** *@breif 打开串口 */ int OpenDev(char *Dev) { int fd = open( Dev, O_RDWR ); if (-1 == fd) { perror("Can't Open Serial Port"); return -1; } else return fd; } /** * @breif main() */ int main(int argc, char *argv[]) { int fd; int nread; int i,j,count = 0; char buff[512]; char dev[20]; static char mesg1[] = {'h','t','t','p',':','/','/','w','w','w','.','e','m', 'b','e','d','a','l','l','.','c','o','m',0x0D, 0X1C,0X26,0XD3,0XA2,0XB1,0XB4,0XB5,0XC2,0XBF,0XC6,0XBC,0XBC, 0XD3,0XD0,0XCF,0XDE,0XB9,0XAB,0XCB,0XBE,0X1C,0X2E,0X0D,0X0D,0X0D, 0x1B,0x31,0x00,0x0D,0x0D,0x0D,0X0D, 0x1B,0x4B,0x80,0x04, 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, 0X00,0X00,0X00,0X00,0X00,0X01,0X07,0X0F,0X0F,0X0F,0X0F,0X0F,0X0F,0X00,0X00,0X00, 0X00,0X09,0X0D,0X0D,0X0D,0X0D,0X0D,0X0D,0X0D,0X0D,0X0D,0X0D,0X0D,0X0D,0X0D,0X0D, 0X0D,0X0D,0X0D,0X0D,0X0D,0X0D,0X0D,0X0D,0X0D,0X0D,0X0D,0X0D,0X0D,0X0D,0X0D,0X0D, 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, 0X01,0X07,0X0F,0X3F,0X7F,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0X00,0X00,0X00, 0X00,0X93,0X93,0X93,0X93,0X93,0X93,0X93,0X93,0X93,0X93,0X93,0X92,0X90,0X90,0X90, 0X90,0X90,0X90,0X90,0X90,0X90,0X90,0X90,0X90,0X90,0X90,0X90,0X90,0X90,0X90,0X90, 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, 0X01,0X01,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, 0X00,0X00,0X00,0X00,0X00,0X00,0X01,0X01,0X01,0X00,0X00,0X00,0X00,0X00,0X00,0X00, 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, 0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X01,0X07,0X0F,0X3F,0XFF, 0XFF,0XFE,0XF8,0XF0,0XC0,0XDF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0X00,0X00,0X00, 0X00,0X26,0X66,0X66,0X66,0X66,0X66,0X66,0X66,0X66,0X66,0X66,0X26,0X06,0X06,0X06, 0X06,0X06,0X06,0X06,0X06,0X06,0X06,0X00,0X00,0X00,0X0F,0X0F,0X07,0X06,0X0C,0X0C, 0X0C,0X0E,0X0F,0X07,0X06,0X0C,0X0C,0X0C,0X0C,0X0E,0X0F,0X03,0X00,0X00,0X00,0X00, 0XFF,0XFF,0X07,0X06,0X1C,0X1C,0X1C,0X0C,0X0E,0X07,0X01,0X00,0X00,0X00,0X00,0X03, 0X07,0X06,0X0C,0X1C,0X1C,0X1C,0X0C,0X0E,0X07,0X03,0X00,0X00,0X00,0X00,0X03,0X07, 0X0E,0X1C,0X1C,0X1C,0X0C,0X06,0XFF,0XFF,0XFF,0X00,0X00,0X00,0X00,0X00,0X00,0X00, 0X01,0X03,0X03,0X00,0X00,0X00,0X00,0X00,0X03,0X03,0X00,0X00,0X00,0X00,0X00,0X00, 0X00,0X00,0X00,0X00,0X00,0X00,0X01,0X01,0X01,0X01,0X01,0X01,0X01,0X01,0X01,0X01, 0X01,0X01,0X01,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X01,0X03,0X01,0X00, 0X00,0X00,0X00,0X00,0X00,0X03,0X03,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00, 0X00,0X00,0X00,0X00,0X00,0X00,0X01,0X07,0X1F,0X3F,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF, 0X3F,0X3F,0X3F,0X3F,0X3F,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0X00,0X00,0X00, 0X00,0XC9,0XCD,0XCD,0XCD,0XCD,0XCD,0XCD,0XCD,0XCD,0XCD,0XCD,0XC8,0XC0,0XC0,0XC0, 0XC0,0XC0,0XC0,0XC0,0XC0,0XC0,0XC0,0X00,0X00,0X00,0XFF,0XFF,0X00,0X00,0X00,0X00, 0X00,0X00,0XFF,0XFF,0X00,0X00,0X00,0X00,0X00,0X00,0XFF,0XFF,0X00,0X00,0X00,0X00, 0XFF,0XFF,0X07,0X03,0X01,0X01,0X01,0X03,0X07,0XFF,0XFC,0X00,0X00,0X00,0X60,0XFE, 0XFF,0XC7,0XC3,0XC1,0XC1,0XC1,0XC3,0XC3,0XC7,0XC6,0X00,0X00,0X00,0XF8,0XFE,0X8F, 0X03,0X01,0X01,0X01,0X01,0X03,0XDF,0XFF,0XFF,0X00,0X00,0X80,0XC0,0XC0,0XC3,0XC7, 0XC7,0XF6,0XE6,0XC6,0XDF,0XDF,0XCE,0XC6,0XF6,0XF6,0XC7,0XC7,0XC0,0XC0,0XC0,0X80, 0X00,0X00,0X00,0X00,0X00,0XFF,0XFF,0XFF,0X80,0X80,0X80,0X8F,0X9F,0X8F,0X80,0X80, 0XC0,0XFF,0XFF,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X30,0X73,0XE7,0X8F,0X18,0X00, 0XC0,0XDF,0X9B,0X91,0XFF,0XFF,0XF1,0X9B,0
评论
    相关推荐
    • Arm处理器开发
      文档包含基于cortex-a9和cortex-a8处理器的开发两个文档,对于学习arm开发有很大帮助
    • ARM开发 watchdog接口
      基于Arm S3c2410的WatchDog接口开发测试示例
    • arm开发指导文档
      arm开发指导文档arm开发指导文档
    • ARM 开发详解
      ARM开发详解》对于ARM初学者是个不错的一本书,我相信看了之后就懂
    • ARM开发详解
      ARM开发详解,看了便知,我就不多废话了
    • ARM7开发详解全集
      ARM开发详解全集ARM开发详解全集,很好的入门教程
    • arm开发案例
      里面有arm开发的各种基本案例跟开发板的资料
    • ARM开发导论
      这是同济大学的本科教学课程,详细的介绍了有关ARM开发所需要具备的一些基础知识,对新接触到ARM开发的新手很有帮助。
    • ARM开发详解
      一个很不错的ARM资料
    • ARM开发详解
      通过本章的阅读,可使读者了解ARM编程模型的基本知识,为进一步的开发做准备。 第三章:详细介绍ARM体系的指令系统和寻址方式,着重介绍32位的ARM指令集。16 位的Thumb指令集为32位ARM指令集的一个子集,在了解了...