- /*
- 适用8300版本
- M/D : 2007.5.14
- KNL : 8300K-3.23
- LIB : 8300L-2.21
- */
- #include <8300lib.h>
- #include <ucos.h>
- #include <stdlib.h>
- #define BYTE unsigned char
- #define BOOL unsigned char
- #define ULONG unsigned long
- #define TRUE 1
- #define FALSE 0
- #define CANCEL 2
- #define Ymax 5
- #define Xmax 20
- static char *ACK = "ACK/r";
- static char *NAK = "NAK/r";
- int beep1[4] = {16, 5, 0, 0};
- int beep2[8] = {30, 10, 0, 5, 30, 10, 0, 0};
- int beep3[8] = {30, 50, 0, 5, 30, 50, 0, 0};
- int beep4[4] = {30, 150, 0, 0};
- //************************VAR***********************************#define NULL 0x00*******//
- //void flip_page(char page[][Xmax], int rowcount); //将page中的内容显示出来,按UP、DOWN键上、下翻动
- int InputData(char* databuf, int maxbit, int x, int y); //数据采集
- int InputData2(char* databuf, int maxbit, int x, int y);
- void backlight(); //设置背光
- int bklt_flag = 0;
- static BOOL ConnectingPage (void); //联接等待界面
- //BOOL DownloadLookup (char* filename, int record_len, int key_offset, int key_len);
- // //数据下载到filename中,记录长度为record_len,索引开始位置为key_offset,长度为key_len
- BOOL UploadDBF (int fDbf); //数据上传
- void record_save(char* record, char* filename);
- void shangchuan(void);
- void ntos(char ns[], long n, unsigned count);
- char date[11];
- char time[11];
- /*-----------函数声明--------------------*/
- void Login(void); //登陆界面
- void MainMenu(void); //主菜单
- void getDatetime(void); //登陆界面显示的时间
- void SetClock(void); //设置时间
- void scan_barcode(void);//扫描条码
- void transmit(void); //传输
- void del_data(void); //清除
- void caiji(void);
- int caiji2(void);
- void chaxun(void);//查询删除
- void chaxun2(void);
- void xiugai(void);//修改
- /*-----------变量------------------------*/
- char riqi[9];//日期
- char chehao[5];//车号
- char zuhao[5];//组号
- char xuhao[4];//序号
- char kunhao[17];//捆号
- char zhongliang[11];//重量
- char all[46];
- int connect_port =0;
- /*******************************************************************/
- void main()
- {
- //SetFont(FONT_6X8);
- SetFont(FONT_6X12);
- SetVideoMode(0);
- SetCursor(0);
- while(1)
- {
- Login(); /*登录界面*/
- MainMenu(); /*应用功能菜单*/
- }
- }
- void Login(void)
- {
- while(1)
- {
- clr_scr();
- gotoxy(0,1);
- printf("铝锭条码离线扫描系统");
- gotoxy(0,3);
- printf(" 版本V1.0.0 ");
- gotoxy(0,4);
- getDatetime();
- printf(" %s",date);
- OSTimeDly (300);
- on_beeper (beep4);
- return;
- }
- }
- void MainMenu(void)
- {
- int ret,f_hd;
- char key;
- if (!access("DATA"))
- {
- f_hd = create_DBF ("DATA", 45);
- create_index (f_hd, 1, 0, 12);
- create_index (f_hd, 2, 0, 16);
- create_index (f_hd, 3, 0, 19);
- close_DBF(f_hd);
- }
- while(1)
- {
- clr_scr();
- gotoxy(0,1);
- printf(" 1 数据采集 ");
- gotoxy(0,2);
- printf(" 2 删除修改 ");
- gotoxy(0,3);
- printf(" 3 资料上传 ");
- for (;!kbhit(););
- switch (key = getchar())
- {
- case KEY_F7: backlight();break;
- case '1': caiji();break;
- case '2': chaxun();break;
- //case '3': xiugai();break;
- case '3': shangchuan();break;
- case KEY_ESC: return;
- }
- }
- }
- void chaxun(void)
- {
- int ret1,ret2,ret3,ret4,i;
- char riqi1[9],chehao1[5],zuhao1[5];
- while(1)
- {
- memset(riqi,' ',9);
- riqi[8] = 0;
- memset(chehao,' ',5);
- chehao[4] = 0;
- memset(zuhao,' ',5);
- zuhao[4] = 0;
- clr_scr();
- gotoxy(0,0);
- printf("请输入:");
- gotoxy(0,1);
- printf("日期:%s",riqi);
- gotoxy(0,2);
- printf("车号:%s",chehao);
- gotoxy(0,3);
- printf("组号:%s",zuhao);
- for(;;)
- {
- memset(riqi1,0x00,9);
- memset(chehao1,0x00,5);
- memset(zuhao1,0x00,5);
- clr_scr();
- gotoxy(0,0);
- printf("请输入:");
- gotoxy(0,1);
- printf("日期:%s",riqi);
- gotoxy(0,2);
- printf("车号:%s",chehao);
- gotoxy(0,3);
- printf("组号:%s",zuhao);
- ret1 = InputData2(riqi1, 8, 5, 1);
- if (ret1 == 0)//没输入就按回车
- {
- memset(riqi1,' ',9);
- riqi1[8] = 0;
- continue;
- }
- if (ret1 == 1)//按ESC
- {
- return;
- }
- if (ret1 == 2)//正常
- {
- for(i=0;i<strlen(riqi1);i++)
- {
- riqi[i] = riqi1[i];
- }
- for(;;)
- {
- clr_scr();
- gotoxy(0,0);
- printf("请输入:");
- gotoxy(0,1);
- printf("日期:%s",riqi);
- gotoxy(0,2);
- printf("车号:%s",chehao);
- gotoxy(0,3);
- printf("组号:%s",zuhao);
- ret2 = InputData2(chehao1, 4, 5, 2);
- if (ret2 == 0)//没输入就按回车
- {
- memset(chehao1,' ',5);
- chehao1[4] = 0;
- continue;
- }
- if (ret2 == 1)//按ESC
- {
- return;
- }
- if (ret2 == 2)//正常
- {
- for(i=0;i<strlen(chehao1);i++)
- {
- chehao[i] = chehao1[i];
- }
- for(;;)
- {
- clr_scr();
- gotoxy(0,0);
- printf("请输入:");
- gotoxy(0,1);
- printf("日期:%s",riqi);
- gotoxy(0,2);
- printf("车号:%s",chehao);
- gotoxy(0,3);
- printf("组号:%s",zuhao);
- ret3 = InputData2(zuhao1, 4, 5, 3);
- if (ret3 == 0)//没输入就按回车
- {
- memset(zuhao1,' ',5);
- zuhao1[4] = 0;
- continue;
- }
- if (ret3 == 1)//按ESC
- {
- return;
- }
- if (ret3 == 2)//正常
- {
- for(i=0;i<strlen(zuhao1);i++)
- {
- zuhao[i] = zuhao1[i];
- }
- chaxun2();
- return;
- }
- }
- }
- }
- }
- }
- }
- }
- void chaxun2(void)
- {
- char rcz[17],buf[46],buf2[46];
- char xianshixuhao[4],xianshishuliang[4],xianshikunhao[17],xianshizhongliang[11];
- int zukunshu;
- int guangbiao;
- int i,n,j;
- int f_hd;
- char key;
- int temp1,temp2;
- int ret1,ret;
- char input1[17],input2[11],disinput1[17],disinput2[11];
- char temp3[4],temp4[4];
- memset(rcz,0x00,17);
- strcat(rcz,riqi);
- strcat(rcz,chehao);
- strcat(rcz,zuhao);
- /*-----------------初始化光标位置-------------------------*/
- f_hd = open_DBF((char *)"DATA");
- n = member_in_DBF (f_hd);
- for(i=0;i<n;i++)
- {
- memset(buf,0x00,46);
- lseek_DBF(f_hd, 2, i, 1);
- get_member(f_hd,2,(char*)buf);
- if(strncmp(buf,rcz,16) == 0)
- {
- guangbiao = i;
- break;
- }
- }
- close_DBF(f_hd);
- /*------------------------------- -------------------------*/
- for(;;)
- {
- /*--------------检测是否有数据---------------------------*/
- f_hd = open_DBF((char *)"DATA");
- if(has_member(f_hd,2,(char*)rcz) == 1)
- {
- close_DBF(f_hd);
- }
- else
- {
- close_DBF(f_hd);
- clr_scr();
- gotoxy(0,2);
- printf(" 无当前组号记录! ");
- OSTimeDly (300);
- return;
- }
- /*------------求相同组数量-----------------*/
- zukunshu = 0;
- memset(buf,0x00,46);
- f_hd = open_DBF((char *)"DATA");
- n = member_in_DBF (f_hd);
- for(i=0;i<n;i++)
- {
- memset(buf,0x00,46);
- lseek_DBF(f_hd, 2, i, 1);
- get_member(f_hd,2,(char*)buf);
- if(strncmp(buf,rcz,16) == 0)
- {
- zukunshu = zukunshu+1;
- }
- }
- close_DBF(f_hd);
- /*-----------移动到光标位置,取数据------------------*/
- f_hd = open_DBF((char *)"DATA");
- lseek_DBF(f_hd, 2, guangbiao, 1);
- memset(buf,0x00,46);
- get_member(f_hd,2,(char*)buf);
- memset(xianshixuhao,0x00,4);
- memset(xianshikunhao,0x00,17);
- memset(xianshizhongliang,0x00,11);
- for(i = 16;i<19;i++)
- {
- xianshixuhao[i-16] = buf[i];
- }
- for(i = 19;i<34;i++)
- {
- xianshikunhao[i-19] = buf[i];
- }
- for(i = 35;i<44;i++)
- {
- xianshizhongliang[i-35] = buf[i];
- }
- close_DBF(f_hd);
- clr_scr();
- gotoxy(0,0);
- printf("序号/组数量 ");
- gotoxy(13,0);
- printf("%s",xianshixuhao);
- gotoxy(16,0);
- printf("/%d",zukunshu);
- gotoxy(0,1);
- printf("%s",riqi);
- gotoxy(9,1);
- printf("%s",chehao);
- gotoxy(13,1);
- printf("%s",zuhao);
- gotoxy(0,2);
- printf("捆号:%s",xianshikunhao);
- gotoxy(0,3);
- printf("重量:%s",xianshizhongliang);
- gotoxy(0,4);
- printf("F1:删除 F3:修改");
- for (;!kbhit(););
- switch (key = getchar())
- {
- case KEY_F7: backlight();continue;
- case KEY_DOWN:
- {
- f_hd = open_DBF((char *)"DATA");
- n = member_in_DBF (f_hd);
- if (guangbiao<n)
- {
- lseek_DBF(f_hd, 2, guangbiao+1, 1);
- memset(buf,0x00,46);
- get_member(f_hd,2,(char*)buf);
- if(strncmp(buf,rcz,16) == 0)
- {
- guangbiao++;
- }
- }
- else
- {
- }
- close_DBF(f_hd);
- break;
- }
- case KEY_UP:
- {
- f_hd = open_DBF((char *)"DATA");
- n = member_in_DBF (f_hd);
- if (guangbiao>0)
- {
- lseek_DBF(f_hd, 2, guangbiao-1, 1);
- memset(buf,0x00,46);
- get_member(f_hd,2,(char*)buf);
- if(strncmp(buf,rcz,16) == 0)
- {
- guangbiao--;
- }
- }
- else
- {
- }
- close_DBF(f_hd);
- break;
- }
- case KEY_F1:
- {
- clr_scr();
- gotoxy(0,1);
- printf(" 是否删除当前数据? ");
- gotoxy(0,3);
- printf(" 1是 2否 ");
- for (;!kbhit(););
- switch (key = getchar())
- {
- case KEY_F7: backlight();continue;
- case '1': //1111
- {
- f_hd = open_DBF((char *)"DATA");
- lseek_DBF(f_hd, 2, guangbiao, 1);
- delete_member(f_hd,2);
- n = member_in_DBF (f_hd);
- for(i=0;i<n;i++)
- {
- lseek_DBF(f_hd, 2, i, 1);
- memset(buf,0x00,46);
- get_member(f_hd,2,(char*)buf);
- if(strncmp(buf,rcz,16) == 0)
- {
- memset(temp3,0x00,4);
- temp3[0] = buf[16];
- temp3[1] = buf[17];
- temp3[2] = buf[18];
- temp1 = atoi(temp3);
- temp2 = atoi(xianshixuhao);
- if(temp1>temp2)
- {
- temp1--;
- memset(temp3,0x00,4);
- itoa(temp1,(char*)temp3,10);
- memset(temp4,' ',4);
- temp4[3] = 0;
- for(j = 0;j<strlen(temp3);j++)
- {
- temp4[j] = temp3[j];
- }
- buf[16] = temp4[0];
- buf[17] = temp4[1];
- buf[18] = temp4[2];
- update_member(f_hd,2,(char*)buf);
- }
- }
- }
- close_DBF(f_hd);
- continue;
- }//case 1111
- case '2':continue;
- }
- }//case F_1
- case KEY_F3:
- {
- memset(disinput1,0x00,17);
- memset(disinput2,0x00,11);
- for(;;)
- {
- clr_scr();
- gotoxy(0,0);
- printf("%s",riqi);
- gotoxy(9,0);
- printf("%s",chehao);
- gotoxy(13,0);
- printf("%s",zuhao);
- gotoxy(0,2);
- printf("捆号:%s",disinput1);
- gotoxy(0,3);
- printf("重量:%s",disinput2);
- memset(input1,0x00,17);
- ret = InputData(input1, 16, 5, 2);
- if(ret == 1)
- {
- memset(disinput1,' ',17);
- disinput1[16] = 0;
- for (i = 0;i<strlen(input1);i++)
- {
- disinput1 [i] = input1 [i];
- }
- gotoxy(0,2);
- printf(" ");
- gotoxy(0,2);
- printf("捆号:%s",disinput1);
- memset(input2,0x00,11);
- ret1 =InputData2(input2, 10, 5, 3);
- if(ret1 == 2)
- {
- memset(disinput2,' ',11);
- disinput2[10] = 0;
- for(i=0;i<strlen(input2);i++)
- {
- disinput2[i] = input2[i];
- }
- memset(buf,0x00,46);
- strcat(buf,riqi);
- strcat(buf,chehao);
- strcat(buf,zuhao);
- f_hd = open_DBF((char *)"DATA");
- lseek_DBF(f_hd, 2, guangbiao, 1);
- memset(buf2,0x00,46);
- get_member(f_hd,2,(char*)buf2);
- xuhao[0] = buf2[16];
- xuhao[1] = buf2[17];
- xuhao[2] = buf2[18];
- close_DBF(f_hd);
- strcat(buf,xuhao);
- strcat(buf,disinput1);
- strcat(buf,disinput2);
- f_hd = open_DBF((char *)"DATA");
- lseek_DBF(f_hd, 2, guangbiao, 1);
- update_member(f_hd,2,(char*)buf);
- close_DBF(f_hd);
- break;
- }
- else if(ret1 == 1)
- {
- break;
- }
- }
- else if(ret == 0)
- {
- break;
- }
- }
- continue;
- }
- case KEY_ESC:return;
- }
- }
- }
- void shangchuan(void)
- {
- int f_hd,uploadflag;
- char key1,key2,key;
- while(1)
- {
- clr_scr ();
- gotoxy(0,0);
- printf("===请选择上传方式===");
- gotoxy(0,2);
- printf(" 1.数据线连接 ");
- gotoxy(0,3);
- printf(" 2.通讯座连接 ");
- gotoxy(0,4);
- printf("ESC返回 ");
- for (;!kbhit(););
- switch (key = getchar())
- {
- case KEY_F7: backlight();continue;
- case '1':
- {
- connect_port = 0;
- f_hd = open_DBF((char *)"DATA");
- uploadflag = UploadDBF (f_hd);
- close_DBF(f_hd);
- if (uploadflag == TRUE)
- {
- clr_scr();
- gotoxy(0,1);
- printf("%s",(char *)" 是否删除所有 ");
- gotoxy(0,2);
- printf("%s",(char *)" 采集数据 ");
- gotoxy(0,3);
- printf("%s",(char *)" 1是 2否 ");
- for (;!kbhit(););
- switch (key2 = getchar())
- {
- case KEY_F7: backlight();break;
- case '1':
- {
- if(remove((char*)"DATA")==1)
- {
- on_beeper (beep1);
- clr_scr();
- gotoxy(0,2);
- printf("%s",(char *)" 删除成功 ");
- if (!access("DATA"))
- {
- f_hd = create_DBF ("DATA", 45);
- create_index (f_hd, 1, 0, 12);
- create_index (f_hd, 2, 0, 16);
- create_index (f_hd, 3, 0, 19);
- close_DBF(f_hd);
- }
- OSTimeDly (300);
- }
- else
- {
- on_beeper (beep3);
- clr_scr();
- gotoxy(0,2);
- printf("%s",(char *)" 删除失败 ");
- OSTimeDly (300);
- }
- break;
- }
- case '2': break;
- }
- }
- break;
- }
- case '2':
- {
- connect_port = 2;
- f_hd = open_DBF((char *)"DATA");
- uploadflag = UploadDBF (f_hd);
- close_DBF(f_hd);
- if (uploadflag == TRUE)
- {
- clr_scr();
- gotoxy(0,1);
- printf("%s",(char *)" 是否删除所有 ");
- gotoxy(0,2);
- printf("%s",(char *)" 采集数据 ");
- gotoxy(0,3);
- printf("%s",(char *)" 1是 2否 ");
- for (;!kbhit(););
- switch (key2 = getchar())
- {
- case KEY_F7: backlight();break;
- case '1':
- {
- if(remove((char*)"DATA")==1)
- {
- on_beeper (beep1);
- clr_scr();
- gotoxy(0,2);
- printf("%s",(char *)" 删除成功 ");
- if (!access("DATA"))
- {
- f_hd = create_DBF ("DATA", 45);
- create_index (f_hd, 1, 0, 12);
- create_index (f_hd, 2, 0, 16);
- create_index (f_hd, 3, 0, 19);
- close_DBF(f_hd);
- }
- OSTimeDly (300);
- }
- else
- {
- on_beeper (beep3);
- clr_scr();
- gotoxy(0,2);
- printf("%s",(char *)" 删除失败 ");
- OSTimeDly (300);
- }
- break;
- }
- case '2': break;
- }
- }
- break;
- }
- case KEY_ESC:return;
- }
- }
- /*f_hd = open_DBF((char *)"DATA");
- uploadflag = UploadDBF (f_hd);
- close_DBF(f_hd);
- if (uploadflag == TRUE)
- {
- clr_scr();
- gotoxy(0,0);
- printf("%s",(char *)" 是否删除所有 ");
- gotoxy(0,1);
- printf("%s",(char *)" 采集数据 ");
- gotoxy(0,3);
- printf("%s",(char *)" 1是 2否 ");
- for (;!kbhit(););
- switch (key2 = getchar())
- {
- case KEY_F7: backlight();break;
- case '1':
- {
- if(remove((char*)"shoujian")==1)
- {
- on_beeper (beep1);
- clr_scr();
- gotoxy(0,2);
- printf("%s",(char *)" 删除成功 ");
- if (!access("shoujian"))
- {
- f_hd = create_DBF ("shoujian", 92);
- create_index (f_hd, 1, 32, 16);
- create_index (f_hd, 2, 0, 16);
- close_DBF(f_hd);
- }
- OSTimeDly (300);
- }
- else
- {
- on_beeper (beep3);
- clr_scr();
- gotoxy(0,2);
- printf("%s",(char *)" 删除失败 ");
- OSTimeDly (300);
- }
- break;
- }
- case '2': break;
- }
- }*/
- }
- void caiji(void)
- {
- int ret1,ret2,ret3,ret4,i;
- char riqi1[9],chehao1[5],zuhao1[5];
- while(1)
- {
- memset(riqi,' ',9);
- riqi[8] = 0;
- memset(chehao,' ',5);
- chehao[4] = 0;
- memset(zuhao,' ',5);
- zuhao[4] = 0;
- clr_scr();
- gotoxy(0,0);
- printf("请输入:");
- gotoxy(0,1);
- printf("日期:%s",riqi);
- gotoxy(0,2);
- printf("车号:%s",chehao);
- gotoxy(0,3);
- printf("组号:%s",zuhao);
- for(;;)
- {
- memset(riqi1,0x00,9);
- memset(chehao1,0x00,5);
- memset(zuhao1,0x00,5);
- clr_scr();
- gotoxy(0,0);
- printf("请输入:");
- gotoxy(0,1);
- printf("日期:%s",riqi);
- gotoxy(0,2);
- printf("车号:%s",chehao);
- gotoxy(0,3);
- printf("组号:%s",zuhao);
- ret1 = InputData2(riqi1, 8, 5, 1);
- if (ret1 == 0)//没输入就按回车
- {
- memset(riqi1,' ',9);
- riqi1[8] = 0;
- continue;
- }
- if (ret1 == 1)//按ESC
- {
- return;
- }
- if (ret1 == 2)//正常
- {
- for(i=0;i<strlen(riqi1);i++)
- {
- riqi[i] = riqi1[i];
- }
- for(;;)
- {
- clr_scr();
- gotoxy(0,0);
- printf("请输入:");
- gotoxy(0,1);
- printf("日期:%s",riqi);
- gotoxy(0,2);
- printf("车号:%s",chehao);
- gotoxy(0,3);
- printf("组号:%s",zuhao);
- ret2 = InputData2(chehao1, 4, 5, 2);
- if (ret2 == 0)//没输入就按回车
- {
- memset(chehao1,' ',5);
- chehao1[4] = 0;
- continue;
- }
- if (ret2 == 1)//按ESC
- {
- return;
- }
- if (ret2 == 2)//正常
- {
- for(i=0;i<strlen(chehao1);i++)
- {
- chehao[i] = chehao1[i];
- }
- for(;;)
- {
- clr_scr();
- gotoxy(0,0);
- printf("请输入:");
- gotoxy(0,1);
- printf("日期:%s",riqi);
- gotoxy(0,2);
- printf("车号:%s",chehao);
- gotoxy(0,3);
- printf("组号:%s",zuhao);
- ret3 = InputData2(zuhao1, 4, 5, 3);
- if (ret3 == 0)//没输入就按回车
- {
- memset(zuhao1,' ',5);
- zuhao1[4] = 0;
- continue;
- }
- if (ret3 == 1)//按ESC
- {
- return;
- }
- if (ret3 == 2)//正常
- {
- for(i=0;i<strlen(zuhao1);i++)
- {
- zuhao[i] = zuhao1[i];
- }
- for(;;)
- {
- ret4 = caiji2();
- if (ret4 == 0)//没输入就按回车
- {
- }
- if (ret4 == 1)//按ESC
- {
- return;
- }
- if (ret4 == 2)//正常
- {
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- int caiji2(void)
- {
- /*atof
- 【功能】将一个字符串转换成浮点数。
- 【原型】double atof(const char *s)
- 【位置】math.h
- */
- char input1[17],input2[11];
- char temp1[13],temp2[17],buf1[46],buf2[13],buf3[17],buf4[11];
- char temptj[11];
- int f_hd,n,i,j;
- int zukunshu= 0,chekunshu= 0;
- double zuzhongliang1,zuzhongliang2,chezhongliang1,chezhongliang2;
- int ret,ret1;
- int xuhaoshu;
- char xhshu[4];
- for(;;)
- {
- chezhongliang1 = 0;
- zuzhongliang1 = 0;
- zukunshu = 0;
- chekunshu = 0;
- memset(temp2,0x00,17);
- memset(temp1,0x00,13);
- strcat(temp2,riqi);
- strcat(temp2,chehao);
- strcat(temp2,zuhao);
- strcat(temp1,riqi);
- strcat(temp1,chehao);
- f_hd = open_DBF((char *)"DATA");
- n = member_in_DBF (f_hd);
- for(i=0;i<n;i++)
- {
- memset(buf1,0x00,46);
- lseek_DBF(f_hd, 2, i, 1);
- get_member(f_hd,2,(char*)buf1);
- if(strncmp(buf1,temp2,16) == 0)
- {
- zukunshu = zukunshu+1;
- }
- }
- close_DBF(f_hd);
- f_hd = open_DBF((char *)"DATA");
- n = member_in_DBF (f_hd);
- for(i=0;i<n;i++)
- {
- memset(buf1,0x00,46);
- lseek_DBF(f_hd, 1, i, 1);
- get_member(f_hd,1,(char*)buf1);
- if(strncmp(buf1,temp1,12) == 0)
- {
- chekunshu = chekunshu+1;
- }
- }
- close_DBF(f_hd);
- /*--------------------------------------------------------*/
- f_hd = open_DBF((char *)"DATA");
- n = member_in_DBF (f_hd);
- for(i=0;i<n;i++)
- {
- memset(buf1,0x00,46);
- lseek_DBF(f_hd, 1, i, 1);
- get_member(f_hd,1,(char*)buf1);
- if(strncmp(buf1,temp1,12) == 0)
- {
- memset(temptj,0x00,11);
- chezhongliang2 = 0;
- for(j = 35;j<45;j++)
- {
- temptj[j-35] = buf1[j];
- }
- chezhongliang2 = atof((char*)temptj);
- chezhongliang1 = chezhongliang1 + chezhongliang2;
- }
- }
- close_DBF(f_hd);
- f_hd = open_DBF((char *)"DATA");
- n = member_in_DBF (f_hd);
- for(i=0;i<n;i++)
- {
- memset(buf1,0x00,46);
- lseek_DBF(f_hd, 2, i, 1);
- get_member(f_hd,2,(char*)buf1);
- if(strncmp(buf1,temp2,16) == 0)
- {
- memset(temptj,0x00,11);
- zuzhongliang2 = 0;
- for(j = 35;j<45;j++)
- {
- temptj[j-35] = buf1[j];
- }
- zuzhongliang2 = atof((char*)temptj);
- zuzhongliang1 = zuzhongliang1 + zuzhongliang2;
- }
- }
- close_DBF(f_hd);
- /*-----------------------------------------------------------------*/
- clr_scr();
- gotoxy(0,0);
- printf("%s",riqi);
- gotoxy(9,0);
- printf("%s",chehao);
- gotoxy(13,0);
- printf("%s",zuhao);
- gotoxy(0,1);
- printf("捆号:");
- gotoxy(0,2);
- printf("重量:");
- gotoxy(0,3);
- printf("zu:%d",zukunshu);
- gotoxy(0,4);
- printf("che:%d",chekunshu);
- gotoxy(7,3);
- printf("%-7.2f",zuzhongliang1);
- gotoxy(7,4);
- printf("%-7.2f",chezhongliang1);
- memset(input1,0x00,17);
- ret = InputData(input1, 16, 5, 1);
- if(ret == 1)
- {
- memset(kunhao,' ',17);
- kunhao[16] = 0;
- for (i = 0;i<strlen(input1);i++)
- {
- kunhao [i] = input1 [i];
- }
- gotoxy(0,1);
- printf(" ");
- gotoxy(0,1);
- printf("捆号:%s",kunhao);
- memset(input2,0x00,11);
- ret1 =InputData2(input2, 10, 5, 2);
- if(ret1 == 2)
- {
- memset(zhongliang,' ',11);
- zhongliang[10] = 0;
- for(i=0;i<strlen(input2);i++)
- {
- zhongliang[i] = input2[i];
- }
- /*-----------------------------------*/
- xuhaoshu = zukunshu +1;
- memset(xhshu,0x00,4);
- itoa (xuhaoshu, (char*)xhshu, 10);
- memset(xuhao,' ',4);
- xuhao[3] = 0;
- for(i=0;i<strlen(xhshu);i++)
- {
- xuhao[i] = xhshu[i];
- }
- /*-----------------------------------*/
- memset(all,0x00,46);
- strcat(all,riqi);
- strcat(all,chehao);
- strcat(all,zuhao);
- strcat(all,xuhao);
- strcat(all,kunhao);
- strcat(all,zhongliang);
- record_save((char*)all, (char*)"DATA");
- }
- else if(ret1 == 1)
- {
- return 1;
- }
- }
- else if(ret == 0)
- {
- return 1;
- }
- }
- }
- void record_save(char* record, char* filename)
- {
- int f_hd;
- f_hd=open_DBF((char *)filename);
- if(add_member(f_hd,(char *)record) == 1)
- {
- on_beeper (beep1);
- }
- else
- {
- on_beeper (beep3);//OSTimeDly (300);
- clr_scr ();
- gotoxy(0,2);
- printf(" 保存失败 ");
- OSTimeDly (300);
- }
- close_DBF(f_hd);
- }
- void getDatetime(void)
- {
- char cur_time[16];
- char tmpdate[11],tmptime[9];
- char year[6],month[4],day[4],hour[4],minute[4],second[4];
- memset(date,0x00,sizeof(date));
- memset(tmpdate,0x00,sizeof(tmpdate));
- memset(time,0x00,sizeof(time));
- memset(tmptime,0x00,sizeof(tmptime));
- memset(year,0x00,sizeof(date));
- memset(month,0x00,sizeof(date));
- memset(day,0x00,sizeof(date));
- memset(hour,0x00,sizeof(date));
- memset(minute,0x00,sizeof(date));
- memset(second,0x00,sizeof(date));
- get_time(cur_time);
- /*获取时间*/
- memcpy(year,cur_time,4);
- memcpy(month,cur_time+4,2);
- memcpy(day,cur_time+6,2);
- /*获取时间*/
- memcpy(hour,cur_time+8,2);
- memcpy(minute,cur_time+10,2);
- memcpy(second,cur_time+12,2);
- sprintf(date,"%04d-%02d-%02d/x00",atoi(year),atoi(month),atoi(day));
- sprintf(time,"%02d:%02d:%02d/x00",atoi(hour),atoi(minute),atoi(second));
- }
- static BOOL ConnectingPage (void)
- {
- clr_scr ();
- gotoxy(0,0);
- printf("连接中. ");
- gotoxy(0,3);
- printf(" ");
- gotoxy(0,4);
- printf("按 ESC 退出");
- // DispString (0, 1, (char*)"连接中. ", 0, 1);
- // DispString (0, 3, (char*)" ", 0, 1);
- // DispString (0, 5, (char*)"按 ESC 退出", 0, 1);
- return TRUE;
- }
- BOOL UploadDBF (int fDbf)
- {
- int i, j, k, n,nPort,p;
- char szbuf1[100];
- unsigned sum;
- BYTE Header [2];
- BYTE c;
- BYTE szData [256];
- BYTE szBuf[256];
- ConnectingPage ();
- SetCommType (1, connect_port); // IR
- nPort = 1; // must use COM2
- c = 0x08; // 115200,N,8,1
- open_com (nPort, c);
- ReTry:
- i = 0;
- while (i < 10)
- {
- if (read_com (nPort, (char *)&c)) // if successful reading
- szData [i++] = c;
- if (c == '/r')
- break;
- if ((c = getchar()) == KEY_ESC)
- {
- close_com (nPort);
- clr_scr ();
- return FALSE;
- }
- else if (c == KEY_F7)
- backlight();
- }
- szData [i] = 0;
- if (!strcmp (szData, "READ/r"))
- {
- write_com (nPort, ACK);
- while (!com_eot (nPort));
- gotoxy(0,0);
- printf("上传中");
- gotoxy(0,3);
- printf("状态:");
- // DispString (0, 1, (char*)"上传中", 0, 1); // Sending data...
- // DispString (0, 3, (char*)"状态:", 0, 1); // Transfered:
- }
- else
- {
- write_com (nPort, NAK);
- while (!com_eot (nPort));
- goto ReTry;
- }
- n = member_in_DBF (fDbf);
- lseek_DBF (fDbf, 1, 0, SEEK_SET); //SEEK_SET=1(from 8000lib.h)
- k = 0;
- while (k < n)
- {
- get_member (fDbf, 1, (char *)szData);
- lseek_DBF (fDbf, 1, 1, SEEK_CUR);
- //p = strlen (szData);
- //for (i=6;i<p;i++)
- // szbuf1[i-6] = szData[i];
- //memset(szData,0x00,strlen(szData));
- //for (i=6;i<p;i++)
- // szData[i-6] = szbuf1[i-6];
- ///
- j = strlen (szData);
- if (j < 1)/**************************************************************************************************/
- {
- k++;
- continue;
- }
- sum = Header [0] = k++ % 10; // rotate from 0 to 9
- for (i=0; i<j; i++)//i=0
- sum += szData [i];
- szData [j] = sum & 0xFF;
- if (szData [j] == '/r') // make sure the checksum isn't '/r'
- szData [j]++;
- j++;
- szData [j] = sum >> 8;
- if (szData [j] == '/r') // make sure the checksum isn't '/r'
- szData [j]++;
- szData [++j] = '/r';
- szData [++j] = 0;
- itoa (k, (char*)szBuf, 10);
- gotoxy(11,3);
- printf("%s",szBuf);
- // DispString (11, 3, (char*)szBuf, 0, 1); // show data transfered
- ReSend:
- nwrite_com (nPort, (char *)Header, 1);
- while (com_eot(nPort) == 0x00);
- nwrite_com (nPort, (char *)szData, j);
- while (!com_eot (nPort));
- ReDo:
- i = 0;
- while (i < 10)
- {
- if (read_com (nPort, (char *)&c))
- szBuf [i++] = c;
- if (c == '/r')
- break;
- if ((c = getchar()) == KEY_ESC)
- {
- close_com (nPort);
- clr_scr ();
- return FALSE;
- }
- else if (c == KEY_F7)
- backlight();
- }
- szBuf [i] = 0;
- if (!strcmp (szBuf, NAK))
- goto ReSend;
- else if (strcmp (szBuf, ACK))
- goto ReDo;
- }
- write_com (nPort, "OVER/r");
- while (!com_eot (nPort));
- write_com (nPort, "OVER/r");
- while (!com_eot (nPort));
- on_beeper (beep2);
- gotoxy(11,3);
- printf("完成");
- //DispString (11, 3, (char*)"完成", 0, 1); // Done
- //DispString (0, 5, (char*)" ", 0);
- //DispString (0, 7, (char*)" ", 0, 1);
- close_com (nPort);
- OSTimeDly (200);
- return TRUE;
- }
- //--------------------------------------------------------//
- int InputData2 (char* databuf, int maxbit, int CurX, int CurY)
- {
- char key,c_space[100];
- int flag,count;
- for (count=0;count<maxbit;count++)
- c_space[count] = ' ';
- c_space[count] = 0; //设定maxbit个字节的空格,用来清空输入区
- memset(databuf,0x00,strlen(databuf));
- databuf[strlen(databuf)-1] = 0;
- gotoxy(CurX,CurY);
- SetCursor (1);
- en_alpha (ALPHA_FIXED); //ALPHA_FIXED 只允许字母输入
- flag = 0;
- count = 0;
- for (;;)
- {
- if (kbhit())
- {
- key = getchar();
- if (key == KEY_CR)
- {
- clr_kb();
- if (count == 0)
- {
- SetCursor (0);
- return 0;
- }
- else if (count > 0)
- {
- on_beeper (beep2);
- break;
- }
- }
- else if (key == KEY_BS)
- {
- if (count>0 && count<=maxbit)
- {
- if ((CurX+count)<=Xmax)
- {
- count--;
- databuf[count] = 0;
- gotoxy(CurX+count,CurY);
- putchar(' ');
- gotoxy(CurX+count,CurY);
- }
- else
- {
- count--;
- databuf[count] = 0;
- gotoxy(CurX+count-Xmax,CurY+1);
- putchar(' ');
- gotoxy(CurX+count-Xmax,CurY+1);
- }
- }
- }
- else if (key == KEY_F7)
- {
- backlight();
- }
- else if (key == KEY_ESC)
- {
- count = 0;
- dis_alpha ();
- SetCursor (0);
- return 1;
- }
- else
- if ( (key>='0'&&key<='9')||(key>='A'&&key<='Z')||(key>='a'&&key<='z')||(key=='.')||(key=='-'))
- {
- if(count == 0)
- {
- gotoxy(CurX,CurY);
- printf("%s",(char *)c_space);
- gotoxy(CurX,CurY);
- databuf[count]=key;
- gotoxy(CurX+count,CurY);
- putchar(databuf[count]);
- count++;
- clr_kb();
- }
- else if (count < maxbit)
- {
- databuf[count]=key;
- if ((CurX+count)<Xmax)
- {
- gotoxy(CurX+count,CurY);
- }
- else
- {
- gotoxy(CurX+count-Xmax,CurY+1);
- }
- putchar(databuf[count]);
- count++;
- clr_kb();
- }
- }
- }
- }
- dis_alpha ();
- SetCursor (0);
- return 2;
- }
- int InputData (char* databuf, int maxbit, int CurX, int CurY)
- {
- char key,c_space[100];
- int flag,count;
- for (count=0;count<maxbit;count++)
- c_space[count] = ' ';
- c_space[count] = 0; //设定maxbit个字节的空格,用来清空输入区
- gotoxy(CurX,CurY);
- SetCursor (1);
- en_alpha (ALPHA_FIXED); //ALPHA_FIXED 只允许字母输入
- InitScanner1();
- flag = 0;
- count = 0;
- for (;;)
- {
- if (Decode ())
- {
- on_beeper (beep2);
- HaltScanner1();
- flag=1;
- break;
- } //扫描条码成功后退出循环
- else if (kbhit())
- {
- key = getchar();
- if (key == KEY_CR)
- {
- clr_kb();
- if (count == 0)
- {
- count = 0;
- gotoxy(CurX,CurY);
- }
- else if (count > 0)
- {
- databuf[count]=0x00;
- on_beeper (beep2);
- HaltScanner1();
- break;
- } //数据输入完成后退出循环
- }
- else if (key == KEY_BS)
- {
- if (count>0 && count<=maxbit)
- {
- if ((CurX+count)<=Xmax)
- {
- count--;
- databuf[count] = 0;
- gotoxy(CurX+count,CurY);
- putchar(' ');
- gotoxy(CurX+count,CurY);
- }
- else
- {
- count--;
- databuf[count] = 0;
- gotoxy(CurX+count-Xmax,CurY+1);
- putchar(' ');
- gotoxy(CurX+count-Xmax,CurY+1);
- }
- }
- }
- else if (key == KEY_F7)
- {
- backlight();
- }
- else if (key == KEY_ESC)
- {
- count = 0;
- HaltScanner1();
- dis_alpha ();
- SetCursor (0);
- return 0; //返回上一级菜单
- }
- else
- if ( (key>='0'&&key<='9')||(key>='A'&&key<='Z')||(key>='a'&&key<='z')||(key=='.')||(key=='-') )
- {
- if(count == 0)
- {
- gotoxy(CurX,CurY);
- printf(" ");
- gotoxy(CurX,CurY);
- databuf[count]=key;
- gotoxy(CurX+count,CurY);
- putchar(databuf[count]);
- count++;
- clr_kb();
- }
- else if (count < maxbit)
- {
- databuf[count]=key;
- if ((CurX+count)<Xmax)
- {
- gotoxy(CurX+count,CurY);
- }
- else
- {
- gotoxy(CurX+count-Xmax,CurY+1);
- }
- putchar(databuf[count]);
- count++;
- clr_kb();
- }
- }
- }
- }
- if (flag == 1)
- {
- for (count=0;count<CodeLen && count<maxbit;count++)
- {
- databuf[count]=CodeBuf[count];
- }
- databuf[count]=0x00;
- }
- dis_alpha ();
- SetCursor (0);
- return 1;//继续下一步操作
- }
- //--------------------------------------------------------//
- /*//--------------------------------------------------------//
- //--------------------------------------------------------//*/
- void backlight()
- {
- if (bklt_flag == 0) bklt_flag = 1;
- else bklt_flag = 0;
- lcd_backlit (bklt_flag);
- }
条形码扫描示例程序
最新推荐文章于 2021-09-22 09:23:26 发布