⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 old_common.c~

📁 linux serial example
💻 C~
📖 第 1 页 / 共 4 页
字号:
     delay(500000);     SocketCommand.Command=FormatInterToInt(0xf931);     SocketCommand.Content=AllDevices.CurrentDownPC;     if(SocketConnect.Socket_Handle!=-1)      send(SocketConnect.Socket_Handle,&SocketCommand,sizeof(SocketCommand),0);     PrintToNetwork("下出卡器检测到未知错误,稍后准备下一张\n");    }    return -3;//ExecCARWFunc(0x33,DeviceID);   }  END  case 0x34:  BEGIN   DataBuffer[0]=0x00;   DataBuffer[1]=0x01;   DataBuffer[2]=0xa0;   DataBuffer[3]=0xa1;   DataBuffer[4]=0xa2;   DataBuffer[5]=0xa3;   DataBuffer[6]=0xa4;   DataBuffer[7]=0xa5;   DataLength=8;   CanverContentTo6003(HS3);   WriteToComm(HS3,WDataLength);   ReadFromComm6003(HS3,0);   delay(10000);   if(Result==0x01) return 0;   else return -3;  END  case 0x08:  BEGIN   DataLength=0;   CanverContentTo6003(HS3);   WriteToComm(HS3,WDataLength);   delay(10000);   ReadFromComm6003(HS3,0);   if(Result==0x01) return 0;   else return -3;  END } return 0;}int PublishCard(){   int rel;    int i;    if(DataBuffer[0]==0x33 && DataBuffer[1]==0x31)   {    if(WMode==0x50)    {     if(AllDevices.Cad!='Y')return -1;     if(AllDevices.Publish=='Y')return -2;    }    else    {     if(AllDevices.Publish=='Y')     {      SocketCommand.Command=FormatInterToInt(0xf934);      if(SocketConnect.Socket_Handle!=-1)      send(SocketConnect.Socket_Handle,&SocketCommand,sizeof(SocketCommand),0);      PrintToNetwork("系统检测到有车多次取卡\n");     }    }    Leap(0x23,0x32);    if(RWMode==0x55)    {      OutCard(0,'A');      VcoterOK(0x01);      delay(50000);      ExecReadyCard(HS4);      Leap(0x24,0x32);      return 0;    }    for(i=0;i<5;i++)    {     rel=ExecCARWFunc(0x33,'A');     if(rel==0)     {      VcoterOK(0x01);      TestCard('A');      return 0;     }     else if(rel==-2)     {      AllDevices.Publish='E';      ExecReadyCard(HS4);      Leap(0x24,0x32);      return -1;     }     else     {      ExecReadyCard(HS4);      delay(500000);     }    }    Leap(0x24,0x32);    return -1;   }   else if(DataBuffer[0]==0x34 && DataBuffer[1]==0x31)   {    if(WMode==0x50)    {     if(AllDevices.Cad!='Y')return -1;     if(AllDevices.Publish=='Y')return -2;    }    else    {      SocketCommand.Command=FormatInterToInt(0xf934);      if(SocketConnect.Socket_Handle!=-1)      send(SocketConnect.Socket_Handle,&SocketCommand,sizeof(SocketCommand),0);      PrintToNetwork("系统检测到有车多次取卡\n");    }    Leap(0x23,0x34);    if(RWMode==0x55)    {      OutCard(0,'B');      VcoterOK(0x01);      delay(50000);      ExecReadyCard(HS2);      Leap(0x24,0x34);      return 0;    }    for(i=0;i<5;i++)    {     rel=ExecCARWFunc(0x33,'B');     if(rel==0)     {      VcoterOK(0x01);      TestCard('B');      return 0;     }     else if(rel==-2)     {      AllDevices.Publish='E';      Leap(0x24,0x34);      ExecReadyCard(HS2);      return -1;     }     else     {      ExecReadyCard(HS2);      delay(500000);     }    }    Leap(0x24,0x34);    return -1;   }   return -1;}int Leap(unsigned char chCommand,unsigned char chState){      Command=chCommand;      DataBuffer[0]=chState;      DataLength=0x01;      CanverContentToBSYN(HS1);      WriteToComm(HS1,WDataLength);      AutoDetect(HS1);      ReadFromComm(HS1,0);}int InitCKKZ(){ Command=0x24; DataBuffer[0]=0x41; DataLength=0x01; CanverContentToBSYN(HS1); WriteToComm(HS1,WDataLength); delay(5000); ReadFromComm(HS1,0);  Command=0x23; DataBuffer[0]=0x31; DataLength=0x01; CanverContentToBSYN(HS1); WriteToComm(HS1,WDataLength); delay(5000); ReadFromComm(HS1,0); Command=0x23; DataBuffer[0]=0x33; DataLength=0x01; CanverContentToBSYN(HS1); WriteToComm(HS1,WDataLength); delay(5000); ReadFromComm(HS1,0);  return 0;}int InitMAPC(){ int m1,m2; CharToInt  cti; CharToLong ctl; byte_bit bb; Command=0x06; DataLength=0; CanverContentToBSYN(HS4); m1=-1; WriteToComm(HS4,WDataLength); ShortBlockDetect(HS4); ReadFromComm(HS4,0); ShortBlockDetect(HS4); ReadFromComm(HS4,0); cti.ch2.by0=DataBuffer[1]; cti.ch2.by1=DataBuffer[2]; bb.ch=DataBuffer[0]; if(bb.bits.b5==1) //no card packeg {   AllDevices.CurrentUpPC=1;   PCMachine[0].State=0x02; } else if(bb.bits.b1==0) //no card {   AllDevices.CurrentUpPC=0x01; } else m1=0; PCMachine[0].State=0x00; PCMachine[0].CardNumber=FormatIntToInter2(cti.i); if(PCMachine[0].CardNumber==0)  PCMachine[0].State=0x01;  cti.ch2.by0=DataBuffer[3]; cti.ch2.by1=DataBuffer[4]; PCMachine[0].MaxCard=FormatIntToInter2(cti.i);; ctl.ch4.by0=DataBuffer[5]; ctl.ch4.by1=DataBuffer[6]; ctl.ch4.by2=DataBuffer[7]; ctl.ch4.by3=DataBuffer[8]; PCMachine[0].Params=ctl.l; ctl.ch4.by0=DataBuffer[9]; ctl.ch4.by1=DataBuffer[10]; ctl.ch4.by2=DataBuffer[11]; ctl.ch4.by3=DataBuffer[12]; PCMachine[0].ID=ctl.l; printf("MAPC1 Data is:"); for(m2=0;m2<DataLength;m2++)  printf("%x ",DataBuffer[m2]); printf("\nMAPC1 Card Number is:%x ID is:%x MAX Card is:%x\n",PCMachine[0].CardNumber,PCMachine[0].ID,PCMachine[0].MaxCard);  bzero(&DataBuffer,DataLength);    Command=0x06; DataLength=0; CanverContentToBSYN(HS4); SET_RTS(HS4); WriteToComm(HS4,WDataLength); ShortBlockDetect(HS4); ReadFromComm(HS4,0); ShortBlockDetect(HS4); ReadFromComm(HS4,0); CLR_RTS(HS4); cti.ch2.by0=DataBuffer[1]; cti.ch2.by1=DataBuffer[2]; bb.ch=DataBuffer[0]; if(m1==-1) {  if(bb.bits.b5==1) //no card packeg  {   // AllDevices.CurrentUpPC=1;   PrintToNetwork("1号和2号卡机没有卡夹,请及时处理\n");   PCMachine[1].State=0x02;  }  else if(bb.bits.b1==0) //no card  {   // AllDevices.CurrentUpPC=1;   PrintToNetwork("1号和2号卡机无卡,请及时处理\n");   PCMachine[1].State=0x01;  }  else AllDevices.CurrentUpPC=0; } PCMachine[1].State=0x00; PCMachine[1].CardNumber=FormatIntToInter2(cti.i); if(PCMachine[1].CardNumber==0)  PCMachine[1].State=0x01; cti.ch2.by0=DataBuffer[3]; cti.ch2.by1=DataBuffer[4]; PCMachine[1].MaxCard=FormatIntToInter2(cti.i);  ctl.ch4.by0=DataBuffer[5]; ctl.ch4.by1=DataBuffer[6]; ctl.ch4.by2=DataBuffer[7]; ctl.ch4.by3=DataBuffer[8]; PCMachine[1].Params=ctl.l; ctl.ch4.by0=DataBuffer[9]; ctl.ch4.by1=DataBuffer[10]; ctl.ch4.by2=DataBuffer[11]; ctl.ch4.by3=DataBuffer[12]; PCMachine[1].ID=ctl.l; printf("MAPC2 Data is:"); for(m2=0;m2<DataLength;m2++)  printf("%x ",DataBuffer[m2]); printf("\nMAPC2 Card Number is:%x ID is:%i MAX Card is:%i\n",PCMachine[1].CardNumber,PCMachine[1].ID,PCMachine[1].MaxCard);   Command=0x06; DataLength=0; CanverContentToBSYN(HS4); m2=-1;  WriteToComm(HS2,WDataLength); ShortBlockDetect(HS2); ReadFromComm(HS2,0); ShortBlockDetect(HS2); ReadFromComm(HS2,0); cti.ch2.by0=DataBuffer[1]; cti.ch2.by1=DataBuffer[2]; bb.ch=DataBuffer[0]; if(bb.bits.b5==1) {   AllDevices.CurrentDownPC=3;   PCMachine[2].State=0x02; } else if(bb.bits.b1==0) {   AllDevices.CurrentDownPC=3;   PCMachine[2].State=0x01; } else m2=2; PCMachine[2].State=0x00; PCMachine[2].CardNumber=FormatIntToInter2(cti.i); if(PCMachine[2].CardNumber==0)  PCMachine[2].State=0x01; cti.ch2.by0=DataBuffer[3]; cti.ch2.by1=DataBuffer[4]; PCMachine[2].MaxCard=FormatIntToInter2(cti.i);  ctl.ch4.by0=DataBuffer[5]; ctl.ch4.by1=DataBuffer[6]; ctl.ch4.by2=DataBuffer[7]; ctl.ch4.by3=DataBuffer[8]; PCMachine[2].Params=ctl.l; ctl.ch4.by0=DataBuffer[9]; ctl.ch4.by1=DataBuffer[10]; ctl.ch4.by2=DataBuffer[11]; ctl.ch4.by3=DataBuffer[12]; PCMachine[2].ID=ctl.l; printf("MAPC3 Data is:"); for(m2=0;m2<DataLength;m2++)  printf("%x ",DataBuffer[m2]); printf("\nMAPC3 Card Number is:%x ID is:%x MAX Card is:%x\n",PCMachine[2].CardNumber,PCMachine[2].ID,PCMachine[2].MaxCard);   Command=0x06; DataLength=0; CanverContentToBSYN(HS4); SET_RTS(HS2); WriteToComm(HS2,WDataLength); ShortBlockDetect(HS2); ReadFromComm(HS2,0); ShortBlockDetect(HS2); ReadFromComm(HS2,0); CLR_RTS(HS2); cti.ch2.by0=DataBuffer[1]; cti.ch2.by1=DataBuffer[2]; bb.ch=DataBuffer[0]; if(m2==-1) {  if(bb.bits.b5==1)  {   PrintToNetwork("3号和4号卡机没有卡夹,请及时处理\n");   PCMachine[3].State=0x02;  }  else if(bb.bits.b1==0)  {   PrintToNetwork("3号和4号卡机无卡,请及时处理\n");   PCMachine[3].State=0x01;  }  else AllDevices.CurrentDownPC=3; }  PCMachine[3].State=0x00; printf("%x---%x ",cti.ch2.by0,cti.ch2.by1); PCMachine[3].CardNumber=FormatIntToInter2(cti.i); if(PCMachine[3].CardNumber==0)  PCMachine[3].State=0x01; printf("%x---%x ",cti.ch2.by0,cti.ch2.by1); cti.i=0; cti.i=FormatInterToInt2(PCMachine[3].CardNumber); printf("%x---%x ",cti.ch2.by0,cti.ch2.by1);  cti.ch2.by0=DataBuffer[3]; cti.ch2.by1=DataBuffer[4]; PCMachine[3].MaxCard=FormatIntToInter2(cti.i);  ctl.ch4.by0=DataBuffer[5]; ctl.ch4.by1=DataBuffer[6]; ctl.ch4.by2=DataBuffer[7]; ctl.ch4.by3=DataBuffer[8]; PCMachine[3].Params=ctl.l; ctl.ch4.by0=DataBuffer[9]; ctl.ch4.by1=DataBuffer[10]; ctl.ch4.by2=DataBuffer[11]; ctl.ch4.by3=DataBuffer[12]; PCMachine[3].ID=ctl.l; printf("MAPC4 Data is:"); for(m2=0;m2<DataLength;m2++)  printf("%x ",DataBuffer[m2]); printf("\nMAPC4 Card Number is:%x ID is:%x MAX Card is:%x\n",PCMachine[3].CardNumber,PCMachine[3].ID,PCMachine[3].MaxCard);  return 0;}int InitIOCO(){ byte_bit bb; Command=0x40; DataLength=0x00; CanverContentToBSYN(HS5); WriteToComm(HS5,WDataLength); ShortBlockDetect(HS5); ReadFromComm(HS5,0); bb.ch=DataBuffer[1]; if(bb.bits.b2==1) {  AllDevices.HHrail='O';  Command=0x42;  DataBuffer[0]=15;  DataBuffer[1]=0x01;  DataLength=2;  CanverContentToBSYN(HS5);  WriteToComm(HS5,WDataLength);  ShortBlockDetect(HS5);  ReadFromComm(HS5,0); } else {  AllDevices.HHrail='C';  Command=0x42;  DataBuffer[0]=15;  DataBuffer[1]=0x00;  DataLength=2;  CanverContentToBSYN(HS5);  WriteToComm(HS5,WDataLength);  ShortBlockDetect(HS5);  ReadFromComm(HS5,0); } VcoterOK(0x00); return 0;}int MainInitialize(){ InitMAPC(); InitIOCO(); InitCKKZ(); ExecCARWFunc(0x34,'A'); ExecCARWFunc(0x34,'B'); return 0;}//initialize galobe Variantvoid Initialize(){ long ti; struct tm *tm; DEBUG=-1;               //调试状态 SocketReadLength=sizeof(struct __SOCKETCOMMAND); Connects=0; //socket连接计数器 SocketConnect.Socket_Handle=-1; AllDevices.CurrentUpPC=0; //默认的上发卡机 AllDevices.CurrentDownPC=2; //默认的下发卡机 AllDevices.BadCardNumber=0; //坏卡数 WMode=0x50; RWMode=0x50; time(&ti); tm=localtime(&ti); printf("%i-%i-%i %i:%i:%i\n",tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);}int main(){ unsigned long ul; Initialize(); if(CreateSocket()!=0) {  printf("Open Socket Error\n");  return -1; } printf("Socket open ok!!!\n"); SocketReadLength=sizeof(struct __SOCKETCOMMAND); Connects=0; //socket连接计数器 SocketConnect.Socket_Handle=-1;//nitilizeComm(1,9600,8,1,-1); //itilizeComm(2,9600,8,1,-1);//nitilizeComm(3,9600,8,1,-1);//nitilizeComm(4,9600,8,1,-1);//nitilizeComm(5,9600,8,1,-1);//ainInitialize();//utCard(1,'A');//utCard(1,'B');//elay(50000);//xecReadyCard(HS4);//xecReadyCard(HS2); ListenAllDeviceOnRead_Error(); return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -