Пример #1
0
        /// <summary>
        /// 设置DataPiont的值
        /// </summary>
        /// <param name="setDpDto"></param>
        public void AddDataPointToSetValue(SetDataPointValue setDpDto)
        {
            var toFindModbusUnit = FindModbusUnit(this.ModbusUnits, setDpDto.DataPointNumber);

            if (toFindModbusUnit != null)
            {
                List <DataPoint> toWriteDataPoints = new List <DataPoint>();
                var toWriteDataPoint = toFindModbusUnit.AllDataPoints.FirstOrDefault(p => p.Number == setDpDto.DataPointNumber);
                if (toWriteDataPoint != null)
                {
                    var copyDp = toWriteDataPoint.CopyNew();
                    copyDp.ValueToSet = setDpDto.ValueToSet;
                    toWriteDataPoints.Add(copyDp);
                }

                List <List <byte> > requestBytes = ModbusTCP.CreateWriteRegisterCommands(toFindModbusUnit.DataAnalyzeMode, toWriteDataPoints);
                foreach (var requestByte in requestBytes)
                {
                    lock (writeMobusThreadLoker)
                    {
                        WriteRegisterCommand writeRegisterCommand = new WriteRegisterCommand();
                        writeRegisterCommand.WriteCommand = requestByte;
                        toFindModbusUnit.ToWriteRegisterCommands.Enqueue(writeRegisterCommand);
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 设置DataPiont的值
        /// </summary>
        /// <param name="setDpDto"></param>
        public void SetDataPointValue(SetDataPointValueDto setDpDto)
        {
            SetDataPointValue setDataPointValue = new SetDataPointValue()
            {
                DataPointNumber = setDpDto.DataPointNumber,
                ValueToSet      = setDpDto.ValueToSet,
            };

            this.ModbusTCPServer.AddDataPointToSetValue(setDataPointValue);
        }