/// <summary> /// 从FICT PLC 接收数据 /// </summary> /// <param name="outdata"></param> /// <param name="msgflag">是否显示結果</param> private void receivePLC(ref string outdata, bool msgflag) { int iA = -1; int iB = -1; if (readPLC(FICT_PLC_Read_AddressA, ref iA) && readPLC(FICT_PLC_Read_AddressB, ref iB)) { try { outdata = Other.Chr(iA) + Other.Chr(iB); } catch (Exception) { } if (msgflag) { SubFunction.updateMessage(lstCommandList, "FICT->PC:" + outdata); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "FICT->PC:" + outdata); SubFunction.saveLog(Param.logType.COMLOG.ToString(), "FICT->PC:" + outdata); } } else { SubFunction.updateMessage(lstCommandList, "FICT->PC:" + outdata + " Fail"); SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "FICT->PC:" + outdata + " Fail"); SubFunction.saveLog(Param.logType.COMLOG.ToString(), "FICT->PC:" + outdata + " Fail"); } }
private void ScanRetryReadBarcode(SerialPort sp, string str1, string str2) { updateMessage(lstMessage, str1 + " close..."); saveLog(p.LogType.SysLog, str1 + " close..."); if (p.Send_Command_Use_Hex) { sendHex(sp, p.Close_Scan_Command); } else { if (p.Close_Add_Enter) { sendData(sp, p.Close_Scan_Command + Other.Chr(13)); } else { sendData(sp, p.Close_Scan_Command); } } updateMessage(lstMessage, str2 + p.Close_Scan_Command); saveLog(p.LogType.SysLog, str2 + p.Close_Scan_Command); Delay(500); if (p.Send_Command_Use_Hex) { sendHex(sp, p.Open_Scan_Command); } else { if (p.Open_Add_Enter) { sendData(sp, p.Open_Scan_Command + Other.Chr(13)); } else { sendData(sp, p.Open_Scan_Command); } } updateMessage(lstMessage, str2 + p.Open_Scan_Command); saveLog(p.LogType.SysLog, str2 + p.Open_Scan_Command); }
private void spBar_B_DataReceived(object sender, SerialDataReceivedEventArgs e) { if (spBar_B.BytesToRead == 0) { return; } try { string sReceive = spBar_B.ReadTo(Other.Chr(13)); spBar_B.DiscardInBuffer(); sReceive = sReceive.Trim(); this.Invoke((EventHandler)(delegate { updateMessage(lstMessage, "BarB->PC:" + sReceive); saveLog(p.LogType.SysLog, "BarB->PC:" + sReceive); updateMessage(lstMessage, "BarB:" + sReceive); saveLog(p.LogType.SysLog, "BarB:" + sReceive); updateMessage(lstBar, "BarB:" + sReceive); p.BarB = sReceive.Trim().ToUpper(); txtBarB.Text = p.BarB; saveLog(p.LogType.SNLog, "BarB:" + p.BarB); //check A,B,C,D if (_runing) { if (CheckAllBarComplete()) { sendData(spPLC, "B"); updateMessage(lstMessage, "PC->PLC:B"); saveLog(p.LogType.SysLog, "PC->PLC:B"); } else { } } })); } catch (Exception) { //throw; } }
/// <summary> /// 打开条码枪串口,并保存log /// </summary> /// <param name="sp">串口控件</param> /// <param name="str2">log前缀,如”PC->BarA:"</param> private void closeScanner(SerialPort sp, string str2) { //sp.PortName = portname; if (p.Send_Command_Use_Hex) { sendHex(sp, p.Close_Scan_Command); } else { if (p.Close_Add_Enter) { sendData(sp, p.Close_Scan_Command + Other.Chr(13)); } else { sendData(sp, p.Close_Scan_Command); } } updateMessage(lstMessage, str2 + p.Close_Scan_Command); saveLog(p.LogType.SysLog, str2 + p.Close_Scan_Command); closeSerialPort(sp); }
/// <summary> /// 打开条码枪串口,并保存log /// </summary> /// <param name="portname">串口号</param> /// <param name="sp">串口控件</param> /// <param name="str2">log前缀,如”PC->BarA:"</param> private void openScanner(SerialPort sp, string portname, string str2) { openSerialPort(sp, portname); if (p.Send_Command_Use_Hex) { sendHex(sp, p.Open_Scan_Command); } else { if (p.Open_Add_Enter) { sendData(sp, p.Open_Scan_Command + Other.Chr(13)); } else { sendData(sp, p.Open_Scan_Command); } } updateMessage(lstMessage, str2 + p.Open_Scan_Command); saveLog(p.LogType.SysLog, str2 + p.Open_Scan_Command); }
private void spPLC_DataReceived(object sender, SerialDataReceivedEventArgs e) { if (spPLC.BytesToRead == 0) { return; } try { string sReceive = spPLC.ReadExisting(); spPLC.DiscardInBuffer(); sReceive = sReceive.Trim(); this.Invoke((EventHandler)(delegate { updateMessage(lstMessage, "PLC->PC:" + sReceive); saveLog(p.LogType.SysLog, "PLC->PC:" + sReceive); if (sReceive == "A") { updateMessage(lstMessage, "PLC ready OK,start to open sanner to read barcode..."); saveLog(p.LogType.SysLog, "PLC ready OK,start to open sanner to read barcode..."); txtBarA.Text = string.Empty; txtBarB.Text = string.Empty; txtBarC.Text = string.Empty; txtBarD.Text = string.Empty; p.BarA = string.Empty; p.BarB = string.Empty; p.BarC = string.Empty; p.BarD = string.Empty; updateMessage(lstMessage, "Open Scanner & start timeout counting..."); saveLog(p.LogType.SysLog, "Open Scanner & start timeout counting..."); if (p.Send_Command_Use_Hex) { sendHex(spBar_A, p.Open_Scan_Command); sendHex(spBar_B, p.Open_Scan_Command); sendHex(spBar_C, p.Open_Scan_Command); sendHex(spBar_D, p.Open_Scan_Command); } else { if (p.Open_Add_Enter) { sendData(spBar_A, p.Open_Scan_Command + Other.Chr(13)); sendData(spBar_B, p.Open_Scan_Command + Other.Chr(13)); sendData(spBar_C, p.Open_Scan_Command + Other.Chr(13)); sendData(spBar_D, p.Open_Scan_Command + Other.Chr(13)); } else { sendData(spBar_A, p.Open_Scan_Command); sendData(spBar_B, p.Open_Scan_Command); sendData(spBar_C, p.Open_Scan_Command); sendData(spBar_D, p.Open_Scan_Command); } } updateMessage(lstMessage, "PC->BarA:" + p.Open_Scan_Command); updateMessage(lstMessage, "PC->BarB:" + p.Open_Scan_Command); updateMessage(lstMessage, "PC->BarC:" + p.Open_Scan_Command); updateMessage(lstMessage, "PC->BarD:" + p.Open_Scan_Command); saveLog(p.LogType.SysLog, "PC->BarA:" + p.Open_Scan_Command); saveLog(p.LogType.SysLog, "PC->BarB:" + p.Open_Scan_Command); saveLog(p.LogType.SysLog, "PC->BarC:" + p.Open_Scan_Command); saveLog(p.LogType.SysLog, "PC->BarD:" + p.Open_Scan_Command); timerScanTimeout.Enabled = true; timerScanTimeout.Start(); } })); } catch (Exception) { // throw; } }