private List <ReadRegisterCommand> GetReadRegisterCommands(List <DataPoint> dataPoints) { List <ReadRegisterCommand> readRegisterCommands = new List <ReadRegisterCommand>(); List <List <byte> > requestBytes = ModbusTCP.CreateReadRegisterCommands(dataPoints); foreach (var requestByte in requestBytes) { var readRegisterCommand = new ReadRegisterCommand(); readRegisterCommand.ReadCommand = requestByte; readRegisterCommands.Add(readRegisterCommand); } return(readRegisterCommands); }
public void SetDataPointRealValueByFunNun03Test() { ModbusTCPServer modbusTCPServer = new ModbusTCPServer(); modbusTCPServer.InitializeFromConfigFile(modbusConfigFile); foreach (var modbusUint in modbusTCPServer.ModbusUnits) { List <DataPoint> dataPointsWhoseRealTimeDataChanged = new List <DataPoint>(); 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 = ModbusTCP.CreateReadRegisterCommands(dataPoints); if (modbusUint.Connector.Connect()) { foreach (var writeBytes in registerCommandBytes) { var recvBytes = modbusUint.Connector.Send(writeBytes); if (recvBytes != null) { AnalyzeRecivedDataReponse reponse = ModbusTCP.AnalyzeRecivedDataStatic(modbusUint.DataAnalyzeMode, writeBytes, recvBytes); if (reponse.ModbusReponseSuccess && reponse.AnalyzeRecivedDataSuccess) { dataPointsWhoseRealTimeDataChanged = ModbusTCP.SetDataPointValueFromRegisterValue(reponse.Registers, dataPoints); } } } } } }