protected ScadaCommunicateKernel CreateCommunicateDrive(SCADA_DRIVER communicateModel) { ScadaCommunicateKernel river = (ScadaCommunicateKernel)CreateObject(communicateModel.CommunicationFullName, communicateModel.FillName); if (river != null) { river.Driver = communicateModel; } return(river); }
/// <summary> /// 初始化驱动 /// </summary> public bool InitKernel(IO_SERVER server, IO_COMMUNICATION communication, List <IO_DEVICE> ioDevices, SCADA_DRIVER driver) { try { this.ParaString = ""; if (communication != null && server != null) { this.IOServer = server; this.IOCommunication = communication; this.IODevices = ioDevices; if (driver == null) { driver = driverBll.GetModel(communication.IO_COMM_DRIVER_ID); } if (driver != null) { this.Driver = driver; this.DeviceDriverModels = deviceDriverBll.GetModelList(" Dll_GUID='" + driver.GUID + "'"); if (DeviceDriverModels != null && DeviceDriverModels.Count > 0) { DeviceDrives = CreateDeviceKernel(DeviceDriverModels); } } if (communication != null) { this.ParaString = communication.IO_COMM_PARASTRING; } } return(InitCommunicateKernel(server, communication, ioDevices, driver)); } catch (Exception ex) { this.DeviceException(ex.Message); return(false); } }
public override bool InitDriver(IO_SERVER server, IO_COMMUNICATION communication, List <IO_DEVICE> ioDevices, SCADA_DRIVER driver) { if (!base.InitDriver(server, communication, ioDevices, driver)) { return(false); } try { ///DTU配置界面 ///初始化驱动控件 if (IsCreateControl)//主要是为了节省内存,在该用的地方创建 { this.CommunicationControl = new CMDTUControl(); } //构造获取数据命令的字节数组 for (int i = 0; i < this.IODevices.Count; i++) { RealData mRealData = new RealData(); mRealData.Device = this.IODevices[i]; DeviceDrive driverDll = DeviceDrives.Find(x => x.DeviceDriverID == this.IODevices[i].DEVICE_DRIVER_ID); if (driverDll != null) { driverDll.InitDrive(IOServer, IOCommunication, this.IODevices[i], null, this.IODevices[i].DriverInfo); //IO_DEVICE_ADDRESS中存储的是DTU编号 mRealData.DTUID = this.IODevices[i].IO_DEVICE_ADDRESS; //获取下发命令的参数 mRealData.ReadSendByte = driverDll.GetDataCommandBytes(this.IOServer, this.IOCommunication, this.IODevices[i], this.IODevices[i].IOParas, null); } if (mRealData.ReadSendByte != null && mRealData.ReadSendByte.Count > 0) { RealDevices.Add(mRealData); } } } catch (Exception ex) { this.DeviceException("ERROR=10023," + ex.Message); return(false); } return(true); }
protected override bool InitCommunicateKernel(IO_SERVER server, IO_COMMUNICATION communication, List <IO_DEVICE> ioDevices, SCADA_DRIVER driver) { if (IsCreateControl) { CommunicationControl = new Modbus_UDP_Ctrl(); if (communication != null) { CommunicationControl.SetUIParameter(communication.IO_COMM_PARASTRING); } } Udp_PARA = new Modbus_TCP_PARA(); if (communication != null) { TcpParaPack = new ParaPack(communication.IO_COMM_PARASTRING); Udp_PARA.CollectFaultsInternal = Convert.ToInt32(TcpParaPack.GetValue("重试间隔")); Udp_PARA.CollectFaultsNumber = Convert.ToInt32(TcpParaPack.GetValue("重试次数")); Udp_PARA.ContinueCollect = TcpParaPack.GetValue("重试") == "1" ? true : false; Udp_PARA.LocalTCP_Port = TcpParaPack.GetValue("本地端口"); Udp_PARA.LocalTCP_IP = TcpParaPack.GetValue("本地IP"); Udp_PARA.SimulatorTCP_Port = TcpParaPack.GetValue("模拟设备端口"); Udp_PARA.SimulatorTCP_IP = TcpParaPack.GetValue("模拟设备IP"); Udp_PARA.WriteTimeout = int.Parse(TcpParaPack.GetValue("写超时时间")); Udp_PARA.ReadTimeout = int.Parse(TcpParaPack.GetValue("读超时时间")); Udp_PARA.WriteBufferSize = int.Parse(TcpParaPack.GetValue("写缓存")); Udp_PARA.ReadBufferSize = int.Parse(TcpParaPack.GetValue("读缓存")); //构造获取数据命令的字节数组,Modbus for (int i = 0; i < this.IODevices.Count; i++) { object fragment = new ModbusFragmentStore(); RealData mRealData = new RealData(); mRealData.Device = this.IODevices[i]; ScadaDeviceKernel driverDll = DeviceDrives.Find(x => x.DeviceDriverID == this.IODevices[i].DEVICE_DRIVER_ID); if (driverDll != null) { driverDll.InitKernel(IOServer, IOCommunication, this.IODevices[i], null, this.IODevices[i].DriverInfo); //IO_DEVICE_ADDRESS中存储的是DTU编号 mRealData.SlaveId = this.IODevices[i].IO_DEVICE_ADDRESS; //数据库中系统编号 mRealData.DEVICEID = this.IODevices[i].IO_DEVICE_ID; //获取下发命令的参数,注意此次要进心分段存储,因为modbus一次不能超过123个寄存器地址 //mRealData.ReadSendByte = driverDll.GetDataCommandBytes(this.IOServer, this.IOCommunication, this.IODevices[i], this.IODevices[i].IOParas, null, ref fragment); } mRealData.Fragment = (ModbusFragmentStore)fragment; RealDevices.Add(mRealData); } } return(true); }
public override bool InitDriver(IO_SERVER server, IO_COMMUNICATION communication, List <IO_DEVICE> ioDevices, SCADA_DRIVER driver) { try { base.InitDriver(server, communication, ioDevices, driver); if (IsCreateControl) { CommunicationControl = new Modbus_TCP_Network_Bridge_Ctrl(); } } catch { return(false); } return(true); }
protected override bool InitCommunicateKernel(IO_SERVER server, IO_COMMUNICATION communication, List <IO_DEVICE> ioDevices, SCADA_DRIVER driver) { if (IsCreateControl) { CommunicationControl = new Modbus_Serial_Ctrl(); if (communication != null) { CommunicationControl.SetUIParameter(communication.IO_COMM_PARASTRING); } } Serial_PARA = new Modbus_Serial_PARA(); if (communication != null) { comParaPack = new ParaPack(communication.IO_COMM_PARASTRING); Serial_PARA.BaudRate = Convert.ToInt32(comParaPack.GetValue("波特率")); Serial_PARA.CollectFaultsInternal = Convert.ToInt32(comParaPack.GetValue("重试间隔")); Serial_PARA.CollectFaultsNumber = Convert.ToInt32(comParaPack.GetValue("重试次数")); Serial_PARA.ContinueCollect = comParaPack.GetValue("连续采集") == "1" ? true : false; Serial_PARA.DataBits = Convert.ToInt32(comParaPack.GetValue("数据位")); Serial_PARA.ModbusType = (ModbusType)Enum.Parse(typeof(ModbusType), comParaPack.GetValue("MODBUS类型")); Serial_PARA.OffsetInterval = Convert.ToInt32(comParaPack.GetValue("偏移间隔")); Serial_PARA.PackMaxSize = Convert.ToInt32(comParaPack.GetValue("包最大长度")); Serial_PARA.ReadTimeout = Convert.ToInt32(comParaPack.GetValue("读超时时间")); Serial_PARA.RSTSendPreKeeyTime = Convert.ToInt32(comParaPack.GetValue("发送前RTS保持时间")); Serial_PARA.RTSSendAfterKeeyTime = Convert.ToInt32(comParaPack.GetValue("发送后RTS保持时间")); Serial_PARA.RTSEnable = comParaPack.GetValue("RTS") == "1" ? true : false; Serial_PARA.SerialCheck = (SerialCheck)Enum.Parse(typeof(SerialCheck), comParaPack.GetValue("校验")); Serial_PARA.SerialPort = comParaPack.GetValue("串口"); Serial_PARA.SimulatorSerialPort = comParaPack.GetValue("模拟器串口"); Serial_PARA.SixCommmand = comParaPack.GetValue("支持6号命令") == "1" ? true : false; Serial_PARA.SixteenCommmand = comParaPack.GetValue("支持16号命令") == "1" ? true : false;; Serial_PARA.StopBits = (StopBits)Enum.Parse(typeof(StopBits), comParaPack.GetValue("停止位")); Serial_PARA.WriteTimeout = Convert.ToInt32(comParaPack.GetValue("写超时时间")); //构造获取数据命令的字节数组,Modbus for (int i = 0; i < this.IODevices.Count; i++) { object fragment = new ModbusFragmentStore(); RealData mRealData = new RealData(); mRealData.Device = this.IODevices[i]; ScadaDeviceKernel driverDll = DeviceDrives.Find(x => x.DeviceDriverID == this.IODevices[i].DEVICE_DRIVER_ID); if (driverDll != null) { driverDll.InitKernel(IOServer, IOCommunication, this.IODevices[i], null, this.IODevices[i].DriverInfo); //IO_DEVICE_ADDRESS中存储的是DTU编号 mRealData.SlaveId = this.IODevices[i].IO_DEVICE_ADDRESS; //数据库中系统编号 mRealData.DEVICEID = this.IODevices[i].IO_DEVICE_ID; //获取下发命令的参数,注意此次要进心分段存储,因为modbus一次不能超过123个寄存器地址 mRealData.Fragment = (ModbusFragmentStore)fragment; RealDevices.Add(mRealData); } } } return(true); }
/// <summary> /// 初始化驱动 /// </summary> /// <param name="server"></param> /// <param name="communication"></param> /// <param name="ioDevices"></param> /// <param name="driver"></param> /// <returns></returns> protected override bool InitCommunicateKernel(IO_SERVER server, IO_COMMUNICATION communication, List <IO_DEVICE> ioDevices, SCADA_DRIVER driver) { try { ParaPack communicatePack = new ParaPack(communication.IO_COMM_PARASTRING); if (communication.IO_COMM_PARASTRING != null && communication.IO_COMM_PARASTRING != "") { this.ServerIP = communicatePack.GetValue("服务器IP"); this.ServerPort = int.Parse(communicatePack.GetValue("端口号")); this.UserName = communicatePack.GetValue("用户名"); this.Password = communicatePack.GetValue("密码"); this.EaableAnonymousAuthentication = bool.Parse(communicatePack.GetValue("开启匿名验证")); this.HeartTime = int.Parse(communicatePack.GetValue("心跳时间")); string msgqulity = communicatePack.GetValue("消息质量"); switch (msgqulity) { case "QoS 0 最多分发一次": MessageQulity = MqttQualityOfServiceLevel.AtMostOnce; break; case "QoS 1 至少分发一次": MessageQulity = MqttQualityOfServiceLevel.AtLeastOnce; break; case "QoS 2 只分发一次": MessageQulity = MqttQualityOfServiceLevel.ExactlyOnce; break; } this.WillFlag = communicatePack.GetValue("遗愿标志"); this.MqttDataType = communicatePack.GetValue("数据格式"); this.EaableClientIDAuthentication = bool.Parse(communicatePack.GetValue("开启Mqtt客户端识别")); } if (IsCreateControl) { CommunicationControl = new MQTTServerCtrl(); if (communication != null && communication.IO_COMM_PARASTRING != "") { CommunicationControl.SetUIParameter(communication.IO_COMM_PARASTRING); } } } catch (Exception emx) { this.DeviceException(emx.Message); return(false); } return(true); }
public override bool InitDriver(IO_SERVER server, IO_COMMUNICATION communication, List <IO_DEVICE> ioDevices, SCADA_DRIVER driver) { try { base.InitDriver(server, communication, ioDevices, driver); if (IsCreateControl) { CommunicationControl = new Modbus_Serial_Ctrl(); CommunicationControl.SetUIParameter(communication.IO_COMM_PARASTRING); } //构造获取数据命令的字节数组,Modbus for (int i = 0; i < this.IODevices.Count; i++) { RealData mRealData = new RealData(); mRealData.Device = this.IODevices[i]; DeviceDrive driverDll = DeviceDrives.Find(x => x.DeviceDriverID == this.IODevices[i].DEVICE_DRIVER_ID); if (driverDll != null) { driverDll.InitDrive(IOServer, IOCommunication, this.IODevices[i], null, this.IODevices[i].DriverInfo); //IO_DEVICE_ADDRESS中存储的是DTU编号 mRealData.SlaveId = this.IODevices[i].IO_DEVICE_ADDRESS; //数据库中系统编号 mRealData.DEVICEID = this.IODevices[i].IO_DEVICE_ID; //获取下发命令的参数 mRealData.ReadSendByte = driverDll.GetDataCommandBytes(this.IOServer, this.IOCommunication, this.IODevices[i], this.IODevices[i].IOParas, null); } if (mRealData.ReadSendByte != null && mRealData.ReadSendByte.Count > 0) { RealDevices.Add(mRealData); } } } catch { return(false); } return(true); }
public static void InitBaseModel() { if (ServerID == "") { return; } try { DbHelperSQLite.connectionString = "Data Source=" + Application.StartupPath + "\\IOProject\\Station.station"; IO_SERVER serverBll = new IO_SERVER(); AddLogToMainLog("读取采集站信息......"); IOServer = serverBll.GetModel(mServerID); if (IOServer == null) { return; } mServerID = IOServer.SERVER_ID; IOServer.SERVER_IP = LocalIp.GetLocalIp(); serverBll.Update(IOServer); //加载通道 AddLogToMainLog("读取采集站通道信息......"); IO_COMMUNICATION commBll = new IO_COMMUNICATION(); SCADA_DRIVER DriverBll = new SCADA_DRIVER(); SCADA_DEVICE_DRIVER DeviceDriverBll = new SCADA_DEVICE_DRIVER(); CommDrivers = DriverBll.GetModelList(""); DeviceDrivers = DeviceDriverBll.GetModelList(""); IOCommunications = commBll.GetModelList(" IO_SERVER_ID='" + IOServer.SERVER_ID + "'"); AddLogToMainLog("读取采集站通道下的所有设备信息......"); IO_DEVICE deviceBll = new IO_DEVICE(); IODevices = deviceBll.GetModelList(" IO_SERVER_ID='" + IOServer.SERVER_ID + "'"); AddLogToMainLog("数据处理中....."); for (int i = 0; i < IOCommunications.Count; i++) { IOCommunications[i].DriverInfo = CommDrivers.Find(x => x.Id == IOCommunications[i].IO_COMM_DRIVER_ID); if (IOCommunications[i].DriverInfo != null) { IOCommunications[i].CommunicateDriver = DriverAssembly.CreateCommunicateDriver(IOCommunications[i].DriverInfo); } AddLogToMainLog("处理 " + IOCommunications[i].IO_COMM_NAME + "[" + IOCommunications[i].IO_COMM_LABEL + "]"); IOCommunications[i].Devices = IODevices.FindAll(x => x.IO_COMM_ID == IOCommunications[i].IO_COMM_ID && x.IO_SERVER_ID == IOCommunications[i].IO_SERVER_ID); for (int j = 0; j < IOCommunications[i].Devices.Count; j++) { IOCommunications[i].Devices[j].DriverInfo = DeviceDrivers.Find(x => x.Id == IOCommunications[i].Devices[j].DEVICE_DRIVER_ID); if (IOCommunications[i].Devices[j].DriverInfo != null) { IOCommunications[i].Devices[j].DeviceDrive = DriverAssembly.CreateDeviceDrive(IOCommunications[i].Devices[j].DriverInfo); } } } AddLogToMainLog("正在创建驱动....."); AddLogToMainLog("读取工程完成!"); ProgressMaxNum = IOCommunications.Count + IODevices.Count; } catch (Exception ex) { ThrowExceptionToMain(ex); } }
protected virtual bool InitCommunicateKernel(IO_SERVER server, IO_COMMUNICATION communication, List <IO_DEVICE> ioDevices, SCADA_DRIVER driver) { try { return(true); } catch { return(false); } }