Commit 5610b6fa by guanghui.cui

所有订单打印

parent 61dc935d
......@@ -111,6 +111,9 @@ private:
//上菜单打印
void printMenu(const OrderObject *obj);
//收银账单打印
void printBill(const OrderObject *obj);
//上菜单打印
QString getPrintTitle(const QString& channel,int index);
......
......@@ -2,7 +2,7 @@
#define _FMSPOSDLL_H_
int open_port(const char* szPort);
void close_port();
void set_port(int fd,int Baudrate);
bool set_port(int Baudrate);
void cut_paper();
//---------------------------------------------
......
......@@ -13,9 +13,8 @@ int g_Handle=INVALID_HANDLE_VALUE;
int g_uBaudrate=0;
int open_port(const char* szPort)
{
int fd; /* 端口文件描述符 */
if(g_Handle != INVALID_HANDLE_VALUE)
close(g_Handle);
//if(g_Handle != INVALID_HANDLE_VALUE)
// close(g_Handle);
g_Handle= open(szPort, O_RDWR | O_NOCTTY | O_NDELAY);
if (g_Handle == INVALID_HANDLE_VALUE)
......@@ -25,14 +24,14 @@ int open_port(const char* szPort)
return (g_Handle);
}
void set_port(int fd,int Baudrate)
bool set_port(int Baudrate)
{
struct termios options;
int flag;
tcgetattr(fd, &options);
tcgetattr(g_Handle, &options);
fcntl(fd, F_SETFL, 0);
fcntl(g_Handle, F_SETFL, 0);
if(9600==Baudrate)
g_uBaudrate=B9600;
......@@ -59,20 +58,38 @@ void set_port(int fd,int Baudrate)
options.c_cc[VMIN] = 0;
options.c_cc[VTIME] = 1;
flag = tcsetattr(fd, TCSANOW, &options);
flag = tcsetattr(g_Handle, TCSANOW, &options);
if (flag < 0)
{
perror("set_port: Setting port /dev/ttyS0 error - ");
printf("setting port error\n");
}
//test
char strCutPaper[] = "\x10\x04\x01\x00"; //打印机状态指令,如果打印机正常,返回长度为1 否则为0
write(g_Handle, &strCutPaper, 4);
//sleep(1);
char temp[3]={0};
int recvLen=read(g_Handle,temp,3);
temp[recvLen]='\0';
printf("-----length:%d recv:%d\n",recvLen,temp[0]);
if(0==recvLen){
tcflush(g_Handle,TCIOFLUSH); //清空终端未完成的输入/输出请求及数据
close_port();
return false;
}
return true;
}
void close_port()
{
if (g_Handle != INVALID_HANDLE_VALUE)
{
sleep(1);
int res = tcflush(g_Handle,TCIOFLUSH);
close(g_Handle);
sleep(2);
// int res = tcflush(g_Handle,TCIOFLUSH);
printf("close begin\n");
close(g_Handle);
printf("close end\n");
g_Handle=INVALID_HANDLE_VALUE;
g_uBaudrate=0;
}
......@@ -86,7 +103,7 @@ void cut_paper()
write(g_Handle, &strCutPaper, 9);
}
void print(char *data,int type)
void print(const char *data,int type)
{
printf("data:%s\n",data);
char *str = (char *)malloc(1024);
......@@ -111,7 +128,7 @@ void print(char *data,int type)
else{
strcpy(str,"\x1B\x40");
strcat(str,"\x1D\x21\x11");
//strcat(str,"\x1B\x21\x30");
//strcat(str,"\x1B\x21\x38");
strcat(str,data);
}
}
......@@ -125,13 +142,41 @@ void print(char *data,int type)
}
else{
strcpy(str,"\x1B\x40");
strcat(str,"\x1C\x57\x01");
strcat(str,"\x1C\x57\x11");
strcat(str,"\x1B\x21\x38");
strcat(str,data);
}
}
else if(5==type){
if(B9600==g_uBaudrate){
strcpy(str,"\x1B\x40\x1B\x21\x00\x1B\x33\x18\x1B\x52\x00\x1B\x63\x34\x05");
strcat(str," \x1C\x57\x01");
strcat(str,"\x1B\x21\x10");
strcat(str,data);
}
else{
strcpy(str,"\x1B\x40");
strcat(str,"\x1D\x21\x01");
strcat(str,data);
}
}
else if(6==type){
if(B9600==g_uBaudrate){
strcpy(str,"\x1B\x40\x1B\x21\x00\x1B\x33\x18\x1B\x52\x00\x1B\x63\x34\x05");
strcat(str," \x1C\x57\x01");
strcat(str,"\x1B\x21\x18");
strcat(str,data);
}
else{
strcpy(str,"\x1B\x40");
strcat(str,"\x1D\x21\x01");
strcat(str,"\x1B\x21\x38");
strcat(str,data);
}
}
else if(7==type){
if(B9600==g_uBaudrate){
strcpy(str,"\x1B\x40");
strcat(str," \x1C\x57\x01");
strcat(str,"\x1B\x21\x38");
......@@ -143,7 +188,7 @@ void print(char *data,int type)
strcat(str,data);
}
}
else if(6==type){
else if(8==type){
if(B9600==g_uBaudrate){
strcpy(str,"\x1B\x40");
strcat(str,"\x1C\x57\x01");
......@@ -167,9 +212,10 @@ void print(char *data,int type)
//strcpy(str,data);
//strcat(str," thanks");
strcat(str," \x0A\x0D");
printf("str is:%s\n",str);
//printf("str is:%s\n",str);
printf("str length:%d\n",strlen(str));
write(g_Handle, str, strlen(str));
int res = write(g_Handle, str, strlen(str));
printf("write result:%d\n",res);
free(str);
}
......
......@@ -2,7 +2,7 @@
#define _FMSPOSDLL_H_
int open_port(const char* szPort);
void close_port();
void set_port(int fd,int Baudrate);
bool set_port(int Baudrate);
void cut_paper();
//---------------------------------------------
......@@ -13,8 +13,10 @@ void cut_paper();
// 2、标准加粗
// 3、两倍宽高
// 4、两倍宽高,加粗
// 5、三倍宽高
// 6、三倍宽高,加粗,红色
// 5、两倍高
// 6、两倍高,加粗
// 7、三倍宽高
// 8、三倍宽高,加粗,红色
//---------------------------------------------
void print(char *data,int type);
void print(const char *data,int type);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment