static void Main(string[] args) { Process[] localByNameKnl = Process.GetProcessesByName("AutoParkingSystem");//想要执行程序的进程名称。 //localByName得到的是进程中所有名称为"knl_proc.exe"的进程。 if (localByNameKnl.Length != 0) //如果得到的进程数是0, 那么说明程序未启动,需要启动程序 { foreach (Process process in localByNameKnl) { if (process.ProcessName == "AutoParkingSystem") { CLOGException.Trace("(Killer): Stop programme AutoParkingSystem..."); process.Kill(); } } } Process[] localByNameOM = Process.GetProcessesByName("MaintainProc");//想要执行程序的进程名称。 //localByName得到的是进程中所有名称为"knl_proc.exe"的进程。 if (localByNameOM.Length != 0) //如果得到的进程数是0, 那么说明程序未启动,需要启动程序 { foreach (Process process in localByNameOM) { if (process.ProcessName == "MaintainProc") { CLOGException.Trace("(Killer): Stop programme MaintainProc..."); process.Kill(); } } } }
/// <summary> /// 初始化 /// </summary> public override void Initialize(List <string> lstConnect) { // 打开TCP通信 Open(); // 添加items项 m_lstItemValueResult.Clear(); string[] fConnects = lstConnect.ToArray(); for (int i = 0; i < fConnects.Length; i++) { ItemValueResult itemValue = new ItemValueResult() { ItemName = fConnects[i] /* 该数据项在服务器中定义的名字*/ }; m_lstItemValueResult.Add(itemValue); itemValue = null; } fConnects = null; m_timer = new Timer() { Interval = m_updateRate, Enabled = true }; // 计时器启用 m_timer.Elapsed += new ElapsedEventHandler(Timer_Tick); CLOGException.Trace("CommunicationLib.CTcpClientAccessTimer.Initialize", string.Format("{0}successfully", IP)); }
/// <summary> /// 定时器 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void timer1_Tick(object sender, EventArgs e) { try { DateTime timeNow = DateTime.Now; if (0 <= timeNow.CompareTo(m_dtStart) && 0 >= timeNow.CompareTo(m_dtEnd)) { // 在空闲时段 if (!IsHasTask()) { // 无作业 VehicleRotation(); } } else { this.timer1.Stop(); this.BtnStart.Enabled = true; this.BtnStop.Enabled = false; Refresh(); } } catch (Exception ex) {//打印日志 CLOGException.Trace("RotationPoc.RotationManagemet.RunRotation 异常", CBaseMethods.MyBase.GetExceptionInfo(ex)); } }
static void Main() { try { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new CFormBilling()); } catch (TimeoutException exception) { CLOGException.Trace("GetExceptionInfo:" + exception.ToString()); MessageBox.Show("The service operation timed out. ", "超时", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } catch (FaultException exception) { CLOGException.Trace("GetExceptionInfo:" + exception.ToString()); MessageBox.Show("系统出现FaultException异常,强制关闭应用程序!", "SOAP错误", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } catch (CommunicationException exception) { CLOGException.Trace("GetExceptionInfo:" + exception.ToString()); MessageBox.Show("There was a communication problem. " + "请检查服务端是否打开,并打开服务!", "通信错误", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } catch (Exception exception) { CLOGException.Trace("GetExceptionInfo:" + exception.ToString()); MessageBox.Show("应用程序异常,强制关闭!", "应用程序异常", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } }
/// <summary> /// 初始化(是否添加定时器) /// </summary> public override void Initialize(List <string> lstConnect, bool isTimer) { // 打开OPC服务器 ReConnectServer(); if (IsConnected) {// 创建OPC订阅 CreatSubscription(lstConnect); } m_isAckHandler = isTimer; if (isTimer) { m_timer = new Timer(); m_timer.Interval = m_updateRate;//ms //m_timer.Start(); m_timer.Enabled = true; // 计时器启用 m_timer.Elapsed += new ElapsedEventHandler(Timer_Tick); // 定义多次循环 m_timer.AutoReset = true; m_timer.Start(); } CLOGException.Trace("CommunicationLib.COPCAccessTimer.Initialize ", " Initialize(2) successfully isTimer:" + isTimer); }
/// <summary> /// 读PLC字数据,返回一个byte[]型数据 /// </summary> /// <param name="bData">返回数据</param> /// <param name="itemNum">操作的Items,0-sendDB,1-sendflag,2-recvDB,3-recvflag,以此类推</param> /// <returns>true表示成功</returns> public override bool Read(ref byte[] bData, int itemNum) { try { if (m_subscription == null || m_subscription.Items == null || itemNum >= m_subscription.Items.Count()) { return(false); } Item[] r_items = new Item[1]; r_items[0] = m_subscription.Items[itemNum]; ItemValueResult[] values = m_subscription.Read(r_items); if (values[0].Quality == Quality.Good) { bData = (byte[])values[0].Value; return(true); } else { return(false); } } catch (Exception ex) { CLOGException.Trace("函数CommunicationLib.COPCAccessTimer.Read 异常", CBaseMethods.MyBase.GetExceptionInfo(ex)); return(false); } }
/// <summary> /// 设备故障文件和状态内容报文处理 /// </summary> /// <param name="nEquipID"></param> private void DealTelegramMessage(object objTelegram, int nEquipID) { try { if (objTelegram.GetType() != typeof(Byte[])) { return; } int nActionFlag = 0; CRequestAction requestAction = new CRequestAction(); if (m_dictHallID.ContainsKey(nEquipID)) { requestAction.struHallEquip = m_dictHallID[nEquipID]; } struTelegram struTelegramTemp = m_struTelegram; struTelegramTemp.nPLCSendFlag = m_nPLCID; struTelegramTemp.nEquipID = nEquipID; requestAction.structTelegram = struTelegramTemp; requestAction.PLCServer = m_commModule; requestAction.DicSound = m_dicSound; m_taskTrigger.DeviceTelegram(ref nActionFlag, ref requestAction, m_nPLCID, nEquipID, objTelegram); requestAction.RequestAction(nActionFlag, m_sendTelegramAction, m_modifyDBAction, m_soundAction); } catch (Exception ex) { CLOGException.Trace("WorkFlowLib.CWorkFlow.DealTelegramMessage1异常", CBaseMethods.MyBase.GetExceptionInfo(ex)); } }
public void DBEditor(CRequestAction RequestParam) { try { if (RequestParam.lstTableDto == null) { return; } // 判断是否插入或者更新修改,并返回操作枚举类型值 foreach (struTableDto obj in RequestParam.lstTableDto) { int accessType = obj.accessType; if (accessType == 1) {// 插入数据表操作 insertTableDto(obj.tableDto); } else if (accessType == 2) { // 更新修改数据表操作 updateTableDto(obj.tableDto); } else if (accessType == 3) { // 删除数据表操作 deleteTableDto(obj.tableDto); } } } catch (Exception ex) { CLOGException.Trace("AbstractActionLib.CDBEditor.DBEditor 异常", CBaseMethods.MyBase.GetExceptionInfo(ex)); } }
/// <summary> /// 读卡器处理 /// 读卡器有读取到刷卡时触发读取卡号 /// </summary> /// <param name="nHallID"></param> /// <param name="strPhysicalCardID"></param> private void ICCardMgmt(object sender, CSwiperEventArgs e) { try { int nHallID = e.HallID; string strPhysicalCardID = e.PhysicalCardID; CLOGException.Trace(m_nPLCID, "WorkFlowLib.CWorkFlow.ICCardMgmt ", string.Format("strPhysicalCardID:{0}", strPhysicalCardID)); if (!m_dictHallID.ContainsKey(nHallID) || string.IsNullOrWhiteSpace(strPhysicalCardID)) { CLOGException.Trace(m_nPLCID, "WorkFlowLib.CWorkFlow.ICCardMgmt ", "nHallID or strPhysicalCardID is invalid"); return;//打印日志 } struHallEquips struLocation = m_dictHallID[nHallID]; CRequestAction requestAction = new CRequestAction(); requestAction.struHallEquip = struLocation; int nActionFlag = 0; m_taskTrigger.SwipeICCard(ref nActionFlag, ref requestAction, strPhysicalCardID, struLocation); requestAction.PLCServer = m_commModule; requestAction.DicSound = m_dicSound; requestAction.RequestAction(nActionFlag, m_sendTelegramAction, m_modifyDBAction, m_soundAction); } catch (Exception ex) { //打印日志 CLOGException.Trace("WorkFlowLib.CWorkFlow.ICCardMgmt异常", CBaseMethods.MyBase.GetExceptionInfo(ex)); } }
/// <summary> /// 消息报文处理 /// </summary> private void DealTelegramMessage(object objTelegram) { try { if (objTelegram.GetType() != typeof(Int16[])) { return; } //解析报文 m_telegramParser.UnpackTelegram(out m_struTelegram, (Int16[])objTelegram); int nActionFlag = 0; CRequestAction requestAction = new CRequestAction(); if (m_dictHallID.ContainsKey(m_struTelegram.nEquipID)) { requestAction.struHallEquip = m_dictHallID[m_struTelegram.nEquipID]; } requestAction.structTelegram = m_struTelegram; m_taskTrigger.Telegram(ref nActionFlag, ref requestAction, m_struTelegram); requestAction.PLCServer = m_commModule; requestAction.DicSound = m_dicSound; requestAction.RequestAction(nActionFlag, m_sendTelegramAction, m_modifyDBAction, m_soundAction); } catch (Exception ex) { //打印日志 CLOGException.Trace("WorkFlowLib.CWorkFlow.DealTelegramMessage异常", CBaseMethods.MyBase.GetExceptionInfo(ex)); } }
/// <summary> /// 初始化LED /// </summary> public void InitLEDManagement() { try { if (m_nPLCID != 1) { return; } #region 线程方式 isStartLed = true; LedThread = new Thread(new ThreadStart(LedShowMsg)); LedThread.IsBackground = true; LedThread.Start(); #endregion #region m_mainCallback.MainCallbackEvent += new MainEventHandler(LEDManagement); //List<CDeviceStatusDto> halls = CCommonMethods.myMethods.GetDeviceStatusList(m_nPLCID, EnmSMGType.Hall); //foreach (CDeviceStatusDto hall in halls) //{ // CMainEventArgs e = new CMainEventArgs(); // e.ObjTable = hall; // LEDManagement(this, e); //} #endregion CLOGException.Trace(m_nPLCID, "WorkFlowLib", "Init Thread(LEDManagement) successfully"); } catch (Exception ex) { //打印日志 CLOGException.Trace("WorkFlowLib.CWorkFlow.InitLEDManagement 异常", CBaseMethods.MyBase.GetExceptionInfo(ex)); } }
/// <summary> /// 释放资源,继承IDisposable接口 /// </summary> /// <param name="bDisposing"></param> protected void Dispose(bool bDisposing) { try { if (!m_isDisposed) { if (bDisposing) { isStart = false; //释放托管资源 m_commModule.CallbackTelegramEvent -= new CallbackTelegramEventHandler(TelegramMgmt); m_commModule.Dispose(); DisposeICCardReader(); if (queueThread != null && queueThread.ThreadState == ThreadState.Running) { queueThread.Abort(); CLOGException.Trace(m_nPLCID, "WorkFlowLib", "Stop Thread(TelegramQueue) successfully"); } } this.m_isDisposed = true; } } catch { } }
/// <summary> /// 语音播放 /// </summary> public override void ReadSound(string file) { try { if (string.IsNullOrWhiteSpace(m_strDeviceDescription) || string.IsNullOrWhiteSpace(file) || !m_hashDevices.ContainsKey(m_strDeviceDescription)) { return; } if (File.Exists(file) == false) { return; } if (null != m_buf) { m_buf.Stop(); m_buf.Dispose(); m_buf = null; } using (BufferDescription temp = new BufferDescription()) { temp.Flags = BufferDescriptionFlags.GlobalFocus; m_buf = new SecondaryBuffer(file, temp, (Device)m_hashDevices[m_strDeviceDescription]); m_buf.Play(0, BufferPlayFlags.Default); } } catch (Exception ex) { CLOGException.Trace("SoundManagementLib.CSoundDirectX.ReadSound 异常", CBaseMethods.MyBase.GetExceptionInfo(ex)); } }
/// <summary> /// 初始化(是否添加定时器) /// </summary> public override void Initialize(List <string> lstConnect, bool isTimer) { // 打开TCP通信 Open(); // 添加items项 m_lstItemValueResult.Clear(); string[] fConnects = lstConnect.ToArray(); for (int i = 0; i < fConnects.Length; i++) { ItemValueResult itemValue = new ItemValueResult() { ItemName = fConnects[i] /* 该数据项在服务器中定义的名字*/ }; m_lstItemValueResult.Add(itemValue); itemValue = null; } fConnects = null; m_isAckHandler = isTimer; CLOGException.Trace("CommunicationLib.CTcpClientAccessTimer.Initialize", string.Format("{0}successfully, isTimer:{1}", IP, isTimer)); if (isTimer) { while (true) { Timer_Tick(this, null); System.Threading.Thread.Sleep(m_updateRate);// CConfigManagement.myPara.ReadICCardRate); } //m_timer = new Timer() { Interval = m_updateRate /*ms*/, Enabled = true, /* 定义多次循环*/AutoReset = true }; //// 计时器启用 //m_timer.Elapsed += new ElapsedEventHandler(Timer_Tick); } }
/// <summary> /// 写PLC数据,写入1个object数据 /// </summary> /// <param name="msg">写入数据</param> /// <param name="itemNum">操作的Items,0-sendDB,1-sendflag,2-recvDB,3-recvflag,4-TV1alarm,5-TV1ResetAlarm,以此类推</param> /// <returns>true表示成功</returns> public override bool Write(object msg, int itemNum) { try { if (m_subscription == null || m_subscription.Items == null || itemNum >= m_subscription.Items.Count()) { return(false); } ItemValue[] itemvalues = new ItemValue[1]; itemvalues[0] = new ItemValue((Opc.ItemIdentifier)m_subscription.Items[itemNum]); itemvalues[0].Value = msg; Opc.IdentifiedResult[] idr = m_subscription.Write(itemvalues); if (idr != null && idr.Length > 0) { return(true); } else { return(false); } } catch (Exception ex) { CLOGException.Trace("函数CommunicationLib.COPCAccessTimer.Write 异常", CBaseMethods.MyBase.GetExceptionInfo(ex)); return(false); } }
/// <summary> /// 播放语音 /// </summary> public void VoicePlayer(object objRequestParam) { try { CRequestAction RequestParam = (CRequestAction)objRequestParam; m_dicSound = RequestParam.DicSound; int nPLCID = RequestParam.struHallEquip.nWareHouseID; int nHallID = RequestParam.struHallEquip.nHallID; if (!m_dicSound.ContainsKey(nHallID)) { CLOGException.Trace("AbstractActionLib.CVoicePlayer.VoicePlayer ", string.Format("无效 PLC ID = {0},或无效 Hall ID = {1}", nPLCID, nHallID)); return; } CSound player = new CSound(); player = m_dicSound[nHallID]; if (typeof(CSoundDirectX) == player.GetType()) { // struHallEquip增加语音设备号参数(读取配置文件) ((CSoundDirectX)player).SetParams(RequestParam.struHallEquip.nWareHouseID, RequestParam.struHallEquip.nHallID, RequestParam.struHallEquip.strAudioDeviceDesc); } player.ReadSound(m_strPathAuto + RequestParam.soundName); player = null; } catch (Exception ex) { CLOGException.Trace("AbstractActionLib.CVoicePlayer.VoicePlayer 异常", CBaseMethods.MyBase.GetExceptionInfo(ex)); } }
public CFormCustomerManage() { InitializeComponent(); try { iccdCom = CReadIniFile.ReadSectionData("刷卡器", "ICCardCom"); } catch (Exception ex) { CLOGException.Trace(ex.ToString()); } m_formCustomer = new CFormCustomer(); m_formCustomer.Tag = this.CucipCustomer; // 设置键盘“Esc”按钮 Button BtnCancel = new Button(); this.CancelButton = BtnCancel; BtnCancel.Click += new EventHandler(BtnCustomerClose_Click); // 设置键盘“Enter”按钮 this.AcceptButton = this.CucipCustomer.BtnFind; if (CStaticClass.ConfigBillingFlag()) {// 有收费管理系统, 删除车主信息tab this.TctlCustomer.Controls.Remove(this.TpCustomer); } this.CucipCustomer.CUserCustomerInfoPanel_Load(null, null); // 修改用户卡号的物理号时不需要 if (CStaticClass.myPara.ReplacePhyCardIDFlag) { this.LblICCardIDOld.Visible = false; this.CTxtICCardIDOld.Visible = false; } }
/// <summary> /// 启动进程 /// </summary> private void RunProcess() { try { Process[] localByName = Process.GetProcessesByName("MaintainProc");//MaintainProc.exe是想要执行程序的进程名称。 //localByName得到的是进程中所有名称为"MaintainProc.exe"的进程。 if (localByName.Length == 0) //如果得到的进程数是0, 那么说明程序未启动,需要启动程序 { string strFilePath = System.AppDomain.CurrentDomain.BaseDirectory + "MaintainProc.exe"; OMProcesses = new System.Diagnostics.Process(); OMProcesses.StartInfo.FileName = strFilePath; OMProcesses.Start(); CLOGException.Trace("Monitor", "Create process(MaintainProc)"); OMProcesses.EnableRaisingEvents = true; OMProcesses.Exited += new EventHandler(MonitorProcess); if (!OMProcesses.HasExited) { CLOGException.Trace("Monitor", "Create process(MaintainProc) successfully"); } while (true) { Thread.Sleep(10000); } } } catch (System.Exception ex) { CLOGException.Trace("KernelGuideLib.CMonitor.InitProcess 异常 ", CBaseMethods.MyBase.GetExceptionInfo(ex)); throw ex; } }
public CFormHandOrder() { InitializeComponent(); this.CboWareHouse.Items.AddRange(CStaticClass.ConfigLstWareHouseDescp().ToArray()); this.CboWareHouse.SelectedIndex = 0; // 设置键盘“Esc”按钮 Button BtnCancel = new Button(); this.CancelButton = BtnCancel; BtnCancel.Click += new EventHandler(BtnCancel_Click); m_formCarLocationStatus.ClientSize = new System.Drawing.Size(CStaticClass.ConfigMinWidth(), CStaticClass.ConfigMinHeight()); m_formCarLocationStatus.FormBorderStyle = FormBorderStyle.FixedDialog; m_formCarLocationStatus.StartPosition = FormStartPosition.CenterScreen; btnRdICCard.Enabled = false; try { iccdCom = CReadIniFile.ReadSectionData("刷卡器", "ICCardCom"); } catch (Exception ex) { CLOGException.Trace(ex.ToString()); } }
/// <summary> /// 接收服务端数据回调 /// </summary> /// <param name="ar"></param> private void ReadCallBack(IAsyncResult ar) { //接收到的数据长度 int receLen = 0; SocketError errorCode; try { receLen = m_socket.EndReceive(ar, out errorCode); char[] chars = new char[receLen + 1]; // Extract the characters as a buffer System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder(); int charLen = d.GetChars(m_dataBuffer, 0, receLen, chars, 0); System.String szData = new System.String(chars); // 构造事件 ItemValueResult[] values = new ItemValueResult[1]; values[0] = new ItemValueResult(); values[0].Value = m_dataBuffer; values[0].ItemName = "MODBUS Client:" + m_socket.LocalEndPoint.ToString(); base.OnDataChange(null, null, values); if (receLen > 0) { string strLogin = "******" + szData; byte[] data = Encoding.ASCII.GetBytes(strLogin); m_socket.BeginSend(data, 0, data.Length, SocketFlags.None, out errorCode, SendCallback, m_dataBuffer);//异步发送数据 //异步接受服务器回报的字符串 m_socket.BeginReceive(m_dataBuffer, 0, m_dataBuffer.Length, SocketFlags.None, ReadCallBack, m_dataBuffer); } } catch (Exception ex) { CLOGException.Trace("函数CommunicationLib.CTcpClientAccess.ReadCallBack 异常", CBaseMethods.MyBase.GetExceptionInfo(ex)); } }
/// <summary> /// 打开查询服务 /// </summary> private void OpenQueryService() { try { using (m_queryHost = new ServiceHost(typeof(CQueryService))) { m_queryHost.Opened += delegate { CLOGException.Trace("QueryService开启中..."); }; //ServiceMetadataBehavior smb = m_queryHost.Description.Behaviors.Find<ServiceMetadataBehavior>(); //if (smb == null) // m_queryHost.Description.Behaviors.Add(new ServiceMetadataBehavior()); m_queryHost.Open(); while (CommunicationState.Opened == m_queryHost.State) { Thread.Sleep(10000); } } } catch (System.Exception ex) { CLOGException.Trace("KernelGuide.CWCFManagement.OpenQueryService 异常", CBaseMethods.MyBase.GetExceptionInfo(ex)); } }
static void CheckProcStat() { try { Process currentProc = Process.GetCurrentProcess(); Process[] localByName = Process.GetProcessesByName("AutoParkingSystem");//想要执行程序的进程名称。 //localByName得到的是进程中所有名称为"knl_proc.exe"的进程。 if (localByName.Length > 1) //如果得到的进程数是0, 那么说明程序未启动,需要启动程序 { foreach (Process process in localByName) { if (process.Id != currentProc.Id && process.ProcessName == "AutoParkingSystem") { MessageBox.Show("服务处于启动状态!请退出后再重新启动。", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); //currentProc.Close(); //currentProc.Dispose(); currentProc.Kill(); return; } } } else { CLOGException.Trace("Start programme...(Ver:AutoParkingV100R001C01SPC100|AutoParkingV100R001C01SPC100)"); } } catch (Exception ex) { CLOGException.Trace("AutoParkingSystem.CProgram.Main 异常", CBaseMethods.MyBase.GetExceptionInfo(ex)); throw new Exception(CBaseMethods.MyBase.GetExceptionInfo(ex)); } }
/// <summary> /// 打开推送服务 /// </summary> private void OpenPushService() { try { using (m_pushHost = new ServiceHost(typeof(CPushService))) { m_pushHost.Opened += delegate { CLOGException.Trace("PushService开启中..."); }; //ServiceMetadataBehavior smb = m_pushHost.Description.Behaviors.Find<ServiceMetadataBehavior>(); //if (smb == null) // m_pushHost.Description.Behaviors.Add(new ServiceMetadataBehavior()); //m_pushHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexTcpBinding(), "mex"); m_pushHost.Open();//开启提供服务的主机的通信 while (CommunicationState.Opened == m_pushHost.State) { Thread.Sleep(10000); } } } catch (System.Exception ex) { CLOGException.Trace("KernelGuide.CWCFManagement.OpenPushService 异常", CBaseMethods.MyBase.GetExceptionInfo(ex)); } }
/// <summary> /// 触发数据更改事件 /// </summary> public void OnDataChange(string strPhysicalCardID) { if (null == m_objReader) { CLOGException.Trace("ICCardManagementLib.CSwiper.OnDataChange", "m_objReader为空对象"); } m_objReader.OnDataChange(strPhysicalCardID); }
/// <summary> /// 构造函数 /// </summary> /// <param name="nWareHouse"></param> /// <param name="nHallID"></param> /// <param name="nDeviceID"></param> public CSoundDirectX(int nWareHouse, int nHallID, string strDeviceDescription) { m_wareHouse = nWareHouse; m_hallID = nHallID; m_strDeviceDescription = strDeviceDescription; SearchSoundDevice(); CLOGException.Trace(m_wareHouse, "SoundManagementLib", "Install component(SoundManagementLib) successfully"); }
/// <summary> /// 通过TCP/IP写入byte[]类型数据到对应PLC中的DB块的对应地址里 /// </summary> /// <param name="dataType"></param> /// <param name="db"></param> /// <param name="startByteAdr"></param> /// <param name="value"></param> /// <returns></returns> public ErrorCode WriteBytes(DataType dataType, int db, int startByteAdr, byte[] value) { byte[] bReceive = new byte[513]; int varCount = 0; try { /*// -----add by wanxiaona20150909 * string data = string.Empty; * for (int i = 0; i < value.Length; i++) * { * data += string.Format("[{0}]", value[i]); * } * CLOGException.Trace(0, "CommunicationLib.CTcpClientAccessTimer.WriteBytes ", string.Format("IP:{0} db:{1} startByteAdr:{2} DATA:{3}", IP, db, startByteAdr, data)); * // -----end by wanxiaona20150909*/ varCount = value.Length; // first create the header int packageSize = 35 + value.Length; Types.ByteArray package = new Types.ByteArray(packageSize); package.Add(new byte[] { 3, 0, 0 }); package.Add((byte)packageSize); package.Add(new byte[] { 2, 0xf0, 0x80, 0x32, 1, 0, 0 }); package.Add(Types.Word.ToByteArray((ushort)(varCount - 1))); package.Add(new byte[] { 0, 0x0e }); package.Add(Types.Word.ToByteArray((ushort)(varCount + 4))); package.Add(new byte[] { 0x05, 0x01, 0x12, 0x0a, 0x10, 0x02 }); package.Add(Types.Word.ToByteArray((ushort)varCount)); package.Add(Types.Word.ToByteArray((ushort)(db))); package.Add((byte)dataType); package.Add((byte)0); package.Add(Types.Word.ToByteArray((ushort)(startByteAdr * 8))); package.Add(new byte[] { 0, 4 }); package.Add(Types.Word.ToByteArray((ushort)(varCount * 8))); // now join the header and the data package.Add(value); _mSocket.Send(package.array, package.array.Length, SocketFlags.None); _mSocket.Receive(bReceive, 512, SocketFlags.None); if (bReceive[21] != 0xff) { CLOGException.Trace("CommunicationLib.CTcpClientAccessTimer.WriteBytes ", IP + " ErrorCode.WrongNumberReceivedBytes"); return(ErrorCode.WrongNumberReceivedBytes); } return(ErrorCode.NoError); } catch (Exception ex) { LastErrorCode = ErrorCode.WriteData; LastErrorString = ""; CLOGException.Trace("函数CommunicationLib.CTcpClientAccessTimer.WriteBytes 异常," + IP, CBaseMethods.MyBase.GetExceptionInfo(ex)); return(LastErrorCode); } }
/// <summary> /// 初始化函数 /// </summary> public void StartMonitor() { OMThread = new Thread(new ThreadStart(RunProcess)) { IsBackground = true /*后台线程在主线程关闭时,子线程随之关闭,速度很快。*/ }; OMThread.Start(); CLOGException.Trace("Monitor", "Initial MaintainProc successfully"); }
/// <summary> /// 构造函数 /// </summary> /// <param name="nPLCID"></param> /// <param name="mainCallback"></param> public CWorkFlow(int nPLCID, CMainCallback mainCallback) { m_nPLCID = nPLCID; m_mainCallback = mainCallback; if (!CConfigManagement.myPara.HashGarageType.ContainsKey(m_nPLCID)) { CLOGException.Trace("WorkFlowLib", "无效PLCID = " + m_nPLCID); return; } }
/// <summary> /// 查询服务 /// </summary> private void CloseAppService() { try { } catch (System.Exception ex) { CLOGException.Trace("KernelGuide.CWCFManagement.CloseAppService 异常", CBaseMethods.MyBase.GetExceptionInfo(ex)); } }
/// <summary> /// 写PLC数据,写入1个object其中的2个字DBW30,DBW32数据 /// </summary> /// <param name="msg">写入数据</param> /// <param name="itemNum">操作的Items,0-sendDB,1-sendflag,2-recvDB,3-recvflag,4-TV1alarm,5-TV1ResetAlarm,以此类推</param> /// <returns>true表示成功</returns> public override bool Write(int nStartWord, int msg30, int msg32, int itemNum) { try { if (m_subscription == null || m_subscription.Items == null || itemNum >= m_subscription.Items.Count()) { return(false); } Item[] r_items = new Item[1]; r_items[0] = m_subscription.Items[itemNum]; ItemValueResult[] values = m_subscription.Read(r_items); if (values[0].Quality == Quality.Good) { if (typeof(byte[]) != values[0].Value.GetType()) { return(false); } byte[] bData = (byte[])values[0].Value; if (nStartWord >= bData.Length || nStartWord + 2 >= bData.Length || 1 > nStartWord) { return(false); } byte[] bytes = Types.Int.ToByteArray(msg30); bData[nStartWord - 1] = bytes[0]; bData[nStartWord] = bytes[1]; bytes = Types.Int.ToByteArray(msg32); bData[nStartWord + 1] = bytes[0]; bData[nStartWord + 2] = bytes[1]; ItemValue[] itemvalues = new ItemValue[1]; itemvalues[0] = new ItemValue((Opc.ItemIdentifier)m_subscription.Items[itemNum]); itemvalues[0].Value = bData; Opc.IdentifiedResult[] idr = m_subscription.Write(itemvalues); if (idr != null && idr.Length > 0) { return(true); } else { return(false); } } return(false); } catch (Exception ex) { CLOGException.Trace("函数CommunicationLib.COPCAccessTimer.Write 异常", CBaseMethods.MyBase.GetExceptionInfo(ex)); return(false); } }