void Dataprocess(object sender, CommEventArgs e) { if (isShiftDataForm) { return; } if ((DTPLCcmd.CmdReadDDataOut != null)) { if ((comManager.IsReadingD) && (!comManager.IsReadingM)) { DTPLCcmd.UnPackCmdReadDDataIn(dataForm, e.Byte_buffer, DPlcInfo); } } if ((DTPLCcmd.CmdReadMDataOut != null)) { if ((comManager.IsReadingM) && (!comManager.IsReadingD)) { DTPLCcmd.UnPackCmdReadMDataIn(dataForm, e.Byte_buffer, MPlcInfoAll); } } //数据处理 以及更新 datagridview // DTPLCcmd.UnPackCmdReadDMDataIn(dataForm,e.Byte_buffer, DPlcInfo, MPlcInfoAll); Application.DoEvents(); e.Byte_buffer = null; //GC.Collect(); //GC.WaitForPendingFinalizers(); }
public easycomMangager(PortParam portparam) { SerialPort = new SerialPortListener(portparam.m_portName, portparam.m_baudRate); SerialPort.PortName = portparam.m_portName; SerialPort.BaudRate = portparam.m_baudRate; SerialPort.DataBits = portparam.m_dataBits; SerialPort.StopBits = portparam.m_stopbits; SerialPort.Parity = portparam.m_parity; SerialPort.Handshake = portparam.m_handshake; SerialPort.ReceivedBytesThreshold = portparam.m_receivedBytesThreshold; SerialPort.ReceiveTimeout = portparam.m_receiveTimeout; SerialPort.SendInterval = portparam.m_sendInterval; SerialPort.ReadBufferSize = portparam.m_readBufferSize; SerialPort.OnSerialPortReceived += new OnReceivedData(XJPLC_SerialPort_Received); m_buffer = new List <byte>(); ErrorConnTimer = new System.Timers.Timer(Constant.XJConnectTimeOut); //这里0.3 秒别改 加到常量里 工控机性能不行 ErrorConnTimer.Enabled = false; ErrorConnTimer.AutoReset = true; ErrorConnTimer.Elapsed += new System.Timers.ElapsedEventHandler(ErrorConnTimerEvent); ErrorConnCount = 0; DataProcessEventArgs = new CommEventArgs(); openPort(); }
void Dataprocess(object sender, CommEventArgs e) { byte[] s = (byte[])e.Byte_buffer.Clone(); if (s.Count() != 9) { return; } byte[] value = s.Skip(3).Take(2).ToArray(); exeCmd(value); }
void Dataprocess(object sender, CommEventArgs e) { if (isShiftDataForm) { return; } //数据处理 以及更新 datagridview XJPLCcmd.UnPackCmdReadDMDataIn(dataForm, e.Byte_buffer, DPlcInfo, MPlcInfoAll); Application.DoEvents(); e.Byte_buffer = null; //GC.Collect(); //GC.WaitForPendingFinalizers(); }
private void CommOverlappedIo_CommEvent(object sender, CommEventArgs e) { SerialData dataFlags = (SerialData)(e.EventType & c_DataFlags); if (dataFlags != 0) { OnDataReceived(this, new SerialDataReceivedEventArgs(dataFlags)); } SerialPinChange pinFlags = (SerialPinChange)(e.EventType & c_PinFlags); if (pinFlags != 0) { OnPinChanged(this, new SerialPinChangedEventArgs(pinFlags)); } }
/// <summary> /// 接收到SOCKET服务器传来数据的函数 /// </summary> /// <param name="sender"></param> /// <param name="args">通信事件参数</param> void AsynServer_OnReceive(object sender, CommEventArgs args) { CommEventArgs commArgs = args; string address = commArgs.SourceAddress; commArgs.SourceAddress = args.TargetAddress; commArgs.TargetAddress = address; if (args.Params != null) { for (int i = 0; i < args.Params.Count; i++) { if (commArgs.Params[i].CMD == CommCMD.扫描产品编号) { if (commArgs.Params[i].Code == TagCode.获取条形码) { if (txtProductCode.InvokeRequired) { this.Invoke(new GlobalObject.DelegateCollection.MessageHandle(this.UpdateProductCode), new object[] { commArgs.Params[i].DataValue.ToString() }); } else { txtProductCode.Text = commArgs.Params[i].DataValue.ToString(); } } } } } for (int i = 0; i < commArgs.Params.Count; i++) { commArgs.Params[i].CMD = CommCMD.应答; } string error; m_server.Send(commArgs, out error); }
void CommEvent_CommReceiveHandler(object sender, CommEventArgs e) { var text = "Response:" + ConvertHelper.BytesToHexString(e.CommDatas, e.CommDatasLen); WriteLog(text); }
void asynServer_OnReceive(object sender, CommEventArgs args) { CommEventArgs commArgs = args; string address = commArgs.SourceAddress; commArgs.SourceAddress = args.TargetAddress; commArgs.TargetAddress = address; if (args.Params != null) { for (int i = 0; i < args.Params.Count; i++) { if (commArgs.Params[i].CMD == CommCMD.用户登陆) { Socket_UserInfo userInfo = commArgs.Params[i].DataValue as Socket_UserInfo; RequestUserProcessor userProcessor = new RequestUserProcessor(); commArgs.Params[i].DataValue = userProcessor.ReceiveUserInfo(userInfo); } else if (commArgs.Params[i].CMD == CommCMD.初始化) { string workbench = commArgs.Params[i].DataValue as string; RequestWorkBenchInfo wbProcessor = new RequestWorkBenchInfo(); if (commArgs.Params[i].Code == TagCode.工位产品列表) { commArgs.Params[i].DataValue = wbProcessor.GetProductInfo(workbench); } else if (commArgs.Params[i].Code == TagCode.工位指定产品零件信息) { commArgs.Params[i].DataValue = wbProcessor.GetWorkBenchInfo(workbench); } } else if (commArgs.Params[i].CMD == CommCMD.请求) { if (commArgs.Params[i].Code == TagCode.获取装配条形码对应零件信息) { Socket_FittingAccessoryInfo fittingAccessoryInfo = commArgs.Params[i].DataValue as Socket_FittingAccessoryInfo; RequestFittingInfo fittingProcessor = new RequestFittingInfo(); commArgs.Params[i].DataValue = fittingProcessor.ReceiveReadBarCodeInfo(fittingAccessoryInfo); } else if (commArgs.Params[i].Code == TagCode.获取选配值) { string info = (string)commArgs.Params[i].DataValue; RequestFittingInfo fittingProcessor = new RequestFittingInfo(); commArgs.Params[i].DataValue = fittingProcessor.ReceiveReadChoseMatchInfo(info); //Socket_FittingAccessoryInfo fittingAccessoryInfo = commArgs.Params[i].DataValue as Socket_FittingAccessoryInfo; //RequestFittingInfo fittingProcessor = new RequestFittingInfo(); //fittingAccessoryInfo = fittingProcessor.ReceiveReadBarCodeInfo(fittingAccessoryInfo); //commArgs.Params[i].DataValue = fittingProcessor.ReceiveReadChoseMatchInfo(fittingAccessoryInfo); } } else if (commArgs.Params[i].CMD == CommCMD.存储工位信息) { if (commArgs.Params[i].Code == TagCode.装配信息) { Socket_FittingAccessoryInfoSum fittingAccessoryInfoSum = commArgs.Params[i].DataValue as Socket_FittingAccessoryInfoSum; fittingAccessoryInfoSum.Edition = GetProductType(fittingAccessoryInfoSum.ProductTypeName); RequestFittingInfo fittingProcessor = new RequestFittingInfo(); commArgs.Params[i].DataValue = fittingProcessor.ReceiveSaveTempFittingInfo(fittingAccessoryInfoSum); if (fittingAccessoryInfoSum.ProductTypeName.Contains("力帆") && fittingAccessoryInfoSum.WorkBench == "DB") { commArgs.Params[i].DataValue = fittingProcessor.ReceiveSaveFittingInfo(fittingAccessoryInfoSum.ProductCode); } else if (fittingAccessoryInfoSum.ProductTypeName.Contains("众泰") && fittingAccessoryInfoSum.WorkBench == "DB") { commArgs.Params[i].DataValue = fittingProcessor.ReceiveSaveFittingInfo(fittingAccessoryInfoSum.ProductCode); } } } } } for (int i = 0; i < commArgs.Params.Count; i++) { commArgs.Params[i].CMD = CommCMD.应答; } string error; m_server.Send(commArgs, out error); }