Пример #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);
        }
Пример #2
0
        /// <summary>
        /// 创建设备驱动
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static ScadaDeviceKernel CreateDeviceDrive(Scada.Model.SCADA_DEVICE_DRIVER driveModel)
        {
            try
            {
                ScadaDeviceKernel river = (ScadaDeviceKernel)CreateObject(driveModel.DeviceFullName, driveModel.Dll_Name);

                return(river);
            }
            catch
            {
                return(null);
            }
        }
Пример #3
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);
        }
Пример #4
0
        private void cb_Driver_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cb_Driver.SelectedItem != null)
            {
                try
                {
                    Scada.Model.SCADA_DEVICE_DRIVER driver = cb_Driver.SelectedItem as Scada.Model.SCADA_DEVICE_DRIVER;
                    DriverKernel = FormManager.CreateDeviceDrive(driver);
                    DriverKernel.IsCreateControl = true;
                    try
                    {
                        DriverKernel.InitKernel(Server, Communication, Device, null, driver);
                    }
                    catch (Exception emx)
                    {
                        FormManager.DisplayException(new Exception("设备驱动初始化InitDriver失败" + emx.Message));
                    }
                    try
                    {
                        if (DriverKernel.DeviceCtrl != null)
                        {
                            DriverKernel.DeviceCtrl.SetUIParameter(Server, Device);
                        }
                    }
                    catch (Exception emx)
                    {
                        FormManager.DisplayException(new Exception("解析设备驱动参数失败(SetUIParameter)" + emx.Message));
                    }


                    this.tabPage2.Controls.Clear();
                    if (DriverKernel.DeviceCtrl != null)
                    {
                        this.tabPage2.Controls.Add(DriverKernel.DeviceCtrl);
                    }
                }
                catch (Exception emx)
                {
                    FormManager.DisplayException(new Exception("加载设备驱动失败" + emx.Message));
                }
            }
        }
Пример #5
0
        private bool ResponseData(IO_SERVER server, IO_COMMUNICATION comm, IO_DEVICE device, IO_PARA para, string value)
        {
            if (para == null)
            {
                return(false);
            }
            if (para.IO_POINTTYPE == "计算值" || para.IO_POINTTYPE == "关系数据库值")
            {
                return(false);
            }
            //设备地址不能为空
            if (device.IO_DEVICE_ADDRESS == "")
            {
                return(false);
            }
            try
            {
                //通过设备驱动进行数据解析,并生成下置的数据bytes
                if (device.DeviceDrive != null)
                {
                    ScadaDeviceKernel Driver = (ScadaDeviceKernel)device.DeviceDrive;

                    //获取参数中的
                    if (udpClient != null && master != null)
                    {
                        ParaPack paraPack = new ParaPack(para.IO_PARASTRING);
                        if (paraPack.Count > 0)
                        {
                            ushort offset = ushort.Parse(paraPack.GetValue("偏置"));
                            switch (paraPack.GetValue("内存区"))
                            {
                            case "01":
                            {
                                if (ushort.Parse(value) > 0)
                                {
                                    master.WriteSingleCoil(byte.Parse(device.IO_DEVICE_ADDRESS), offset, true);
                                }
                                else
                                {
                                    master.WriteSingleCoil(byte.Parse(device.IO_DEVICE_ADDRESS), offset, false);
                                }
                            }
                            break;

                            case "02":    //此类型只能查询,不能写入
                            {
                            }
                            break;

                            case "03":
                            {
                                Modbus_Type datatype     = (Modbus_Type)Enum.Parse(typeof(Modbus_Type), paraPack.GetValue("数据类型"));
                                bool        ishigh       = paraPack.GetValue("存储位置") == "高八位" ? true : false;
                                int         charsize     = int.Parse(paraPack.GetValue("字节长度"));
                                bool        isposition   = paraPack.GetValue("按位存取") == "1" ? true : false;
                                int         dataposition = int.Parse(paraPack.GetValue("数据位"));
                                switch (datatype)
                                {
                                case Modbus_Type.单精度浮点数32位:
                                {
                                    ushort[] buff       = new ushort[2];
                                    float    WriteValue = float.Parse(value);
                                    ModbusConvert.SetReal(buff, 0, WriteValue);
                                    master.WriteMultipleRegisters(byte.Parse(device.IO_DEVICE_ADDRESS), offset, buff);
                                }
                                break;

                                case Modbus_Type.双精度浮点数64位:
                                {
                                    ushort[] buff       = new ushort[4];
                                    double   WriteValue = double.Parse(value);
                                    ModbusConvert.SetDouble(buff, 0, WriteValue);
                                    master.WriteMultipleRegisters(byte.Parse(device.IO_DEVICE_ADDRESS), offset, buff);
                                }
                                break;

                                case Modbus_Type.字符型:
                                {
                                    ushort[] buff       = new ushort[charsize];
                                    string   WriteValue = value;
                                    if (value.Length > charsize)
                                    {
                                        WriteValue = value.Substring(0, charsize);
                                    }
                                    if (value.Length < charsize)
                                    {
                                        WriteValue = value.PadRight(charsize, ' ');
                                    }
                                    ModbusConvert.SetString(buff, 0, WriteValue);
                                    master.WriteMultipleRegisters(byte.Parse(device.IO_DEVICE_ADDRESS), offset, buff);
                                }
                                break;

                                case Modbus_Type.无符号整数8位:
                                {
                                    ushort[] buff       = new ushort[1];
                                    byte     WriteValue = byte.Parse(value);
                                    ModbusConvert.SetByte(buff, 0, WriteValue, ishigh);
                                    master.WriteSingleRegister(byte.Parse(device.IO_DEVICE_ADDRESS), offset, buff[0]);
                                }
                                break;

                                case Modbus_Type.符号整数8位:
                                {
                                    ushort[] buff       = new ushort[1];
                                    sbyte    WriteValue = sbyte.Parse(value);
                                    ModbusConvert.SetSByte(buff, 0, WriteValue, ishigh);
                                    master.WriteSingleRegister(byte.Parse(device.IO_DEVICE_ADDRESS), offset, buff[0]);
                                }
                                break;

                                case Modbus_Type.无符号整数16位:
                                {
                                    if (isposition)
                                    {
                                        //获取当前寄存器的值
                                        ushort[] datas     = master.ReadHoldingRegisters(byte.Parse(device.IO_DEVICE_ADDRESS), offset, 1);
                                        ushort   dataValue = ModbusConvert.GetUShort(datas, 0);

                                        if (short.Parse(value) > 0)
                                        {
                                            dataValue = Convert.ToUInt16(dataValue >> dataposition & 1);
                                        }
                                        else
                                        {
                                            dataValue = Convert.ToUInt16(dataValue >> dataposition & 0);
                                        }
                                        //新发送的值

                                        ushort[] datas2 = new ushort[1];
                                        ModbusConvert.SetUShort(datas2, 0, dataValue);
                                        master.WriteSingleRegister(byte.Parse(device.IO_DEVICE_ADDRESS), offset, datas2[0]);
                                    }
                                    else
                                    {
                                        ushort   WriteValue = ushort.Parse(value);
                                        ushort[] buff       = new ushort[1];
                                        ModbusConvert.SetUShort(buff, 0, WriteValue);
                                        master.WriteSingleRegister(byte.Parse(device.IO_DEVICE_ADDRESS), offset, buff[0]);
                                    }
                                }
                                break;

                                case Modbus_Type.符号整数16位:
                                {
                                    if (isposition)
                                    {
                                        //获取当前寄存器的值
                                        ushort[] datas     = master.ReadHoldingRegisters(byte.Parse(device.IO_DEVICE_ADDRESS), offset, 1);
                                        short    dataValue = ModbusConvert.GetShort(datas, 0);

                                        if (short.Parse(value) > 0)
                                        {
                                            dataValue = Convert.ToInt16(dataValue >> dataposition & 1);
                                        }
                                        else
                                        {
                                            dataValue = Convert.ToInt16(dataValue >> dataposition & 0);
                                        }
                                        //新发送的值

                                        ushort[] datas2 = new ushort[1];
                                        ModbusConvert.SetShort(datas2, 0, dataValue);
                                        master.WriteSingleRegister(byte.Parse(device.IO_DEVICE_ADDRESS), offset, datas2[0]);
                                    }
                                    else
                                    {
                                        Int16    WriteValue = Int16.Parse(value);
                                        ushort[] buff       = new ushort[1];
                                        ModbusConvert.SetShort(buff, 0, WriteValue);
                                        master.WriteSingleRegister(byte.Parse(device.IO_DEVICE_ADDRESS), offset, buff[0]);
                                    }
                                }
                                break;

                                case Modbus_Type.无符号整数32位:
                                {
                                    uint     WriteValue = uint.Parse(value);
                                    ushort[] buff       = new ushort[2];
                                    ModbusConvert.SetUInt(buff, 0, WriteValue);
                                    master.WriteMultipleRegisters(byte.Parse(device.IO_DEVICE_ADDRESS), offset, buff);
                                }
                                break;

                                case Modbus_Type.符号整数32位:
                                {
                                    int      WriteValue = int.Parse(value);
                                    ushort[] buff       = new ushort[2];
                                    ModbusConvert.SetInt(buff, 0, WriteValue);
                                    master.WriteMultipleRegisters(byte.Parse(device.IO_DEVICE_ADDRESS), offset, buff);
                                }
                                break;
                                }
                            }
                            break;
                            }
                        }
                    }
                }
            }
            catch
            {
                return(false);
            }
            return(true);
        }
Пример #6
0
        /// <summary>
        /// 返回服务器端接收的数据,此处主要将一个设备下的所有IO表数据统一获取后在一次性上传,
        /// </summary>
        /// <param name="server"></param>
        /// <param name="comm"></param>
        /// <param name="device"></param>
        /// <param name="para">为null,此参数不传递,根据用户驱动需要</param>
        /// <param name="receivedatas">接收的全部数据,要求在驱动中进行一次读取后返回</param>

        public static void CDriverDll_OnDataReceived(IO_SERVER server, IO_COMMUNICATION comm, IO_DEVICE device, byte[] receivedatas, string date, object sender)
        {
            //解析数据
            var analysisTask = Task.Run(() =>
            {
                try
                {
                    if (device != null && device.DeviceDrive != null)
                    {
                        //清理已经接收完成的数据
                        for (int i = 0; i < device.IOParas.Count; i++)
                        {
                            device.IOParas[i].IORealData = null;
                        }

                        device.GetedValueDate = DateTime.Now;
                        device.ReceiveBytes   = receivedatas;
                        #region 循环解析实时数据接收的每个参数

                        ScadaDeviceKernel Driver = (ScadaDeviceKernel)device.DeviceDrive;
                        for (int i = 0; i < device.IOParas.Count; i++)
                        {
                            #region 解析开关量 模拟量 字符常量 数据
                            try
                            {
                                if (device.IOParas[i].IO_POINTTYPE == "模拟量" || device.IOParas[i].IO_POINTTYPE == "开关量" || device.IOParas[i].IO_POINTTYPE == "字符串量")
                                {
                                    try
                                    {
                                        Driver.InitKernel(server, comm, device, device.IOParas[i], device.DriverInfo);
                                        IOData recdata = Driver.AnalysisData(server, comm, device, device.IOParas[i], receivedatas, Convert.ToDateTime(date), sender);
                                        if (recdata != null)
                                        {
                                            device.IOParas[i].IORealData = recdata;
                                        }
                                    }
                                    catch
                                    {
                                        device.IOParas[i].IORealData = null;
                                    }
                                }
                            }
                            catch
                            {
                            }
                            #endregion
                            #region 解析关系数据库值
                            try
                            {
                                if (device.IOParas[i].IO_POINTTYPE == "关系数据库值" && device.IOParas[i].IO_DATASOURCE.Trim() != "")
                                {
                                    RelationalDatabase rlation = new RelationalDatabase(device.IOParas[i].IO_DATASOURCE);
                                    string sql  = rlation.GetSql();
                                    string conn = rlation.ConnectString;
                                    switch (rlation.Database_Type)
                                    {
                                    case "SQL Server":
                                        {
                                            try
                                            {
                                                if (conn != "" && sql != "")
                                                {
                                                    DbHelperSQL sqlHealp      = new DbHelperSQL();
                                                    sqlHealp.connectionString = conn;
                                                    DataSet ds = sqlHealp.Query(sql);
                                                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                                                    {
                                                        device.IOParas[i].IORealData = new IOData();
                                                        device.IOParas[i].IORealData.CommunicationID = device.IO_COMM_ID;
                                                        device.IOParas[i].IORealData.ServerID        = device.IO_SERVER_ID;
                                                        device.IOParas[i].IORealData.ID           = device.IO_DEVICE_ID;
                                                        device.IOParas[i].IORealData.ParaName     = device.IOParas[i].IO_NAME;
                                                        device.IOParas[i].IORealData.ParaString   = device.IOParas[i].IO_PARASTRING;
                                                        device.IOParas[i].IORealData.ParaValue    = ds.Tables[0].Rows[0]["value"].ToString();
                                                        device.IOParas[i].IORealData.QualityStamp = QualityStamp.GOOD;
                                                        device.IOParas[i].IORealData.Date         = Convert.ToDateTime(ds.Tables[0].Rows[0]["datetime"].ToString());
                                                    }
                                                }
                                            }
                                            catch
                                            {
                                                device.IOParas[i].IORealData = null;
                                            }
                                        }
                                        break;

                                    case "ORACLE":
                                        {
                                            try
                                            {
                                                if (conn != "" && sql != "")
                                                {
                                                    DbHelperOra oracleHealp      = new DbHelperOra();
                                                    oracleHealp.connectionString = conn;
                                                    DataSet ds = oracleHealp.Query(sql);
                                                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                                                    {
                                                        device.IOParas[i].IORealData = new IOData();
                                                        device.IOParas[i].IORealData.CommunicationID = device.IO_COMM_ID;
                                                        device.IOParas[i].IORealData.ServerID        = device.IO_SERVER_ID;
                                                        device.IOParas[i].IORealData.ID           = device.IO_DEVICE_ID;
                                                        device.IOParas[i].IORealData.ParaName     = device.IOParas[i].IO_NAME;
                                                        device.IOParas[i].IORealData.ParaString   = device.IOParas[i].IO_PARASTRING;
                                                        device.IOParas[i].IORealData.ParaValue    = ds.Tables[0].Rows[0]["value"].ToString();
                                                        device.IOParas[i].IORealData.QualityStamp = QualityStamp.GOOD;
                                                        device.IOParas[i].IORealData.Date         = Convert.ToDateTime(ds.Tables[0].Rows[0]["datetime"].ToString());
                                                    }
                                                }
                                            }
                                            catch
                                            {
                                                device.IOParas[i].IORealData = null;
                                            }
                                        }
                                        break;

                                    case "MySql":
                                        {
                                            try
                                            {
                                                if (conn != "" && sql != "")
                                                {
                                                    DbHelperMySQL mysqlHealp    = new DbHelperMySQL();
                                                    mysqlHealp.connectionString = conn;
                                                    DataSet ds = mysqlHealp.Query(sql);
                                                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                                                    {
                                                        device.IOParas[i].IORealData = new IOData();
                                                        device.IOParas[i].IORealData.CommunicationID = device.IO_COMM_ID;
                                                        device.IOParas[i].IORealData.ServerID        = device.IO_SERVER_ID;
                                                        device.IOParas[i].IORealData.ID           = device.IO_DEVICE_ID;
                                                        device.IOParas[i].IORealData.ParaName     = device.IOParas[i].IO_NAME;
                                                        device.IOParas[i].IORealData.ParaString   = device.IOParas[i].IO_PARASTRING;
                                                        device.IOParas[i].IORealData.ParaValue    = ds.Tables[0].Rows[0]["value"].ToString();
                                                        device.IOParas[i].IORealData.QualityStamp = QualityStamp.GOOD;
                                                        device.IOParas[i].IORealData.Date         = Convert.ToDateTime(ds.Tables[0].Rows[0]["datetime"].ToString());
                                                        double d = 0;
                                                        if (double.TryParse(device.IOParas[i].IORealData.ParaValue, out d))
                                                        {
                                                            device.IOParas[i].IORealData.DataType = typeof(double);
                                                        }
                                                        else
                                                        {
                                                            device.IOParas[i].IORealData.DataType = typeof(string);
                                                        }
                                                    }
                                                }
                                            }
                                            catch
                                            {
                                                device.IOParas[i].IORealData = null;
                                            }
                                        }
                                        break;
                                    }
                                }
                            }
                            catch
                            {
                            }
                            #endregion
                            #region 解析计算值包含公式计算的

                            //

                            try
                            {
                                if (device.IOParas[i].IO_POINTTYPE == "计算值")
                                {
                                    if (device.IOParas[i].IO_FORMULA.Trim() != "")
                                    {
                                        device.IOParas[i].IORealData = new IOData();
                                        try
                                        {
                                            device.IOParas[i].IORealData.QualityStamp = QualityStamp.GOOD;
                                            device.IOParas[i].IORealData.Date         = DateTime.Now;
                                            device.IOParas[i].IORealData.ParaName     = device.IOParas[i].IO_NAME;
                                            device.IOParas[i].IORealData.DataType     = typeof(double);
                                            //替换关键字为数值
                                            string formula = device.IOParas[i].IO_FORMULA;
                                            foreach (IO_PARA para in device.IOParas)
                                            {
                                                if (device.IOParas[i].IO_POINTTYPE != "字符串量" && device.IOParas[i].IO_POINTTYPE != "计算值" && device.IOParas[i].IORealData != null)
                                                {
                                                    if (device.IOParas[i].IORealData.QualityStamp == QualityStamp.GOOD && device.IOParas[i].IORealData.ParaValue != "-9999" && device.IOParas[i].IORealData.ParaValue != "")
                                                    {
                                                        formula = formula.Replace(device.IOParas[i].IO_NAME, device.IOParas[i].IORealData.ParaValue);
                                                    }
                                                }
                                            }
                                            if (formula != "")
                                            {
                                                //解析数学公式
                                                device.IOParas[i].IORealData.ParaValue = AnalyzeCalculate.Calculate(device.IOParas[i].IO_FORMULA);
                                                double d = 0;
                                                if (double.TryParse(device.IOParas[i].IORealData.ParaValue, out d))
                                                {
                                                    device.IOParas[i].IORealData.DataType = typeof(double);
                                                }
                                                else
                                                {
                                                    device.IOParas[i].IORealData.DataType = typeof(string);
                                                }
                                            }

                                            else
                                            {
                                                device.IOParas[i].IORealData.ParaValue    = "-9999";
                                                device.IOParas[i].IORealData.QualityStamp = QualityStamp.BAD;
                                            }
                                        }
                                        catch
                                        {
                                            device.IOParas[i].IORealData.QualityStamp = QualityStamp.BAD;
                                            device.IOParas[i].IORealData.Date         = DateTime.Now;
                                            device.IOParas[i].IORealData.ParaName     = device.IOParas[i].IO_NAME;
                                        }
                                    }
                                    else
                                    {
                                        device.IOParas[i].IORealData = null;
                                    }
                                }
                            }
                            catch
                            {
                            }
                            #endregion
                            #region 进行量程转换
                            try
                            {
                                if (device.IOParas[i].IO_POINTTYPE == "模拟量")
                                {
                                    if (device.IOParas[i].IORealData != null && device.IOParas[i].IO_ENABLERANGECONVERSION == 1 && device.IOParas[i].IORealData.QualityStamp == QualityStamp.GOOD)
                                    {
                                        if (device.IOParas[i].IORealData.ParaValue != "" && device.IOParas[i].IORealData.ParaValue != "-9999")
                                        {
                                            string value = ConvertParaTypeValue(device.IOParas[i].GetParaValueType(), device.IOParas[i].IORealData.ParaValue, double.Parse(device.IOParas[i].IO_RANGEMAX), double.Parse(device.IOParas[i].IO_RANGEMIN), double.Parse(device.IOParas[i].IO_MAXVALUE), double.Parse(device.IOParas[i].IO_MINVALUE));
                                            device.IOParas[i].IORealData.ParaValue = value;
                                        }
                                    }
                                }
                            }
                            catch
                            {
                            }

                            #endregion

                            #region 常量值
                            try
                            {
                                if (device.IOParas[i].IO_POINTTYPE == "常量值")
                                {
                                    device.IOParas[i].IORealData = new IOData()
                                    {
                                        CommunicationID = device.IOParas[i].IO_COMM_ID,
                                        DataType        = typeof(string),
                                        Date            = device.GetedValueDate,
                                        ParaName        = device.IOParas[i].IO_NAME,
                                        ParaString      = device.IOParas[i].IO_PARASTRING,
                                        ParaValue       = device.IOParas[i].IO_INITALVALUE,
                                        QualityStamp    = QualityStamp.GOOD,
                                        ServerID        = device.IOParas[i].IO_SERVER_ID
                                    };
                                }
                            }
                            catch
                            {
                            }

                            #endregion
                        }
                        #endregion
                        #region 将解析后的数据上传到数据中心服务器上
                        IO_DEVICE newDevice = device.Copy();
                        try
                        {
                            //将接收到的数据保存到实时缓存,主要用于批量上传,提高传输效率
                            receiveRealCache.Push(new ReceiveCacheObject()
                            {
                                DataString = RealDataDBUtility.GetRealDataCacheString(device)
                            });
                            MonitorFormManager.ShowMonitorUploadListView(server, comm, device, "上传成功");
                        }
                        catch (Exception emx)
                        {
                            ThrowExceptionToMain(emx);
                        }
                        //在事件接收窗体中显示接收的采集数据
                        if (OnMonitorReceive != null)
                        {
                            OnMonitorReceive(server, comm, newDevice, receivedatas);
                        }

                        #endregion
                        #region 计算报警并上传
                        try
                        {
                            Task.Run(() =>
                            {
                                List <IO_PARAALARM> res = new List <IO_PARAALARM>();
                                //将接收到的数据保存到实时缓存,主要用于批量上传,提高传输效率
                                receiveRealCache.Push(new AlarmCacheObject()
                                {
                                    DataString = RealDataDBUtility.GetAlarmCacheString(device, out res)
                                });
                                for (int i = 0; i < res.Count; i++)
                                {
                                    MonitorFormManager.MonitorIODataAlarmShowView(server, comm, device, res[i], "上传成功");
                                }
                                res.Clear();
                                res = null;
                            });
                        }
                        catch (Exception emx)
                        {
                            ThrowExceptionToMain(emx);
                        }
                        #endregion
                    }
                }
                catch (Exception emx)
                {
                    ThrowExceptionToMain(emx);
                }
                if (receivedatas != null && receivedatas.Length > 0)
                {
                    AddLogToMainLog(device.IO_DEVICE_NAME + "接收到数据 DATA=" + CVT.ByteToHexStr(receivedatas));
                }
            });
        }