- /*
- 适用8300版本
- M/D:2007.5.14
- KNL:8300K-3.23
- LIB:8300L-2.21
- */
- #include<8300lib.h>
- #include<ucos.h>
- #include<stdlib.h>
- #defineBYTEunsignedchar
- #defineBOOLunsignedchar
- #defineULONGunsignedlong
- #defineTRUE1
- #defineFALSE0
- #defineCANCEL2
- #defineYmax5
- #defineXmax20
- staticchar*ACK="ACK\r";
- staticchar*NAK="NAK\r";
- intbeep1[4]={16,5,0,0};
- intbeep2[8]={30,10,0,5,30,10,0,0};
- intbeep3[8]={30,50,0,5,30,50,0,0};
- intbeep4[4]={30,150,0,0};
- //************************VAR***********************************#defineNULL0x00*******//
- //voidflip_page(charpage[][Xmax],introwcount);//将page中的内容显示出来,按UP、DOWN键上、下翻动
- intInputData(char*databuf,intmaxbit,intx,inty);//数据采集
- intInputData2(char*databuf,intmaxbit,intx,inty);
- voidbacklight();//设置背光
- intbklt_flag=0;
- staticBOOLConnectingPage(void);//联接等待界面
- //BOOLDownloadLookup(char*filename,intrecord_len,intkey_offset,intkey_len);
- ////数据下载到filename中,记录长度为record_len,索引开始位置为key_offset,长度为key_len
- BOOLUploadDBF(intfDbf);//数据上传
- voidrecord_save(char*record,char*filename);
- voidshangchuan(void);
- voidntos(charns[],longn,unsignedcount);
- chardate[11];
- chartime[11];
- /*-----------函数声明--------------------*/
- voidLogin(void);//登陆界面
- voidMainMenu(void);//主菜单
- voidgetDatetime(void);//登陆界面显示的时间
- voidSetClock(void);//设置时间
- voidscan_barcode(void);//扫描条码
- voidtransmit(void);//传输
- voiddel_data(void);//清除
- voidcaiji(void);
- intcaiji2(void);
- voidchaxun(void);//查询删除
- voidchaxun2(void);
- voidxiugai(void);//修改
- /*-----------变量------------------------*/
- charriqi[9];//日期
- charchehao[5];//车号
- charzuhao[5];//组号
- charxuhao[4];//序号
- charkunhao[17];//捆号
- charzhongliang[11];//重量
- charall[46];
- intconnect_port=0;
- /*******************************************************************/
- voidmain()
- {
- //SetFont(FONT_6X8);
- SetFont(FONT_6X12);
- SetVideoMode(0);
- SetCursor(0);
- while(1)
- {
- Login();/*登录界面*/
- MainMenu();/*应用功能菜单*/
- }
- }
- voidLogin(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;
- }
- }
- voidMainMenu(void)
- {
- intret,f_hd;
- charkey;
- 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())
- {
- caseKEY_F7:backlight();break;
- case'1':caiji();break;
- case'2':chaxun();break;
- //case'3':xiugai();break;
- case'3':shangchuan();break;
- caseKEY_ESC:return;
- }
- }
- }
- voidchaxun(void)
- {
- intret1,ret2,ret3,ret4,i;
- charriqi1[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;
- }
- }
- }
- }
- }
- }
- }
- }
- voidchaxun2(void)
- {
- charrcz[17],buf[46],buf2[46];
- charxianshixuhao[4],xianshishuliang[4],xianshikunhao[17],xianshizhongliang[11];
- intzukunshu;
- intguangbiao;
- inti,n,j;
- intf_hd;
- charkey;
- inttemp1,temp2;
- intret1,ret;
- charinput1[17],input2[11],disinput1[17],disinput2[11];
- chartemp3[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())
- {
- caseKEY_F7:backlight();continue;
- caseKEY_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;
- }
- caseKEY_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;
- }
- caseKEY_F1:
- {
- clr_scr();
- gotoxy(0,1);
- printf("是否删除当前数据?");
- gotoxy(0,3);
- printf("1是2否");
- for(;!kbhit(););
- switch(key=getchar())
- {
- caseKEY_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;
- }//case1111
- case'2':continue;
- }
- }//caseF_1
- caseKEY_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;
- }
- elseif(ret1==1)
- {
- break;
- }
- }
- elseif(ret==0)
- {
- break;
- }
- }
- continue;
- }
- caseKEY_ESC:return;
- }
- }
- }
- voidshangchuan(void)
- {
- intf_hd,uploadflag;
- charkey1,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())
- {
- caseKEY_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())
- {
- caseKEY_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())
- {
- caseKEY_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;
- }
- caseKEY_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())
- {
- caseKEY_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;
- }
- }*/
- }
- voidcaiji(void)
- {
- intret1,ret2,ret3,ret4,i;
- charriqi1[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)//正常
- {
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- intcaiji2(void)
- {
- /*atof
- 【功能】将一个字符串转换成浮点数。
- 【原型】doubleatof(constchar*s)
- 【位置】math.h
- */
- charinput1[17],input2[11];
- chartemp1[13],temp2[17],buf1[46],buf2[13],buf3[17],buf4[11];
- chartemptj[11];
- intf_hd,n,i,j;
- intzukunshu=0,chekunshu=0;
- doublezuzhongliang1,zuzhongliang2,chezhongliang1,chezhongliang2;
- intret,ret1;
- intxuhaoshu;
- charxhshu[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;
条形码扫描示例程序
最新推荐文章于 2021-09-22 09:23:26 发布
本系统是一款用于铝锭条码离线扫描的应用程序,支持数据采集、查询及上传等功能。通过简单的用户界面进行操作,实现铝锭信息录入、查询及数据传输到远程系统。
3476





