using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Threading; using Microsoft.VisualBasic; using DBFactory; using ICommLayer; namespace Symbol3204 { /// /// 使用SocketsUDP的客户端进行通讯 /// 发送设备命令类 /// 创建者:Richard.Liu /// public class CSendDeviceOrder: ISendDeviceOrder { string _commLayerError; public string CommLayerError { get { return _commLayerError; } set { _commLayerError = value; } } DBOperator dbo = new DBOperator(); public CSendDeviceOrder() { dbo.Open(); } public bool SendDeviceOrder(int MessageIndex, int TaskIndex, int Order, int DeviceIndex) { try { CScan cs; //根据DeviceIndex,得到串口号和初始设置 DataSet ds = dbo.ExceSQL("SELECT F_DeviceIndex, F_CommSettings, F_SerialPort FROM T_Base_Device where F_DeviceIndex=" + DeviceIndex); DataView dv = ds.Tables[0].DefaultView; if (ds.Tables[0].DefaultView.Count > 0) { cs = new CScan(Convert.ToInt16(dv[0]["F_SerialPort"]), Convert.ToString(dv[0]["F_CommSettings"])); if (Order == 1)//触发扫描 { if (cs.StartSession() == true) { cs.StopScan(); return true; } else { cs.StopScan(); return false; } } else//停止触发 { if (cs.StopSession() == true) { cs.StopScan(); return true; } else { cs.StopScan(); return false; } } } else { { return false; } } } catch (Exception ex) { _commLayerError = "Symbol3204:SendDeviceOrder---" + ex.Message; return false; } } public bool SendDeviceOrder(int MessageIndex, int TaskIndex, int Order, int DeviceIndex, int StartX, int StartY, int StartZ, int EndX, int EndY, int EndZ) { try { CScan cs; //根据DeviceIndex,得到串口号和初始设置 DataSet ds = dbo.ExceSQL("SELECT F_DeviceIndex, F_CommSettings, F_SerialPort FROM T_Base_Device where F_DeviceIndex=" + DeviceIndex); DataView dv = ds.Tables[0].DefaultView; if (ds.Tables[0].DefaultView.Count > 0) { cs = new CScan(Convert.ToInt16(dv[0]["F_SerialPort"]), Convert.ToString(dv[0]["F_CommSettings"])); if (Order == 1)//触发扫描 { if (cs.StartSession() == true) { cs.StopScan(); return true; } else { cs.StopScan(); return false; } } else//停止触发 { if (cs.StopSession() == true) { cs.StopScan(); return true; } else { cs.StopScan(); return false; } } } else { return false; } } catch (Exception ex) { _commLayerError = "Symbol3204:SendDeviceOrder---" + ex.Message; return false; } } } }