/// <summary> /// 增加排队报文和插入排队的报文到数据库中 /// </summary> /// <param name="objTelegram"></param> /// <param name="struSendTelegram"></param> private void InsertWorkQueue(Int16[] objTelegram, struTelegram struSendTelegram) { // 插入数据库对应工作队列数据 string strWaitTelegram = m_telegramParser.Int16sToString(objTelegram, 0, objTelegram.Length - 1, 4); CWorkQueueDto workQueueDto = CCommonMethods.myMethods.GetSendTelegramInfo(struSendTelegram.nEMSSendFlag, struSendTelegram.nEquipID, strWaitTelegram); if (workQueueDto == null) { workQueueDto = new CWorkQueueDto { devicecode = struSendTelegram.nEquipID, warehouse = struSendTelegram.nEMSSendFlag, iccode = struSendTelegram.strICCardID, waitsendtelegram = strWaitTelegram, tasktype = struSendTelegram.nMasterType }; CDBEditor dbEditor = new CDBEditor(); if (null != dbEditor) { dbEditor.insertTableDto(workQueueDto); } } }
/// <summary> /// 删除报文 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnDelete_Click(object sender, EventArgs e) { if (!CStaticClass.CheckPushService()) {// 检查服务 return; } QueryServiceClient proxy = new QueryServiceClient(); try { if (null == this.DgvQueue.CurrentRow) { MessageBox.Show("作业不能为空", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } // 删除数据库作业 CWorkQueueDto workQueue = (CWorkQueueDto)this.DgvQueue.CurrentRow.DataBoundItem; CarLocationPanelLib.QueryService.EnmFaultType type = proxy.DeleteWorkQueueObject(workQueue.id); switch (type) { case CarLocationPanelLib.QueryService.EnmFaultType.Success: { GetFindQueueLst(proxy); MessageBox.Show("删除作业成功", "成功", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); break; } case CarLocationPanelLib.QueryService.EnmFaultType.NoICCardInfo: { MessageBox.Show("没有刷卡信息", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); break; } case CarLocationPanelLib.QueryService.EnmFaultType.FailToDelete: { MessageBox.Show("删除数据库失败", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); break; } case CarLocationPanelLib.QueryService.EnmFaultType.Exception: { MessageBox.Show(CStaticClass.GetExceptionInfo(null), "连接异常", MessageBoxButtons.OK, MessageBoxIcon.Error); break; } default: { MessageBox.Show("删除作业失败", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); break; } } } catch (TimeoutException) { MessageBox.Show("The service operation timed out. ", "超时", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (FaultException exception) { MessageBox.Show(CStaticClass.GetExceptionInfo(exception), "SOAP错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (CommunicationException exception) { MessageBox.Show("There was a communication problem. " + CStaticClass.GetExceptionInfo(exception), "通信错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception exception) { MessageBox.Show(CStaticClass.GetExceptionInfo(exception), "应用程序异常", MessageBoxButtons.OK, MessageBoxIcon.Error); } proxy.Close(); }
/// <summary> /// 发送报文并判断是否重发,如果重发次数不超过m_retryCount /// </summary> /// <param name="data"></param> /// <param name="wareHouse"></param> private bool DealSendTelegram(object data, int wareHouse) { if (null == m_PLCServer) { CWException.WriteLog("报文发送时,m_PLCServer为空", 4); return(false); } if (data.GetType() == typeof(short[])) { short[] mydt = (short[])data; if (mydt[6] == 0 || mydt[2] == 0 || mydt[3] == 0) { CWException.WriteLog(data, 1); return(true); } } int count = m_retryCount;//重发次数 bool bSendResult = false; bool bACKResult = false; while (0 < count--) { bSendResult = SendData(data, wareHouse); if (bSendResult) { m_PLCServer.AckAllowClear = false; int nMillisecond = 0; while (nMillisecond < 3000) { short recvBuffer = 0; bool isOK = m_PLCServer.Read(ref recvBuffer, 1); if (isOK) { if (recvBuffer == 9999) { Int16[] ackTelegram = null; m_PLCServer.Read(ref ackTelegram, 0);// 读取PLC回应ACK报文 bACKResult = CBaseMethods.MyBase.IsPLCAck((Int16[])data, ackTelegram); if (bACKResult) { //更新PLC发送缓冲区标志位为0 if (!m_PLCServer.Write(0, 1)) { ThreadPool.QueueUserWorkItem(new WaitCallback(ReWritePLCFlag)); } //接收报文ack成功 CCommonMethods.myMethods.InsertTelegramLog(ackTelegram, 0); break; } } } Thread.Sleep(50);//4000 nMillisecond += 50; } if (bACKResult) { break; } //重发时更改MessageID if (data.GetType() == typeof(short[])) { short[] mydt = (short[])data; mydt[48] = (short)new CRequestAction().MessageID; } } } m_PLCServer.AckAllowClear = true; if (!bSendResult) { CWException.WriteLog("以下报文发送不成功,SendResult:" + bSendResult.ToString() + " bAckResult:" + bACKResult.ToString(), 4); CWException.WriteLog(data, 1); short[] msg = (short[])data; string strWaitTelegram = m_telegramParser.Int16sToString(msg, 0, msg.Length - 1, 4); //加入队列,将其作业类型改为RetrySend CWorkQueueDto workQueueDto = new CWorkQueueDto { devicecode = msg[6], warehouse = wareHouse, iccode = msg[11].ToString().PadLeft(4, '0'), waitsendtelegram = strWaitTelegram, tasktype = (int)EnmTaskType.RetrySend }; CWorkQueueDto exitQueue = CCommonMethods.myMethods.GetSendTelegramInfo(wareHouse, (int)workQueueDto.devicecode, strWaitTelegram); if (exitQueue == null) { new CDBEditor().insertTableDto(workQueueDto); } } return(bSendResult); }