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

📄 old_common.c~

📁 linux serial example
💻 C~
📖 第 1 页 / 共 4 页
字号:
     Leap(0x24,0x33);//     AllDevices.CurrentDownPC=2;     return -0;    }    AllDevices.CurrentDownPC=2;    if(SocketConnect.Socket_Handle!=-1)      send(SocketConnect.Socket_Handle,&SocketCommand,sizeof(SocketCommand),0);    PrintToNetwork("513 4号卡机(下左)卡已经发完,请及时更换,现已切换到3号卡机(下右)\n");    return -4;  } } else if(bb.bits.b5==0 && bb.bits.b3==0 && bb.bits.b6==0) //卡机鼓掌 {  if(AllDevices.CurrentUpPC==0)  {   PCMachine[0].Error='E';   AllDevices.CurrentUpPC=1;   if(PCMachine[1].Error=='E')   {    PCMachine[1].Error='N';    PrintToNetwork("500 1号卡机和2号卡机出现故障\n");    Leap(0x24,0x31);    return -10;   }   if(SocketConnect.Socket_Handle!=-1)    send(SocketConnect.Socket_Handle,&SocketCommand,sizeof(SocketCommand),0);   PrintToNetwork("520 1号卡机(上右)发生故障,请及时处理,现已切换到2号卡机(上左)\n");  }  else if(CurrentDevice==1)  {   PCMachine[1].Error='E';   AllDevices.CurrentUpPC=0;   if(PCMachine[0].Error=='E')   {    PCMachine[0].Error='N';    PrintToNetwork("500 1号卡机和2号卡机出现故障\n");    Leap(0x24,0x31);    return -10;   }   if(SocketConnect.Socket_Handle!=-1)    send(SocketConnect.Socket_Handle,&SocketCommand,sizeof(SocketCommand),0);   PrintToNetwork("521 2号卡机(上左)发生故障,请及时处理,现已切换到1号卡机(上右)\n");  }  else if(CurrentDevice==2)  {   PCMachine[2].Error='E';   AllDevices.CurrentDownPC=3;   if(PCMachine[3].Error=='E')   {    PCMachine[3].Error='N';    PrintToNetwork("500 1号卡机和2号卡机出现故障\n");    Leap(0x24,0x33);    return -10;   }   SocketCommand.Command=FormatInterToInt(0xf932);   SocketCommand.Content=2;   SocketCommand.Buffer[0]=0x03;   if(SocketConnect.Socket_Handle!=-1)    send(SocketConnect.Socket_Handle,&SocketCommand,sizeof(SocketCommand),0);   PrintToNetwork("522 3号卡机(下右)发生故障,请及时处理,现已切换到4号卡机(下左)\n");  }  else if(CurrentDevice==3)  {   PCMachine[3].Error='E';   AllDevices.CurrentDownPC=2;   if(PCMachine[2].Error=='E')   {    PCMachine[2].Error='N';    PrintToNetwork("500 1号卡机和2号卡机出现故障\n");    Leap(0x24,0x33);    return -10;   }  if(SocketConnect.Socket_Handle!=-1)   send(SocketConnect.Socket_Handle,&SocketCommand,sizeof(SocketCommand),0);   PrintToNetwork("522 4号卡机(下左)发生故障,请及时处理,现已切换到3号卡机(下右)\n");  }  return -10; } else {  PCMachine[CurrentDevice].Error='N';  if(CurrentDevice<=1)Leap(0x23,0x31);  else if(CurrentDevice==2 || CurrentDevice==3)Leap(0x23,0x33); }}//命令卡机准备卡int ReadyCard(int DeviceIndex){ int rel; unsigned char DeviceID; byte_bit bb; CharToInt  cti; PrintToNetwork("正在准备卡\n"); if(DeviceIndex==HS4) {  printf("in HS4\n");  if(AllDevices.CurrentUpPC==0)  {   PrintToNetwork("1号卡机工作(上右)\n");   DeviceID='A';   CLR_RTS(HS4);  }  else if(AllDevices.CurrentUpPC==1)  {   PrintToNetwork("2号卡机工作(上左)\n");   SET_RTS(HS4);   DeviceID='B';  } } else if(DeviceIndex==HS2) {  if(AllDevices.CurrentDownPC==2)  {   PrintToNetwork("3号卡机工作(下右)\n");   DeviceID='A';   CLR_RTS(HS2);     }  else if(AllDevices.CurrentDownPC==3)  {   PrintToNetwork("4号卡机工作(下左)\n");   DeviceID='B';   SET_RTS(HS2);  } } if(DeviceID=='A') {  Command=0x05;  DataLength=0;  CanverContentToBSYN(DeviceIndex);  WriteToComm(DeviceIndex,WDataLength);  AutoDetect(DeviceIndex);  ReadFromComm(DeviceIndex,0);  AutoDetect(DeviceIndex);  rel=ReadFromComm(DeviceIndex,0);  if(rel==-10)return -10;  if(DeviceIndex==HS4)  {   PCMachine[0].CardNumber-=1;   PCMachine[0].PublishNumber+=1;  }  else if(DeviceIndex==HS2)  {   PCMachine[2].CardNumber-=1;   PCMachine[2].PublishNumber+=1;  } } else {  Command=0x05;  DataLength=0;  CanverContentToBSYN(DeviceIndex);  WriteToComm(DeviceIndex,WDataLength);  AutoDetect(DeviceIndex);  ReadFromComm(DeviceIndex,0);  AutoDetect(DeviceIndex);  rel=ReadFromComm(DeviceIndex,0);  if(rel==-10)return -10;  if(DeviceIndex==HS4)  {   PCMachine[1].CardNumber-=1;   PCMachine[1].PublishNumber+=1;  }  else if(DeviceIndex==HS2)  {   PCMachine[3].CardNumber-=1;   PCMachine[3].PublishNumber+=1;  } } return rel;}int ExecReadyCard(int DeviceIndex){ int er; er=0; while(ReadyCard(DeviceIndex)==-10) {  if(er<10)er+=1;  else return -1; } return 0;}//出卡,State==0正常出卡 State==1故障出卡int OutCard(int State,unsigned char DeviceID){ if(State==1)  //正常是错误状态=1 现在为调试改为0 {  AllDevices.BadCardNumber+=1;  if(DeviceID=='A')  {   Command=0x22;   DataBuffer[0]=0x35;   DataLength=1;   CanverContentToBSYN(HS1);   WriteToComm(HS1,WDataLength);   AutoDetect(HS1);   ReadFromComm(HS1,0);  }  else if(DeviceID=='B')  {   Command=0x22;   DataBuffer[0]=0x36;   DataLength=1;   CanverContentToBSYN(HS1);   WriteToComm(HS1,WDataLength);   AutoDetect(HS1);   ReadFromComm(HS1,0);  } } else {  if(DeviceID=='A')  {   Command=0x21;   DataBuffer[0]=0x35;   DataLength=1;   CanverContentToBSYN(HS1);   WriteToComm(HS1,WDataLength);   AutoDetect(HS1);   ReadFromComm(HS1,0);   Leap(0x24,0x32);  }  else if(DeviceID=='B')  {   Command=0x21;   DataBuffer[0]=0x36;   DataLength=1;   CanverContentToBSYN(HS1);   WriteToComm(HS1,WDataLength);   AutoDetect(HS1);   ReadFromComm(HS1,0);   Leap(0x24,0x34);  } } return 0;}//车辆通过int VcoterOK(unsigned char State){ Command=0x42; DataBuffer[0]=11+State; DataBuffer[1]=0x01; DataLength=2; CanverContentToBSYN(HS5); WriteToComm(HS5,WDataLength); AutoDetect(HS5); ReadFromComm(HS5,0); Command=0x42; DataBuffer[0]=14; DataBuffer[1]=State; DataLength=2; CanverContentToBSYN(HS5); WriteToComm(HS5,WDataLength); AutoDetect(HS5); ReadFromComm(HS5,0); return 0;}int TestCard(unsigned char DeviceID){ int i; for(i=0;i<4;i++) {    if(DeviceID=='A')   ExecReadyCard(HS4);  else if(DeviceID=='B')   ExecReadyCard(HS2);  Command=0x33;  DataBuffer[0]=0x00;  DataBuffer[1]=0x04;  for(i=0;i<16;i++)   DataBuffer[2+i]=0x60;  DataLength=18;  if(DeviceID=='B')  {   SET_RTS(HS3);  }  else CLR_RTS(HS3);  CanverContentTo6003(HS3);  WriteToComm(HS3,WDataLength);  delay(450000);  ReadFromComm6003(HS3,0);  if(Result==0x01)return 0;  else  {   OutCard(1,DeviceID);   delay(500000);  } } if(DeviceID=='A')  while(ReadyCard(HS4)==-10); else if(DeviceID=='B')  while(ReadyCard(HS2)==-10); return -1;}int ExecCKKZFunc(unsigned char cm){ int rel; inBusy=0x55aa; switch(cm) {  case 0x20:Leap(0x23,0x31);Leap(0x23,0x33);break;//Device Initialize  case 0x21:break;//  case 0x22:break;  case 0x23:break;  case 0x24:break;  case 0x25:  BEGIN   if(DataBuffer[0]==0x31)   {    PrintToNetwork("上出控制器电机故障");   }   else if(DataBuffer[0]==0x32)   {    PrintToNetwork("下出控制器电机故障");   }   if(DataBuffer[0]==0x33 || DataBuffer[0]==0x34)//发卡按钮   {    rel=PublishCard();    if(rel==-1)printf("No Vcoter\n");    else if(rel==-2)printf("Published!!\n");   }   else if(DataBuffer[0]==0x35)//发卡线圈   {    if(DataBuffer[1]==0x30)AllDevices.Cad='Y';    else if(DataBuffer[1]==0x31)AllDevices.Cad=AllDevices.Publish='N';   }  END } inBusy=0; return 0;}int ExecIOCOFunc(unsigned char cm){ switch(cm) {  case 0x40:break;//Device Initialize  case 0x41:  BEGIN   switch(DataBuffer[0])   {    case 0x02:    BEGIN     Command=0x42;     DataBuffer[0]=15;     DataLength=2;     CanverContentToBSYN(HS5);     WriteToComm(HS5,WDataLength);     AutoDetect(HS5);     ReadFromComm(HS5,0);    END   case 0x04: //抓拍线圈    BEGIN    END   case 0x05:    BEGIN    if(DataBuffer[1]==0x01)    {     VcoterOK(0x00);    }    END   }  END  case 0x42:break; } return 0;}int ExecCARWFunc(unsigned char cm,unsigned char DeviceID){ int i; switch(cm) {  case 0x33:  BEGIN   delay(100000);   ReadFromComm6003(HS3,0);   Command=cm;   DataBuffer[0]=0x00;   DataBuffer[1]=0x04;   for(i=0;i<16;i++)    DataBuffer[2+i]=0x60;   DataLength=18;   if(DeviceID=='B')   {    SET_RTS(HS3);   }   else CLR_RTS(HS3);   CanverContentTo6003(HS3);   WriteToComm(HS3,WDataLength);   delay(450000);   ReadFromComm6003(HS3,0);   if(Result==0x01)   {     AllDevices.Publish='Y';     OutCard(0,DeviceID);     delay(400000);     SocketCommand.Command=FormatInterToInt(0xf930);     if(DeviceID=='A')      SocketCommand.Content=AllDevices.CurrentUpPC;     else if(DeviceID=='B')      SocketCommand.Content=AllDevices.CurrentDownPC;     if(SocketConnect.Socket_Handle!=-1)      send(SocketConnect.Socket_Handle,&SocketCommand,sizeof(SocketCommand),0);     PrintToNetwork("发卡成功\n");    return 0;   }   else if(Result==0x80)   {    OutCard(1,DeviceID);    if(DeviceID=='A')    {     delay(500000);     SocketCommand.Command=FormatInterToInt(0xf931);     SocketCommand.Content=AllDevices.CurrentUpPC;     if(SocketConnect.Socket_Handle!=-1)      send(SocketConnect.Socket_Handle,&SocketCommand,sizeof(SocketCommand),0);     PrintToNetwork("上出卡器检测到卡片读写错误,稍后准备下一张\n");    }    else if(DeviceID=='B')    {     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;   }   else if(Result==0x00)   {    OutCard(1,DeviceID);    AllDevices.BadCardNumber+=1;    if(DeviceID=='A')    {     delay(500000);     SocketCommand.Command=FormatInterToInt(0xf931);     SocketCommand.Content=AllDevices.CurrentUpPC;     if(SocketConnect.Socket_Handle!=-1)      send(SocketConnect.Socket_Handle,&SocketCommand,sizeof(SocketCommand),0);     PrintToNetwork("上出卡器没有检测到卡片或卡片损坏,稍后准备下一张\n");    }    else if(DeviceID=='B')    {     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);   }   else if(Result==0x81)   {    OutCard(1,DeviceID);    SocketCommand.Command=FormatInterToInt(0xf931);    if(DeviceID=='A')SocketCommand.Content=AllDevices.CurrentUpPC;    else SocketCommand.Content=AllDevices.CurrentDownPC;    if(SocketConnect.Socket_Handle!=-1)     send(SocketConnect.Socket_Handle,&SocketCommand,sizeof(SocketCommand),0);    PrintToNetwork("卡片密钥认证错误,正在下载密钥,稍后准备下一张\n");    Command=0x34;    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);    delay(5000);    ReadFromComm6003(HS3,0);    return -3;   }   else   {    OutCard(1,DeviceID);    AllDevices.BadCardNumber+=1;    if(DeviceID=='A')    {     delay(500000);     SocketCommand.Command=FormatInterToInt(0xf931);     SocketCommand.Content=AllDevices.CurrentUpPC;     if(SocketConnect.Socket_Handle!=-1)      send(SocketConnect.Socket_Handle,&SocketCommand,sizeof(SocketCommand),0);     PrintToNetwork("上出卡器检测到未知错误,稍后准备下一张\n");    }    else if(DeviceID=='B')    {

⌨️ 快捷键说明

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