コード例 #1
0
        //加载端口
        private static WrapperBll PortSetting(Model_Data.DeviceModel obj)
        {
            WrapperBll PS = new WrapperBll();

            PS.Port = obj.Port;
            switch (obj.Port.PortType)
            {
            case Protocol.Modbus_SerialPort:
                PS.PortBll = AllPortBll.CreateInstance(Protocol.Modbus_SerialPort);
                PS.PortBll.SetParaMeter(CreatCommSerialEntity(obj));
                break;

            case Protocol.Modbus_TCPIPPort:
                PS.PortBll = AllPortBll.CreateInstance(Protocol.Modbus_TCPIPPort);
                PS.PortBll.SetParaMeter(CreatCommTCPEntity(obj));
                break;

            case Protocol.Modbus_USBPort:
                PS.PortBll = AllPortBll.CreateInstance(Protocol.Modbus_USBPort);
                break;

            default:
                return(null);
            }
            //Device
            DeviceBll deviceBLL = new DeviceBll();

            deviceBLL.Device.DeviceName                 = obj.DeviceName;
            deviceBLL.Device.UnitId                     = obj.UnitId;
            deviceBLL.Device.write2DBInterval           = obj.WriteDBTime;
            deviceBLL.Device.AnalogSignalValueTableName = obj.TableName;
            deviceBLL.Device.UIpath                     = obj.UIPath;
            //
            foreach (AnalogModel AnalogRow in obj.Analog)
            {
                AnalogBll analogSignalBLL = new AnalogBll();
                analogSignalBLL.AnalogInfo = AnalogRow;
                deviceBLL.AnalogList.Add(analogSignalBLL);
            }
            //
            foreach (DigitalModel DigitalRow in obj.Digital)
            {
                DigitalBll digitalSignalBLL = new DigitalBll();
                digitalSignalBLL.DigitalInfo = DigitalRow;
                deviceBLL.DigitalList.Add(digitalSignalBLL);
            }
            deviceBLL.SetSignalAlarmDelegate();
            if (deviceBLL != null)
            {
                PS.DeviceList.Add(deviceBLL);
            }
            PS.SetDeviceDelegate();
            return(PS);
        }
コード例 #2
0
ファイル: CommandCreat.cs プロジェクト: wpmyj/OF2.0
        //创建数字量查询命令列表
        private static List <CommandClass> CreatDigitalCommandList(Protocol PortType, byte UnitId, List <DigitalBll> DigitalList)
        {
            List <CommandClass> DigitalCommandList = new List <CommandClass>();
            CommandClass        DigitalCommand;

            if (DigitalList.Count < 1)
            {
                return(DigitalCommandList);
            }

            DigitalBll tempdigital = DigitalList[DigitalList.Count - 1];

            if (tempdigital.DigitalInfo.ISContinuous)
            {
                tempdigital.DigitalInfo.ISContinuous = false;
            }

            byte  CommandCode = 2;
            short StartAdr    = 0;
            short Datalength  = 0;
            short RegisterLen = 0;
            bool  IsStartAdr  = true;//前一数字量与当前数字量是否连续的标志

            foreach (DigitalBll digital in DigitalList)
            {
                RegisterLen++;
                if (IsStartAdr)
                {
                    CommandCode = digital.DigitalInfo.RegisterType;
                    StartAdr    = digital.DigitalInfo.DataStartAddress;
                }
                IsStartAdr = !digital.DigitalInfo.ISContinuous;

                if (!digital.DigitalInfo.ISContinuous)
                {
                    DigitalCommand         = new CommandClass();
                    Datalength             = Convert.ToInt16(RegisterLen % 8 > 0 ? RegisterLen / 8 + 1 : RegisterLen / 8);
                    Datalength            += 3;
                    DigitalCommand.Command = CreatOneModbusReadCommand(PortType, UnitId, CommandCode, StartAdr, RegisterLen, ref Datalength);
                    DigitalCommand.RecLen  = Datalength;
                    DigitalCommandList.Add(DigitalCommand);
                    RegisterLen = 0;
                }
            }


            return(DigitalCommandList);
        }