Пример #1
0
        public void SetDataPointRealValueByFunNun03Test()
        {
            ModbusRTUServer modbusRTUServer = new ModbusRTUServer();

            modbusRTUServer.InitializeFromConfigFile(modbusConfigFile, serialPortConfigFile);
            List <DataPoint> dataPointsWhoseRealTimeDataChanged = new List <DataPoint>();

            modbusRTUServer.SerialPort.OnCurrentRequestDataChanged += new EventHandler <RequstDataEventArgs>(SerialPort_OnRequestDataChanged);
            modbusRTUServer.SerialPort.OnCurrentReceiveDataChanged += new EventHandler <ReceiveDataEventArgs>(SerialPort_OnReceiveDataChanged);

            dataAnalyzeMode = modbusRTUServer.DataAnalyzeMode;
            allDataPoints   = modbusRTUServer.AllDataPoints;

            List <DataPoint> dataPoints = new List <DataPoint>();

            dataPoints.Add(new DataPoint()
            {
                DeviceAddress        = 1,
                StartRegisterAddress = 83,
                DataPointType        = DataPointType.WriteAndReadByFunNum03,
                DataPointDataType    = DataPointDataType.F32,
                RealTimeValue        = -1,
            });

            List <List <byte> > registerCommandBytes = ModbusRTU.CreateReadRegisterCommands(dataPoints);

            if (modbusRTUServer.SerialPort.TryOpenSerialPort())
            {
                foreach (var writeBytes in registerCommandBytes)
                {
                    modbusRTUServer.SerialPort.WriteSerialPort(writeBytes.ToArray());
                }
            }
        }
Пример #2
0
        private List <ReadRegisterCommand> GetReadRegisterCommands(List <DataPoint> dataPoints)
        {
            List <ReadRegisterCommand> readRegisterCommands = new List <ReadRegisterCommand>();

            List <List <byte> > requestBytes = ModbusRTU.CreateReadRegisterCommands(dataPoints);

            foreach (var requestByte in requestBytes)
            {
                var readRegisterCommand = new ReadRegisterCommand();
                readRegisterCommand.ReadCommand = requestByte;

                readRegisterCommands.Add(readRegisterCommand);
            }

            return(readRegisterCommands);
        }