protected override object[] wsmbtReadMethod(ushort startAdd, ushort count, WSMBTControl wsmbtControl)
        {
            short[] registers = new short[26];
            wsmbtControl.ReadInputRegisters(1, startAdd, count, registers);

            return(Array.ConvertAll(registers, item => (object)item));
        }
        protected override object[] wsmbtReadMethod(ushort startAdd, ushort count, WSMBTControl wsmbtControl)
        {
            bool[] coils = new bool[25];
            wsmbtControl.ReadCoils(1, startAdd, count, coils);

            return(Array.ConvertAll(coils, item => (object)item));
        }
Ejemplo n.º 3
0
        protected override object[] wsmbtReadMethod(ushort startAdd, ushort count, WSMBTControl wsmbtControl)
        {
            bool[] discreteInputs = new bool[25];
            wsmbtControl.ReadDiscreteInputs(1, startAdd, count, discreteInputs);

            return(Array.ConvertAll(discreteInputs, item => (object)item));
        }
        public override void readData(WSMBTControl wsmbtControl)
        {
            ushort startAddress = (ushort)RegisterValueList.Select(item => item.Address).Min();
            ushort endAddress   = (ushort)RegisterValueList.Select(item => item.Address).Max();

            List <object> valueList = base.readRegisterRange(startAddress, endAddress, wsmbtControl).ToList();

            for (int i = 0; i < RegisterValueList.Count; i++)
            {
                ((RegisterValue <short>)RegisterValueList[i]).Value = Convert.ToInt16(valueList[i]);
            }
        }
        public override void readData(WSMBTControl wsmbtControl)
        {
            ushort        startAddress = (ushort)RegisterValueList.Select(item => item.Address).Min();
            ushort        endAddress   = (ushort)(startAddress + RegisterValueList.Count * 2);
            List <object> valueList    = base.readRegisterRange(startAddress, endAddress, wsmbtControl).ToList();

            for (int i = 0; i < RegisterValueList.Count * 2 - 2; i = i + 2)
            {
                float val = wsmbtControl.RegistersToFloat(Convert.ToInt16(valueList[i + 1]), Convert.ToInt16(valueList[i]));

                ((RegisterValue <float>)RegisterValueList[i / 2]).Value = val;
            }
        }
Ejemplo n.º 6
0
        void initModbusClient()
        {
            wsmbtControl = new WSMBTControl();

            wsmbtControl.Mode            = Mode.TCP_IP;
            wsmbtControl.ResponseTimeout = 1000;
            wsmbtControl.ConnectTimeout  = 1000;
            Result result = wsmbtControl.Connect(_registerGroup.IpAddress, _registerGroup.Port);

            if (result != Result.SUCCESS)
            {
                _comStatusError = "Not able to connect to Device:" + _registerGroup.IpAddress;
            }
            else if (result == Result.SUCCESS)
            {
                _comStatusError = "Connected to Device:" + _registerGroup.IpAddress;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 端口连接函数
        /// </summary>
        /// <param name="sName"></param>
        /// <param name="nPort"></param>
        /// <returns></returns>
        public bool MB_Connect(string sName, int nPort)
        {
            if (m_nProcotol == 2)
            {
                tcp_svr = new WSMBTControl();
                tcp_svr.LicenseKey("2222222222222222222222222AAF2");
                return(WSMBT.Result.SUCCESS == tcp_svr.Connect(sName, nPort));
            }

            ser_svr = new WSMBSControl();
            ser_svr.LicenseKey("2222222222222222222222222F3AA");
            ser_svr.PortName = sName;
            ser_svr.Parity   = Parity.None;
            ser_svr.DataBits = 8;
            ser_svr.StopBits = 1;
            ser_svr.BaudRate = nPort;
            bTaskStatus      = false;
            return(WSMBS.Result.SUCCESS == ser_svr.Open());
        }
        protected List <object> readRegisterRange(ushort startAddress, ushort endAddress, WSMBTControl wsmbtControl)
        {
            ushort maxRegToRead = 26;

            ushort tempStartAddress = startAddress;

            List <object> resultList = new List <object>();

            while ((endAddress - tempStartAddress) > 0)
            {
                resultList.AddRange(wsmbtReadMethod(tempStartAddress, maxRegToRead, wsmbtControl));

                tempStartAddress = (ushort)(tempStartAddress + maxRegToRead);
            }

            return(resultList);
        }
 protected abstract object[] wsmbtReadMethod(ushort startAdd, ushort count, WSMBTControl wsmbtControl);
 public abstract void readData(WSMBTControl wsmbtControl);