Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        //用户发送下置命令
        public override bool SendCommand(IO_SERVER server, IO_COMMUNICATION communication, IO_DEVICE device, IO_PARA para, string value)
        {
            try
            {
                Dtu_Data data = new Dtu_Data();
                data.DeviceID = device.IO_DEVICE_ID;
                //获取value 的字节数组
                DeviceDrive driver = DeviceDrives.Find(x => x.DeviceDriverID == device.DEVICE_DRIVER_ID);
                if (driver != null)
                {
                    data.datas = driver.GetSendValueBytes(server, this.IOCommunication, device, para, value);
                    this.DeviceException("error=10011," + device.IO_DEVICE_ADDRESS + "设备驱动不存在");
                }

                data.ParaID = para.IO_ID;

                data.DtuID      = device.IO_DEVICE_ADDRESS;
                data.DataStatus = DataStatus.WriterData;

                string error  = "";
                bool   result = false;
                Thread.Sleep(100);//停止10秒,保证之前发送命令已经发送出去
                if (!svr.Send(data.DtuID, data.datas, out error, false))
                {
                    this.DeviceException("error=10010" + error);
                    result = false;
                }
                else
                {
                    result = true;
                }

                //信息发送完成的事件
                DataSended(server, this.IOCommunication, device, para, value, result);


                return(true);
                ///接收的数据
            }
            catch (Exception emx)
            {
                return(false);
            }
            finally
            {
            }
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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);
        }