Ejemplo n.º 1
0
        /// <summary>
        /// 生成批量写入寄存器的报文信息
        /// </summary>
        /// <param name="address">地址</param>
        /// <param name="values">实际值</param>
        /// <returns>包含结果对象的报文</returns>
        public OperateResult <byte[]> BuildWriteRegisterCommand(string address, byte[] values)
        {
            OperateResult <ModbusAddress> analysis = ModbusInfo.AnalysisReadAddress(address, isAddressStartWithZero);

            if (!analysis.IsSuccess)
            {
                return(OperateResult.CreateFailedResult <byte[]>(analysis));
            }

            // 生成最终rtu指令
            byte[] buffer = ModbusInfo.PackCommandToRtu(analysis.Content.CreateWriteRegister(station, values));
            return(OperateResult.CreateSuccessResult(buffer));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 生成一个读取离散信息的指令头
        /// </summary>
        /// <param name="address">地址</param>
        /// <param name="length">长度</param>
        /// <returns>携带有命令字节</returns>
        public OperateResult <byte[]> BuildReadDiscreteCommand(string address, ushort length)
        {
            OperateResult <ModbusAddress> analysis = ModbusInfo.AnalysisReadAddress(address, isAddressStartWithZero);

            if (!analysis.IsSuccess)
            {
                return(OperateResult.CreateFailedResult <byte[]>(analysis));
            }

            // 生成最终tcp指令
            byte[] buffer = ModbusInfo.PackCommandToRtu(analysis.Content.CreateReadDiscrete(station, length));
            return(OperateResult.CreateSuccessResult(buffer));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 生成一个读取寄存器的指令头
 /// </summary>
 /// <param name="address">地址</param>
 /// <param name="length">长度</param>
 /// <returns>携带有命令字节</returns>
 private OperateResult <byte[]> BuildReadRegisterCommand(ModbusAddress address, ushort length)
 {
     // 生成最终rtu指令
     byte[] buffer = ModbusInfo.PackCommandToRtu(address.CreateReadRegister(station, length));
     return(OperateResult.CreateSuccessResult(buffer));
 }