Example #1
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
            {
            }
        }
Example #2
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);
        }
Example #3
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);
        }