📄 t8.c
字号:
#include<io.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<graph.h>
#include<time.h>
#include<dos.h>
#include<fcntl.h>
#include<malloc.h>
#include<share.h>
#include<math.h>
#include "svgacc.h"
#include "pcl4c.h"
#include "lu.h"
int main(void)
{ int ok,ikeycode,i,k;
char *buf,*buf1;
FILE *fpASC;
char far *Ptr;
int borrowcount;
char buf111[8];
int Seg;
int sendok,maxtm;
time_t tmstart,tmend;
initdata();
lmtspeedinit();
Port=iCOM;
Ptr = (char far *)RxBuffer;
Seg = FP_SEG(Ptr) + ((FP_OFF(Ptr)+15)>>4);
ErrorCheck(SioRxBuf(Port,Seg,Size1024));
Ptr = (char far *)TxBuffer;
Seg = FP_SEG(Ptr) + ((FP_OFF(Ptr)+15)>>4);
ErrorCheck( SioTxBuf(Port,Seg,Size512) );
ErrorCheck( SioParms(Port,NoParity,OneStopBit,WordLength8) );
ErrorCheck( SioReset(Port,Baud9600) );
i = SioFIFO(Port,LEVEL_4TH);
if((fpASC=fopen("asc16","rb"))==0)
{printf("Error: ASC16 can't open.\n");
return FALSE;
}
if(fgets(ASC16,4096,fpASC)==NULL)
{printf("ERROR:ASC16 Read Error.\n");
fclose(fpASC);
return FALSE;
}
fclose(fpASC);
setlength=935;
setnumber=0L;
lmtspeed=184;
cuterror=0;
prdnumber=0L;
ispeed=0;
badnumber=0;
oldspeed=0;
oldprdnumber=0L;
leftnumber=0L;
rcvcount=0;
maxtm=1500;
borrowcount=0;
autook=FALSE;
FirstChangeOk=TRUE;
omaxrec=0;
irec=0;
maxrec=0;
tmcounter=0;
buf=(char *)calloc(1,80);
buf1=(char *)calloc(1,10);
_strtime(oldtimebuf);
whichvga();
res800();
drwbox(SET,lPINK,0,0,800,600);
drwbox(SET,lPINK,1,1,799,599);
drwbox(SET,lPINK,2,2,798,598);
drwfillbox(SET,GRAY,3,3,797,597);
drwline(SET,lPINK,2,22,799,22);
drwline(SET,lPINK,2,22,799,22);
drwfillbox(SET,WHITE,3,3,798,21);
strcpy(buf,"瓦楞纸板生产线换单系统:横切机控制"); /*自动换单系统--横切机控制");*/
drwhzstr(buf,4,5,1,1,lBLUE,SET);
drwbox(SET,lYELLOW,5,25,795,80);
drwbox(SET,lYELLOW,6,26,794,79);
drwfillbox(SET,WHITE,7,27,793,78);
strcpy(buf,"湖北京山轻工机械股份有限公司");
drwhzstr(buf,202,36,1,2,lPINK,SET);
strcpy(buf,"地址:湖北省京山县新市镇轻机大道");
drwhzstr(buf,280,62,1,1,lPINK,SET);
strcpy(buf,"78");
drwstring(SET,lPINK,15,buf,536,64);
strcpy(buf,"号");
drwhzstr(buf,552,62,1,1,lPINK,SET);
drwbox(SET,lYELLOW,5,86,795,222);
drwbox(SET,lYELLOW,6,87,794,221);
drwfillbox(SET,lCYAN,7,88,793,220);
drwbox(SET,GREEN,9,90,116,148);
drwbox(SET,GREEN,10,91,115,147);
drwfillbox(SET,lBLUE,11,92,114,146);
strcpy(buf,"速");
drwhzstr3(buf,16,106,2,3,WHITE,SET);
drwhzstr3(buf,15,106,2,3,WHITE,SET);
strcpy(buf,"度");
drwhzstr3(buf,66,106,2,3,WHITE,SET);
drwhzstr3(buf,65,106,2,3,WHITE,SET);
/*生产数量*/
drwbox(SET,GREEN,119,90,389,148);
drwbox(SET,GREEN,120,91,388,147);
drwfillbox(SET,lBLUE,121,92,387,146);
strcpy(buf,"生产数量");
drwhzstr3(buf,169,106,2,3,WHITE,SET);
drwhzstr3(buf,168,106,2,3,WHITE,SET);
/*剩余数量*/
drwbox(SET,GREEN,392,90,650,148);
drwbox(SET,GREEN,393,91,649,147);
drwfillbox(SET,lBLUE,394,92,648,146);
strcpy(buf,"剩余数量");
drwhzstr3(buf,428,106,2,3,WHITE,SET);
drwhzstr3(buf,427,106,2,3,WHITE,SET);
/*废品*/
drwbox(SET,GREEN,653,90,793,148);
drwbox(SET,GREEN,654,91,792,147);
drwfillbox(SET,RED,655,92,791,146);
strcpy (buf,"废");
drwhzstr3(buf,667,106,2,3,WHITE,SET);
drwhzstr3(buf,666,106,2,3,WHITE,SET);
strcpy(buf,"品");
drwhzstr3(buf,732,106,2,3,WHITE,SET);
drwhzstr3(buf,731,106,2,3,WHITE,SET);
/************************************/
drwbox(SET,GREEN,9,152,116,215);
drwbox(SET,GREEN,10,153,115,214);
drwfillbox(SET,lBLUE,11,154,114,213);
drwbox(SET,GREEN,119,152,389,215);
drwbox(SET,GREEN,120,153,388,214);
drwfillbox(SET,lBLUE,121,154,387,213);
drwbox(SET,GREEN,392,152,650,215);
drwbox(SET,GREEN,393,153,649,214);
drwfillbox(SET,lBLUE,394,154,648,213);
drwbox(SET,GREEN,653,152,793,215);
drwbox(SET,GREEN,654,153,792,214);
drwfillbox(SET,RED,655,154,791,213);
drwbox(SET,RED,5,226,795,540);
drwbox(SET,RED,6,227,794,539);
drwfillbox(SET,BLACK,7,228,793,538);
drwfillbox(SET,CYAN,9,230,72,250);
strcpy(buf,"工号");
drwfillbox(SET,CYAN,74,230,115,250);
drwhzstr(buf,76,232,1,1,lPINK,SET);
strcpy(buf,"定单号");
drwfillbox(SET,CYAN,117,230,169,250);
drwhzstr(buf,119,232,1,1,lPINK,SET);
drwfillbox(SET,RED,9,260,72,280);
strcpy(buf,"已生产");
drwhzstr(buf,20,262,1,1,WHITE,SET);
drwfillbox(SET,GREEN,9,288,72,308);
strcpy(buf,"生产中");
drwhzstr(buf,20,290,1,1,lPINK,SET);
drwfillbox(SET,BLUE,9,316,72,336);
strcpy(buf,"待生产");
drwhzstr(buf,20,318,1,1,RED,SET);
strcpy(buf,"纸质");
drwfillbox(SET,CYAN,171,230,550,250);
drwhzstr(buf,353,232,1,1,lPINK,SET);
strcpy(buf,"纸宽");
drwfillbox(SET,CYAN,552,230,593,250);
drwhzstr(buf,555,232,1,1,lPINK,SET);
strcpy(buf,"长度");
drwfillbox(SET,CYAN,595,230,636,250);
drwhzstr(buf,600,232,1,1,lPINK,SET);
strcpy(buf,"数量");
drwfillbox(SET,CYAN,638,230,748,250);
drwhzstr(buf,678,232,1,1,lPINK,SET);
strcpy(buf,"限速");
drwfillbox(SET,CYAN,750,230,791,250);
drwhzstr(buf,757,232,1,1,lPINK,SET);
strcpy(buf1,"F1");
strcpy(buf,"定单输入");
drwbutton(buf1,buf,8,545,SET,44);
strcpy(buf1,"F2");
strcpy(buf,"强制换单");
drwbutton(buf1,buf,88,545,SET,44);
strcpy(buf1,"F3");
strcpy(buf,"定单保存");
drwbutton(buf1,buf,167,545,SET,44);
strcpy(buf1,"F4");
strcpy(buf,"定单浏览");
drwbutton(buf1,buf,247,545,SET,44);
strcpy(buf1,"F5");
strcpy(buf,"定单上载");
drwbutton(buf1,buf,326,545,SET,44);
strcpy(buf1,"F6");
strcpy(buf,"生产定单");
drwbutton(buf1,buf,406,545,SET,44);
strcpy(buf1,"F7");
strcpy(buf,"自动换单");
drwbutton(buf1,buf,485,545,SET,44);
strcpy(buf1,"F8");
strcpy(buf,"取消换单");
drwbutton(buf1,buf,565,545,SET,44);
strcpy(buf1,"+/-");
strcpy(buf,"废品计数");
drwbutton(buf1,buf,644,545,SET,44);
strcpy(buf1,"ESC");
strcpy(buf,"退出系统");
drwbutton(buf1,buf,725,545,SET,44);
_strdate(buf);
drwstr(buf,400,5,1,2,RED,SET);
ok=TRUE;
sendok=TRUE;
orderok=FALSE;
autoct=0;
leftct=0;
strcpy(buf111,"tu.pcx");
pcxmake(9,byorder[borrowcount][0]-3,72,byorder[borrowcount][1]+3,buf111);
drwfillbox(SET,BLACK,9,byorder[borrowcount][0]-3,72,byorder[borrowcount][1]+3);
borrow(10,55,byorder[borrowcount][0],byorder[borrowcount][1],borrowcount+33,3);
while(ok)
{if((sendok) && (orderok))
{buf3[0]='1';
buf3[1]=ENTER;
buf3[2]='\0';
SioRTS(Port,'S');
SioPuts(Port,buf3,2);
SioEmpty(Port);
SioRTS(Port,'C');
sendok=FALSE;
tmcounter=0;
time(&tmstart);
}
if(kbhit())
{ikeycode=getkey();
switch(ikeycode)
{ case kbF1: /* Input */
drwbutton(str0[0],str0[1],8,545,SET,lGREEN);
inputorder(buf);
strupr(buf);
if (flag2==TRUE)
appendorder(buf);
dispallorder(irec,maxrec-1);
drwbutton(str0[0],str0[1],8,545,SET,44);
break;
case kbF2: /* Change */
drwbutton(str0[2],str0[3],88,545,SET,lGREEN);
changeorder();
dispallorder(irec,maxrec-1);
drwfillcircle(SET,WHITE,30,50,20);
drwbutton(str0[2],str0[3],88,545,SET,44);
break;
case kbF3: /* Save */
drwbutton(str0[4],str0[5],167,545,SET,lGREEN);
saveorder();
sdelay(5);
drwbutton(str0[4],str0[5],167,545,SET,44);
break;
case kbF4: /* Brow */
drwbutton(str0[6],str0[7],247,545,SET,lGREEN);
broworder();
dispallorder(irec,maxrec-1);
drwbutton(str0[6],str0[7],247,545,SET,44);
break;
case kbF5: /* Upload */
drwbutton(str0[8],str0[9],326,545,SET,lGREEN);
uploadorder();
dispallorder(irec,maxrec-1);
drwbutton(str0[8],str0[9],326,545,SET,44);
break;
case kbF6: /* History */
drwbutton(str0[10],str0[11],406,545,SET,lGREEN);
historybrow();
dispallorder(irec,maxrec-1);
drwbutton(str0[10],str0[11],406,545,SET,44);
break;
case kbF7: /* Auto Order Exchange */
autook=!autook;
break;
case kbF8: /* Cancel Exchange */
drwbutton(str0[12],str0[13],565,545,SET,lGREEN);
strcpy(buf2,"请确认是否需要取消换单?");
i=msgbox(buf2,1,1);
if((i=='y') || (i=='Y') || (i==ENTER))
{strncpy(buf3,currentorder,70);
appendorder(buf3);
for(k=maxrec-1;k>irec;k--)
exchangeorder(k,k-1);
strncpy(buf3,oldorder,70);
appendorder(buf3);
for(k=maxrec-1;k>irec;k--)
exchangeorder(k,k-1);
changeorder();
dispallorder(irec,maxrec-1);
}
drwbutton(str0[12],str0[13],565,545,SET,44);
break;
case '+':
/* drwbutton(str0[14],str0[15],644,545,SET,lGREEN);*/
badnumber++;
dispbadnumber();
/* drwbutton(str0[14],str0[15],644,545,SET,44); */
break;
case '-':
drwbutton(str0[14],str0[15],644,545,SET,lGREEN);
if(badnumber>0)
{badnumber--;
dispbadnumber();
}
drwbutton(str0[14],str0[15],644,545,SET,44);
break;
case ESC:
drwbutton(str0[16],str0[17],725,545,SET,lGREEN);
strcpy(buf2,"请确认退出系统?");
i=msgbox(buf2,1,1);
if((i=='y') || (i=='Y') || (i==ENTER))
ok=FALSE;
drwbutton(str0[16],str0[17],725,545,SET,44);
break;
case kbUp:
if (borrowcount!=0)
{ pcxput(SET,9,byorder[borrowcount][0]-3,buf111);
pcxmake(9,byorder[borrowcount-1][0]-3,72,byorder[borrowcount-1][1]+3,buf111);
drwfillbox(SET,BLACK,9,byorder[borrowcount-1][0]-3,72,byorder[borrowcount-1][1]+3);
borrow(10,55,byorder[borrowcount-1][0],byorder[borrowcount-1][1],borrowcount+33,3);
}
if (borrowcount==0)
borrowcount=0;
else borrowcount=borrowcount-1;
break;
case kbDn:
if (borrowcount!=7)
{if (borrowcount==0)
{pcxput(SET,9,byorder[borrowcount][0]-3,buf111);
pcxmake(9,byorder[borrowcount+1][0]-3,72,byorder[borrowcount+1][1]+3,buf111);
drwfillbox(SET,BLACK,9,byorder[borrowcount+1][0]-3,72,byorder[borrowcount+1][1]+3);
}
else{pcxput(SET,9,byorder[borrowcount][0]-3,buf111);
pcxmake(9,byorder[borrowcount+1][0]-3,72,byorder[borrowcount+1][1]+3,buf111);
drwfillbox(SET,BLACK,9,byorder[borrowcount+1][0]-3,72,byorder[borrowcount+1][1]+3);
}
borrow(10,55,byorder[borrowcount+1][0],byorder[borrowcount+1][1],borrowcount+33,3);
}
if (borrowcount==7)
borrowcount=7;
else borrowcount=borrowcount+1;
break;
}
tmcounter=maxtm;
time(&tmstart);
}
showtime();
dispspeed();
dispprdnumber();
rcvchar= (char)SioGetc(Port,0);
if(rcvchar==STX)
rcvcount=0;
else if(rcvchar==ENTER)
{rcvbuf[rcvcount]='\0';
if(bcccheck(rcvbuf))
{for(i=0;i<3;i++)
buf3[i]=rcvbuf[i];
buf3[3]='\0';
ispeed=atoi(buf3);
for(i=0;i<6;i++)
buf3[i]=rcvbuf[3+i];
buf3[6]='\0';
prdnumber=atol(buf3);
}
sendok=TRUE;
tmcounter=maxtm;
time(&tmstart);
}
else if(rcvchar>=' ')
rcvbuf[rcvcount++]=rcvchar;
if(!sendok)
{time(&tmend);
tmcounter++;
if(fabs(difftime(tmend,tmstart))>=5.0)
{sendok=TRUE;
strcpy(buf2,"通信超时错误!");
waitbox(buf2,0,1);
time(&tmstart);
}
else if(tmcounter>=maxtm)
{ sendok=TRUE;
tmcounter=0;
time(&tmstart);
}
}
leftnumber=setnumber-prdnumber+badnumber;
if(leftnumber<20L)
{if(leftct==0)
drwfillcircle(XOR,GREEN,30,50,20);
leftct++;
if(leftct>500) leftct=0;
}
if((autook) && (leftnumber<=1) && (orderok))
{changeorder();
dispallorder(irec,maxrec-1);
drwfillcircle(SET,WHITE,30,50,20);
}
if(autook)
{if(autoct==0)
drwfillcircle(XOR,CYAN,515,570,5);
autoct++;
if(autoct>800) autoct=0;
if(irec>maxrec-1) autook=FALSE;
}
else
drwfillcircle(SET,YELLOW,515,570,5);
lmtspeed=lmtspeedcal(setlength);
if((ispeed>lmtspeed) && orderok)
{ strcpy(buf2,"生产速度超过极速!不能保证正常生产!");
waitbox(buf2,0,1);
}
}
restext();
SioDone(Port);
free(buf);
return 1;
}
int maxprdrec(void)
{FILE *fp;
long i;
i=0L;
if((fp=fopen("prddata.txt","r")) != NULL)
{i=filelength(fileno(fp));
fclose(fp);
}
return (int)(i/112L);
}
void scandata(int istart,int iend)
{FILE *fp;
int i,j,k,m;
long ii,jj;
i=0;
j=0;
k=2;
if((fp=fopen("prddata.txt","r")) != NULL)
{ii=filelength(fileno(fp));
jj=0L;
while(!feof(fp))
{fgets(ibuf1,130,fp);
m=strlen(ibuf1);
jj=jj+m;
if (jj>ii) break;
if(i>=istart)
{k=i-istart+2;
if((k>=2) && (k<=9))
{strncpy(ibuf2,ibuf1,70);
ibuf2[70]='\0';
disporder(k,ibuf2,GREEN,RED);
}
j++;
}
if(j>iend) break;
i++;
}
if(k<=9)
{strncpy(ibuf2,ibuf1,70);
ibuf2[70]='\0';
disporder(k,ibuf2,GREEN,RED);
}
memset(ibuf2,' ',70);
ibuf2[70]='\0';
for(i=k+1;i<10;i++)
disporder(i,ibuf2,GREEN,RED);
fclose(fp);
}
}
int scanbuf(int istart,char *istr)
{FILE *fp;
int i,j,k,m;
long ii,jj;
i=0;
j=0;
k=0;
if((fp=fopen("prddata.txt","r")) != NULL)
{ii=filelength(fileno(fp));
jj=0L;
while(!feof(fp))
{fgets(ibuf1,120,fp);
m=strlen(ibuf1);
jj=jj+m;
if(jj>=ii) break;
if(i==istart)
{strncpy(istr,ibuf1,70);
istr[70]='\0';
fclose(fp);
return TRUE;
}
i++;
}
fclose(fp);
return FALSE;
}
}
void initdata(void)
{ FILE *fpin,*fpout;
long idate,jdate;
int iyear,imonth,iday,m;
int jyear,jmonth,jday;
long ii,jj;
_strdate(buffer);
imonth=atoi(buffer);
iday=atoi(buffer+3);
iyear=atoi(buffer+6);
idate=iyear*365+imonth*30+iday;
if((fpout=fopen("olddata.txt","w")) != NULL)
if((fpin=fopen("prddata.txt","rb"))!=NULL)
{ii=filelength(fileno(fpin));
jj=0L;
while(!feof(fpin))
{fgets(ibuf1,120,fpin);
m=strlen(ibuf1);
jj=jj+m;
if(jj>ii) break;
ibuf1[110]='\n';
ibuf1[111]='\0';
strncpy(ibuf2,ibuf1+70,8);
ibuf2[8]='\0';
jmonth=atoi(ibuf2);
jday=atoi(ibuf2+3);
jyear=atoi(ibuf2+6);
jdate=jyear*365+jmonth*30+jday;
if(labs(jdate-idate)<=DAT)
fputs(ibuf1,fpout);
}
}
fclose(fpin);
fclose(fpout);
remove("prddata.txt");
rename("olddata.txt","prddata.txt");
}
int bcccheck(char *str)
{int i,j,bcc;
i=strlen(str);
bcc=str[0];
for(j=1;j<i-1;j++)
bcc=bcc ^ str[j];
if(bcc<' ') bcc=bcc+' ';
if(bcc==str[i-1])
return TRUE;
else
return FALSE;
}
int bccstr(char *str)
{int i,j,bcc;
i=strlen(str);
bcc=str[0];
for(j=1;j<i;j++)
bcc=bcc ^ str[j];
if(bcc<' ') bcc=bcc+' ';
return bcc;
}
int ErrorCheck(int Code)
{/* trap PCL error codes */
if(Code<0)
{printf("ERROR %d:",Code);
SioError(Code);
SioDone(Port);
exit(1);
}
return(0);
} /* end ErrorCheck */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -