private Dictionary <int, CSound> m_dicSound;//语音播放对象 public CRequestAction() { m_nSendIDMax = CConfigManagement.myPara.MaxTelegramID;//读取配置文件 lstAction = new List <CAbstractAction>(); m_PLCServer = null; m_telegram = null; m_lstTelegram = new List <struTelegram>(); // 发送报文列表 m_soundName = string.Empty; m_lstTableDto = new List <struTableDto>(); // SQL操作表格数据 m_ledContent = string.Empty; // LED显示文本内容 m_struTelegram = new struTelegram(); m_carLocationTBL = new CCarLocationDto(); m_deviceStatusTBL = new CDeviceStatusDto(); m_struHallEquip = new struHallEquips(); m_soundUpdateContent = string.Empty; m_dicSound = new Dictionary <int, CSound>(); }
public void Init() { try { // System.Timers.Timer tmpTimer = new System.Timers.Timer(5000); //Timer的时间间隔为1000毫秒 = 1s // tmpTimer.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件 // tmpTimer.AutoReset = true;//设置是执行一次(false)还是一直执行(true) // tmpTimer.Elapsed += new System.Timers.ElapsedEventHandler(tmpTimer_Elapsed); // m_PLCServer = CCommonMethods.myMethods.GetCommModule(m_nWareHouse); if (null == m_PLCServer) { CLOGException.Trace("WorkFlowLib.CWorkFlow.InitialTelegramMgmt", "获取通信模式块失败"); return; //获取通信模式块失败,请查看配置文件是否正确 } // add by wanxiaona20150728 if (!CConfigManagement.myPara.HashAllPLCItemAdress.ContainsKey(m_nWareHouse)) { CLOGException.Trace("WorkFlowLib.CWorkFlow.InitialTelegramMgmt", "无效库区号"); return; } // add by wanxiaona20150728 // lock (m_commModule) //{ m_PLCServer.Initialize((List <string>)CConfigManagement.myPara.HashAllPLCItemAdress[m_nWareHouse], false); bool bIsSended = false; bool bIsACKReceived = false; while (!bIsSended || !bIsACKReceived) { bIsSended = SendData(); Int16[] data = (Int16[])m_objData; if (bIsSended) { int nMillisecond = 0; while (nMillisecond < 10000) { 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报文 bIsACKReceived = CBaseMethods.MyBase.IsPLCAck((Int16[])data, ackTelegram); if (bIsACKReceived) { //更新PLC发送缓冲区标志位为0 if (m_PLCServer.Write(0, 1)) { ThreadPool.QueueUserWorkItem(new WaitCallback(ReWritePLCFlag)); } //接收报文ack成功 CCommonMethods.myMethods.InsertTelegramLog(ackTelegram, 0); break; } else { StringBuilder sb = new StringBuilder(); Int16[] dataTmp = (Int16[])ackTelegram; sb.Append("EMS:" + dataTmp[0] + "|"); sb.Append("PLC:" + dataTmp[1] + "|"); sb.Append("TeleType:" + dataTmp[2] + "|"); sb.Append("EMSSubType:" + dataTmp[3] + "|"); sb.Append("PLCSubType:" + dataTmp[4] + "|"); sb.Append("DeviceID:" + dataTmp[6] + "|"); sb.Append("ID:" + dataTmp[48]); string telegram = sb.ToString(); CLOGException.Trace(m_nWareHouse, "WorkFlowLib.TelegramHandler", "Send telegram failed:" + telegram); } } } Thread.Sleep(1000);//4000 nMillisecond += 1000; } if (bIsACKReceived) { break; } } } CLOGException.Trace(m_nWareHouse, "WorkFlowLib.TelegramHandler", "***************************WorkFlowLib.CTelegramHandler.Init*****************************"); m_PLCServer.Dispose(); } catch (Exception ex) { CLOGException.Trace("AbstractActionLib.CTelegramHandler.Init 异常", CBaseMethods.MyBase.GetExceptionInfo(ex)); } }
/// <summary> /// 构造函数 /// </summary> public void Init(Dictionary <int, CLedShower> dicLedDevice) { try { //CLOGException.Trace("——————WorkFlowLib.CWorkFlow.Init "); if (!CConfigManagement.myPara.DicAllDeviceID.ContainsKey(m_nPLCID)) { CLOGException.Trace("WorkFlowLib.CWorkFlow.Init", "HashAllDeviceID-无效PLCID"); return;//无效PLCID } m_telegramParser = new CTelegramParse(); m_struTelegram = new struTelegram(); m_soundAction = new CSoundAction(); m_modifyDBAction = new CModifyDBAction(); m_sendTelegramAction = new CSendTelegramAction(); m_taskTrigger = new CTaskTriggerMgmt(); m_taskTrigger.SetTaskTrigger(m_nPLCID); m_dictHallID = new Dictionary <int, struHallEquips>(); if (!CConfigManagement.myPara.DicHallIDDictionary.ContainsKey(m_nPLCID)) { CLOGException.Trace("WorkFlowLib.CWorkFlow.Init", "HashHallIDDictionary-无效PLCID"); return; //无效PLCID } m_dictHallID = (Dictionary <int, struHallEquips>)CConfigManagement.myPara.DicHallIDDictionary[m_nPLCID]; //.GetHallIDDictionary(m_nPLCID); if (!CConfigManagement.myPara.HashAllPLCItemAdress.ContainsKey(m_nPLCID)) { CLOGException.Trace("WorkFlowLib", "HashAllPLCItemAdress-无效PLC ID"); return;//无效PLCID } m_commModule = CCommonMethods.myMethods.GetCommModule(m_nPLCID); if (null == m_commModule) { CLOGException.Trace(m_nPLCID, "WorkFlowLib", "Get communication module failed"); return; //获取通信模式块失败,请查看配置文件是否正确 } m_commModule.Initialize((List <string>)CConfigManagement.myPara.HashAllPLCItemAdress[m_nPLCID]); m_commModule.Write(0, 1);//更新PLC发送缓冲区标志位为0 m_dicSound = new Dictionary <int, CSound>(); foreach (int hallID in (List <int>)CConfigManagement.myPara.HashHallDeviceID[m_nPLCID]) { //获取语音模块类型的对应类名及相应参数 string strClassName = string.Format("CSound{0}", CConfigManagement.myPara.AudioAPI); CSound sound = new CSound(); if (string.IsNullOrWhiteSpace(strClassName)) { CLOGException.Trace(m_nPLCID, "IEG_AP_Proc", "Get AudioAPI name failed"); return; //获取语音模式块失败,使用默认 } // 配置 SpeechSynthesizer 对象以发送输出到默认音频设备。 sound = (CSound)Assembly.Load("SoundManagementLib").CreateInstance("SoundManagementLib." + strClassName, false, BindingFlags.Default, null, null, null, null); if (null == sound) { CLOGException.Trace(m_nPLCID, "IEG_AP_Proc", "Failed to new sound object, strClassName= " + strClassName); return; } m_dicSound.Add(hallID, sound); } m_dicLEDDevice = dicLedDevice; } catch (Exception ex) {//打印日志 CLOGException.Trace(m_nPLCID, "WorkFlowLib.CWorkFlow.Init 异常", CBaseMethods.MyBase.GetExceptionInfo(ex)); } }
/// <summary> /// 报文下发 /// </summary> /// <param name="objRequestParam"></param> public void TelegramSender(object objRequestParam) { try { CRequestAction RequestParam = (CRequestAction)objRequestParam; m_PLCServer = RequestParam.PLCServer; // 发送报文 foreach (struTelegram struSendTelegram in RequestParam.lstTelegram) { CWException.WriteLog(string.Format("Telegram ({0},{1}) will send ,devicecode:{2},iccode:{3}", struSendTelegram.nTelegramType, struSendTelegram.nSubTypeEMS, struSendTelegram.nEquipID, struSendTelegram.strICCardID), 4); Int16[] objTelegram; m_telegramParser.PackTelegram(out objTelegram, struSendTelegram); int warehouse = struSendTelegram.nEMSSendFlag; int equipID = struSendTelegram.nEquipID; //存在该位(nDeviceByteBit),表示在下发时要判断设备是否允许下发报文否,如果不存在该位,则可以直接下发当前报文 if (0 != struSendTelegram.nDeviceByteBit) { #region CDeviceStatusDto smg = CCommonMethods.myMethods.GetDeviceStatus(warehouse, equipID); #region if (smg == null) { //如果不存在设备号,则表示异常,先加入队列 CWException.WriteLog(string.Format("报文({0},{1})没有设备号,其卡号:{2}", struSendTelegram.nTelegramType, struSendTelegram.nSubTypeEMS, struSendTelegram.strICCardID), 4); //加入队列 InsertWorkQueue(objTelegram, struSendTelegram); continue; } #endregion if (smg.devicetype == (int)EnmSMGType.Hall) { #region 允许下发或加入队列 if (smg.devicemode == (int)EnmModel.Automatic && smg.isable == 1 && smg.isavailable == 1 && smg.tasktype == (int)EnmTaskType.Init) { smg.tasktype = struSendTelegram.nMasterType; smg.iccode = struSendTelegram.strICCardID; smg.prevnode = null; smg.currentnode = null; smg.scrloc = struSendTelegram.strSrcLocAddr; smg.desccloc = struSendTelegram.strDestLocAddr; new CDBEditor().updateTableDto(smg); //下发报文 DealSendTelegram(objTelegram, warehouse); } else { //加入队列 InsertWorkQueue(objTelegram, struSendTelegram); } #endregion } else if (smg.devicetype == (int)EnmSMGType.ETV) { #region 将(14,1)加入队列 if (struSendTelegram.nTelegramType == 14 && struSendTelegram.nSubTypeEMS == 1) { CWException.WriteLog(string.Format("warehouse:{0}, devicecode:{1} has telegram (14,1) add workqueue! ", smg.warehouse, smg.devicecode), 4); InsertWorkQueue(objTelegram, struSendTelegram); continue; } #endregion #region 判断避让, 执行(13,1)(11,1) if (smg.devicemode == (int)EnmModel.Automatic && smg.isable == 1 && smg.isavailable == 1 && smg.tasktype == (int)EnmTaskType.Init) { string toAddrss = ""; if (struSendTelegram.nTelegramType == 11 && struSendTelegram.nSubTypeEMS == 1) { toAddrss = struSendTelegram.strDestLocAddr; } else { toAddrss = struSendTelegram.strSrcLocAddr; } if (this.DealAvoid(smg, toAddrss, struSendTelegram.strICCardID)) { //允许下发,绑定设备,下发报文 smg.tasktype = struSendTelegram.nMasterType; smg.iccode = struSendTelegram.strICCardID; smg.prevnode = null; smg.currentnode = null; if (struSendTelegram.nMasterType != (int)EnmTaskType.MoveEquipTask) { smg.currentnode = (int)EnmFlowNodeDescp.Load; } smg.scrloc = struSendTelegram.strSrcLocAddr; smg.desccloc = struSendTelegram.strDestLocAddr; new CDBEditor().updateTableDto(smg); //下发报文 DealSendTelegram(objTelegram, warehouse); continue; } } //加入队列 InsertWorkQueue(objTelegram, struSendTelegram); #endregion } continue; #endregion } // 发送报文 DealSendTelegram(objTelegram, warehouse); } } catch (Exception ex) { CLOGException.Trace("AbstractActionLib.CTelegramSender.TelegramSender 异常", CBaseMethods.MyBase.GetExceptionInfo(ex)); } }
/// <summary> /// 构造函数 /// </summary> public CTelegramSender(CCommModule OPCServer) { m_PLCServer = OPCServer; }