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); }
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); }