private void trigger_SendPosChanged(IPC_SIMPLE_ANSWER isa) { if (global_static_var.is_init_ok) { if (call.OnSendFilePosChanged != null) { SendFileEventArgs arg = new SendFileEventArgs(); arg.filename = isa.send_fileName; arg.send_pos = isa.pos; arg.product_id = isa.product_id; arg.is_send_failed_flag = isa.is_cmd_failed_flag; arg.is_send_over = isa.is_cmd_over_flag; if (isa.is_cmd_failed_flag) { arg.msg = isa.er_message; } else { arg.msg = isa.repair_message; } call.m_thisPtr.BeginInvoke(new MethodInvoker(delegate { if (call.OnSendFilePosChanged != null) { call.OnSendFilePosChanged(this, arg); } })); } } }
private void OnDeviceCmdReturn(object sender, DeviceCmdEventArgs arg) { this.isReceiveEvent = true; IPC_SIMPLE_ANSWER isa = arg.isa; this.isaQueue.Enqueue(isa); this.isReceiveEvent = false; }
private void trigger_HeartReturnResult(IPC_SIMPLE_ANSWER isa) { if (global_static_var.is_init_ok) { if (call.OnAutoFoundDevice != null) { AutoFoundDeviceEventArgs arg = new AutoFoundDeviceEventArgs(); if (!isa.is_cmd_failed_flag) { DEVICE_INFO di = isa.return_object as DEVICE_INFO; call.m_thisPtr.Invoke(new MethodInvoker(delegate { if (call.m_devList.ContainsKey(di.product_id)) { call.m_devList.Remove(di.product_id); } call.m_devList.Add(di.product_id, di); })); arg.cmd_id = (int)isa.cmd_id; arg.net_id = di.net_id; arg.product_id = di.product_id; arg.state = di.state; arg.signal_strength = di.signal_strength; arg.program_number = di.program_number; if (isa.cmd_id == 4341) { arg.repair_message = "心跳引发的设备状态更新!"; } else if (isa.cmd_id == 4342) { arg.repair_message = "心跳引发的新设备发现!"; } else if (isa.cmd_id == 4343) { arg.repair_message = "长时间没有心跳,认为此设备已离线。"; } } else if (isa.cmd_id == 4342) { arg.repair_message = isa.er_message; arg.net_id = ""; arg.product_id = ""; arg.state = DEVICE_STATE.ST_NONE; arg.signal_strength = 0; arg.program_number = 0; arg.cmd_id = (int)isa.cmd_id; } call.m_thisPtr.BeginInvoke(new MethodInvoker(delegate { if (call.OnAutoFoundDevice != null) { call.OnAutoFoundDevice(this, arg); } })); } } }
private void OnDeviceCmdReturn(object sender, DeviceCmdEventArgs arg) { IPC_SIMPLE_ANSWER isa = arg.isa; if (isa == null) { return; } if ((byte)isa.cmd_id == 85 && !isa.is_cmd_failed_flag && isa.is_cmd_over_flag && isa.return_object != null) { this.label3.Text = isa.return_object.ToString(); this.comboBox1.Text = this.label3.Text; } }
public void OnIPCRecv(object obj) { if (obj.GetType() == typeof(IPC_NOTIFY_CMD)) { Console.WriteLine("I 收到server发来的IPC通知命令:" + (IPC_NOTIFY_CMD)obj); if (IPC_NOTIFY_CMD.AW_ENABLE_COMM == (IPC_NOTIFY_CMD)obj) { if (!call.is_IPC_ready_flag) { call.m_thisPtr.BeginInvoke(new MethodInvoker(delegate { this.IPC_send_cfg_prar(); call.is_IPC_ready_flag = true; this.trigger_IPCReadyOKEvent(); })); } } else if (IPC_NOTIFY_CMD.AW_SERVER_BUSY == (IPC_NOTIFY_CMD)obj) { this.trigger_DeviceCmdReturnResult(new IPC_SIMPLE_ANSWER { cmd_id = call.m_last_run_cmd_id, is_cmd_failed_flag = true, er_code = 65281, er_message = "后台服务器忙,因为上一条指令是排它执行的指令,所以要收到它的OVER事件后,才能继续发送命令。" }); } } else { IPC_SIMPLE_ANSWER iPC_SIMPLE_ANSWER = obj as IPC_SIMPLE_ANSWER; if (iPC_SIMPLE_ANSWER.cmd_id == 4342 || iPC_SIMPLE_ANSWER.cmd_id == 4341 || iPC_SIMPLE_ANSWER.cmd_id == 4343) { Console.WriteLine("收到心跳通信"); this.trigger_HeartReturnResult(iPC_SIMPLE_ANSWER); } else if (iPC_SIMPLE_ANSWER.cmd_id == 6) { this.trigger_SendPosChanged(iPC_SIMPLE_ANSWER); } else { this.trigger_DeviceCmdReturnResult(iPC_SIMPLE_ANSWER); } } }
private void trigger_DeviceCmdReturnResult(IPC_SIMPLE_ANSWER isa) { if (global_static_var.is_init_ok) { if (call.OnDeviceCmdReturnResult != null) { this.tb_cl_cmd(ref isa); DeviceCmdEventArgs arg = new DeviceCmdEventArgs(); arg.isa = isa; call.m_thisPtr.BeginInvoke(new MethodInvoker(delegate { if (call.OnDeviceCmdReturnResult != null) { call.OnDeviceCmdReturnResult(this, arg); } })); } } }
private void tb_cl_cmd(ref IPC_SIMPLE_ANSWER aisa) { IPC_SIMPLE_ANSWER isa = aisa; if (isa.cmd_id == 45) { if (!isa.is_cmd_over_flag && !isa.is_cmd_failed_flag) { call.m_thisPtr.Invoke(new MethodInvoker(delegate { DEVICE_INFO dEVICE_INFO = isa.return_object as DEVICE_INFO; if (call.m_devList.ContainsKey(isa.product_id)) { call.m_devList.Remove(isa.product_id); } call.m_devList.Add(dEVICE_INFO.product_id, dEVICE_INFO); })); } } else if (isa.cmd_id == 4338) { if (isa.is_cmd_over_flag && !isa.is_cmd_failed_flag) { call.m_thisPtr.Invoke(new MethodInvoker(delegate { Dictionary <string, DEVICE_INFO> dictionary = isa.return_object as Dictionary <string, DEVICE_INFO>; foreach (DEVICE_INFO current in call.m_devList.Values) { if (current.cur_use_net_mode == 1 || current.cur_use_net_mode == 8) { DEVICE_INFO dEVICE_INFO; if (dictionary.TryGetValue(current.product_id, out dEVICE_INFO)) { current.state = dEVICE_INFO.state; } } } })); } else if (!isa.is_cmd_over_flag && !isa.is_cmd_failed_flag) { call.m_thisPtr.Invoke(new MethodInvoker(delegate { DEVICE_INFO dEVICE_INFO; if (isa.product_id != null && call.m_devList.TryGetValue(isa.product_id, out dEVICE_INFO)) { DEVICE_INFO expr_32 = dEVICE_INFO; expr_32.state |= DEVICE_STATE.ST_ONLINE; } })); } } else if (isa.cmd_id == 4339) { if (isa.is_cmd_over_flag && !isa.is_cmd_failed_flag) { call.m_thisPtr.Invoke(new MethodInvoker(delegate { DEVICE_INFO dEVICE_INFO = isa.return_object as DEVICE_INFO; if (call.m_devList.ContainsKey(isa.product_id)) { call.m_devList.Remove(isa.product_id); } call.m_devList.Add(dEVICE_INFO.product_id, dEVICE_INFO); })); } } aisa = isa; }
private void ReceiveEvent() { while (this.isThreadReceiveEvent) { if (this.isaQueue != null && this.isaQueue.Count != 0) { IPC_SIMPLE_ANSWER isa = this.isaQueue.Dequeue(); if (isa != null) { if ((byte)isa.cmd_id == 17) { if (!isa.is_cmd_failed_flag) { if (isa.is_cmd_over_flag) { base.Invoke(new MethodInvoker(delegate { this.pgbStatus.Value = 100; })); if (!this.isWiFiProductionTest) { Thread.Sleep(600); } if (isa.return_object != null && isa.return_object.GetType() == typeof(LedPanel)) { LedPanel ledPanel = isa.return_object as LedPanel; if (ledPanel.CardType == formMain.ledsys.SelectedPanel.CardType) { this.StartSendData(); } else if (!this.isCmdOver) { this.isCmdOver = true; this.isThreadReceiveEvent = false; base.Invoke(new MethodInvoker(delegate { this.tmrDaemon.Stop(); MessageBox.Show(this, formMain.ML.GetStr("Prompt_ProductModelError")); this.needtoClose = true; base.Close(); })); } } } else { base.Invoke(new MethodInvoker(delegate { this.pgbStatus.Value = 50; })); if (!this.isWiFiProductionTest) { Thread.Sleep(300); } } } else if (isa.is_cmd_over_flag) { if (isa.er_code > 20) { if (this.ResendCount + 1 < this.MaxResendCount) { this.dtStart = DateTime.Now; this.ResendCount++; this.CheckCardType(); } else if (!this.isCmdOver) { this.isCmdOver = true; this.isThreadReceiveEvent = false; base.Invoke(new MethodInvoker(delegate { this.pgbStatus.Value = 100; })); if (!this.isWiFiProductionTest) { Thread.Sleep(600); } base.Invoke(new MethodInvoker(delegate { this.tmrDaemon.Stop(); MessageBox.Show(this, formMain.ML.GetStr("Prompt_CommFaileder")); this.needtoClose = true; base.Close(); })); } } else { this.isThreadReceiveEvent = false; base.Invoke(new MethodInvoker(delegate { this.pgbStatus.Value = 100; })); if (!this.isWiFiProductionTest) { Thread.Sleep(600); } base.Invoke(new MethodInvoker(delegate { this.tmrDaemon.Stop(); MessageBox.Show(this, formMain.GetSendingCSWDescription("Sending_CSW", isa.er_code)); this.needtoClose = true; this.Close(); })); } } else { base.Invoke(new MethodInvoker(delegate { this.pgbStatus.Value = 50; })); if (!this.isWiFiProductionTest) { Thread.Sleep(300); } } } if ((byte)isa.cmd_id == 1 || (byte)isa.cmd_id == 113 || (byte)isa.cmd_id == 8) { base.Invoke(new MethodInvoker(delegate { this.dtStart = DateTime.Now; this.pgbStatus.Value = isa.pos; this.lblCurrentFrame.Text = (this.totalFrame * isa.pos / 100).ToString(); this.lastFrame = this.lblCurrentFrame.Text; this.lblCurrentFrame.Refresh(); })); if (!this.isWiFiProductionTest) { Thread.Sleep(40); } if (!isa.is_cmd_failed_flag) { if (isa.is_cmd_over_flag && isa.pos == 100 && !this.isCmdOver) { this.isCmdOver = true; formSendData.SendALl = true; formSendData.Finished = true; if (this.ShowOK) { this.isThreadReceiveEvent = false; base.Invoke(new MethodInvoker(delegate { this.tmrDaemon.Stop(); if (this.isUpdataCode) { MessageBox.Show(this, formMain.ML.GetStr("formSendData_mssage_UpdateAndWaitOneMinute")); } else if (this.isDownloadStringLibrary) { MessageBox.Show(this, formMain.ML.GetStr("Message_Download_String_Library_Success")); } else { MessageBox.Show(this, formMain.ML.GetStr("formSendData_mssage_Display_Successed")); } this.needtoClose = true; base.Close(); })); } else { Thread.Sleep(600); this.isThreadReceiveEvent = false; base.Invoke(new MethodInvoker(delegate { this.tmrDaemon.Stop(); this.Refresh(); if (!this.isWiFiProductionTest) { Thread.Sleep(1200); } this.needtoClose = true; base.Close(); })); } } } else if (isa.is_cmd_over_flag) { if (isa.er_code > 20) { if (!this.isCmdOver) { this.isCmdOver = true; this.isThreadReceiveEvent = false; base.Invoke(new MethodInvoker(delegate { this.tmrDaemon.Stop(); MessageBox.Show(this, formMain.ML.GetStr("formSendData_mssage_Display_Failed")); this.needtoClose = true; base.Close(); })); } } else { this.isThreadReceiveEvent = false; base.Invoke(new MethodInvoker(delegate { this.tmrDaemon.Stop(); MessageBox.Show(this, formMain.GetSendingCSWDescription("Sending_CSW", isa.er_code)); this.needtoClose = true; this.Close(); })); } } } if (this.isaQueue != null && this.isaQueue.Count == 0) { Thread.Sleep(20); } } } } if (this.isaQueue != null) { this.isaQueue.Clear(); this.isaQueue = null; } }
private void ReceiveEvent() { while (this.isThreadReceiveEvent) { if (this.isaQueue == null || this.isaQueue.Count == 0) { Thread.Sleep(5); } else if (this.isReceiveEvent) { Thread.Sleep(5); } else { IPC_SIMPLE_ANSWER isa = this.isaQueue.Dequeue(); if (isa == null) { Thread.Sleep(5); } else { string product_id = isa.product_id; int rowIndex = -1; for (int i = 0; i < formGroupSendingSingle.screenSendGroup.Count; i++) { if (formGroupSendingSingle.screenSendGroup[i].Panel_NO.ProductID == product_id) { rowIndex = i; break; } } if (rowIndex < 0) { return; } formGroupSendingSingle.screenSendGroup[rowIndex].LastRecvTime = DateTime.Now; if ((byte)isa.cmd_id == (byte)this.command) { if (!isa.is_cmd_failed_flag) { if (isa.is_cmd_over_flag) { string msg = formMain.ML.GetStr("formSendData_FormText") + formMain.ML.GetStr("Display_Successed"); this.StateColor = 1; formGroupSendingSingle.screenSendGroup[rowIndex].Send_State = 3; formGroupSendingSingle.screenSendGroup[rowIndex].ResendCount = 0; formGroupSendingSingle.screenSendGroup[rowIndex].State_Message = msg; formGroupSendingSingle.screenSendGroup[rowIndex].SendCompleted = true; if (formGroupSendingSingle.screenSendGroup[rowIndex].Send_Data != null) { formGroupSendingSingle.screenSendGroup[rowIndex].Send_Data.Dispose(); formGroupSendingSingle.screenSendGroup[rowIndex].Send_Data = null; } base.Invoke(new MethodInvoker(delegate { this.dgvSendState.Rows[rowIndex].Cells[4].Value = msg; this.dgvSendState.Rows[rowIndex].Cells[4].Style.ForeColor = this.StateOfColor(this.StateColor); this.dgvSendState.Rows[rowIndex].Cells[5].Value = 100; })); Thread.Sleep(10); } } else if (isa.is_cmd_over_flag) { if (isa.er_code > 20) { if (formGroupSendingSingle.screenSendGroup[rowIndex].ResendCount + 1 < this.MaxResendCount) { formGroupSendingSingle.screenSendGroup[rowIndex].ResendCount++; ParameterizedThreadStart start = new ParameterizedThreadStart(this.SingleSend); Thread thread = new Thread(start); object parameter = rowIndex; thread.Start(parameter); this.thrCount++; Thread.Sleep(50); } else { this.failureCount++; formGroupSendingSingle.screenSendGroup[rowIndex].Send_State = 3; formGroupSendingSingle.screenSendGroup[rowIndex].SendCompleted = true; base.Invoke(new MethodInvoker(delegate { this.dgvSendState.Rows[rowIndex].Cells[4].Value = formMain.ML.GetStr("Prompt_CommFaileder"); this.StateColor = 2; this.dgvSendState.Rows[rowIndex].Cells[4].Style.ForeColor = this.StateOfColor(this.StateColor); })); Thread.Sleep(10); } } else { this.failureCount++; formGroupSendingSingle.screenSendGroup[rowIndex].Send_State = 3; formGroupSendingSingle.screenSendGroup[rowIndex].SendCompleted = true; base.Invoke(new MethodInvoker(delegate { this.dgvSendState.Rows[rowIndex].Cells[4].Value = formMain.GetSendingCSWDescription("Sending_CSW", isa.er_code); this.StateColor = 2; this.dgvSendState.Rows[rowIndex].Cells[4].Style.ForeColor = this.StateOfColor(this.StateColor); })); Thread.Sleep(10); } } } Thread.Sleep(5); } } } if (this.isaQueue != null) { this.isaQueue.Clear(); this.isaQueue = null; } }
private void ReceiveEvent() { while (this.isThreadReceiveEvent) { if (this.isaQueue == null || this.isaQueue.Count == 0) { Thread.Sleep(5); } else if (this.isReceiveEvent) { Thread.Sleep(5); } else { IPC_SIMPLE_ANSWER isa = this.isaQueue.Dequeue(); if (isa == null) { Thread.Sleep(5); } else { if ((byte)isa.cmd_id == (byte)this.command) { if (!isa.is_cmd_failed_flag) { base.Invoke(new MethodInvoker(delegate { this.Text = this.operation + " " + isa.repair_message; this.Refresh(); })); if (!this.isWiFiProductionTest) { Thread.Sleep(20); } if (isa.is_cmd_over_flag) { if (!this.isCmdOver) { this.isCmdOver = true; formSendSingle.LastSendResult = true; formSendSingle.SendFinish = true; formSendSingle.LastSendResultObject = isa.return_object; base.Invoke(new MethodInvoker(delegate { this.pgbStatus.Value = 100; this.pgbStatus.Refresh(); })); Thread.Sleep(600); this.isThreadReceiveEvent = false; if (this.ShowOK) { base.Invoke(new MethodInvoker(delegate { this.tmrDaemon.Stop(); MessageBox.Show(this, this.operation + formMain.ML.GetStr("Display_Successed")); this.needtoClose = true; base.Close(); })); } else { base.Invoke(new MethodInvoker(delegate { this.tmrDaemon.Stop(); if (!this.isWiFiProductionTest) { Thread.Sleep(1200); } this.needtoClose = true; base.Close(); })); } } } else { this.executeProgress = 50; if (this.executeProgress > this.pgbStatus.Value) { base.Invoke(new MethodInvoker(delegate { this.pgbStatus.Value = this.executeProgress; this.pgbStatus.Refresh(); })); if (!this.isWiFiProductionTest) { Thread.Sleep(600); } } } } else { formSendSingle.LastSendResult = false; base.Invoke(new MethodInvoker(delegate { this.Text = this.operation + " " + isa.repair_message; this.Refresh(); })); if (!this.isWiFiProductionTest) { Thread.Sleep(20); } if (isa.is_cmd_over_flag) { if (isa.er_code > 20) { if (this.ResendCount + 1 < this.MaxResendCount) { this.dtStart = DateTime.Now; this.ResendCount++; this.StartSend(); } else if (!this.isCmdOver) { this.isCmdOver = true; this.isThreadReceiveEvent = false; base.Invoke(new MethodInvoker(delegate { this.pgbStatus.Value = 100; this.tmrDaemon.Stop(); MessageBox.Show(this, formMain.ML.GetStr("Display_CommunicationFailed")); this.needtoClose = true; base.Close(); })); } } else { this.isThreadReceiveEvent = false; base.Invoke(new MethodInvoker(delegate { this.pgbStatus.Value = 100; this.tmrDaemon.Stop(); if ((byte)isa.cmd_id == 58 || (byte)isa.cmd_id == 60) { formSendSingle.LastSendResult = true; } else { MessageBox.Show(this, formMain.GetSendingCSWDescription("Sending_CSW", isa.er_code)); } this.needtoClose = true; this.Close(); })); } } else { this.executeProgress = 50; if (this.executeProgress > this.pgbStatus.Value) { base.Invoke(new MethodInvoker(delegate { this.pgbStatus.Value = this.executeProgress; this.pgbStatus.Refresh(); })); if (!this.isWiFiProductionTest) { Thread.Sleep(600); } } } } } if (!this.isWiFiProductionTest) { Thread.Sleep(100); } } } } if (this.isaQueue != null) { this.isaQueue.Clear(); this.isaQueue = null; } }