Esempio n. 1
0
        /// <summary>
        ///     读数据
        /// </summary>
        /// <param name="startAddress">起始地址</param>
        /// <param name="getByteCount">获取字节个数</param>
        /// <returns>获取的结果</returns>
        public override async Task <byte[]> GetDatasAsync(string startAddress, int getByteCount)
        {
            try
            {
                var inputStruct = new ReadDataModbusInputStruct(SlaveAddress, startAddress,
                                                                (ushort)getByteCount, AddressTranslator);
                var outputStruct = await
                                   Wrapper.SendReceiveAsync <ReadDataModbusOutputStruct>(Wrapper[typeof(ReadDataModbusProtocal)], inputStruct);

                return(outputStruct?.DataValue);
            }
            catch
            {
                return(null);
            }
        }
Esempio n. 2
0
        public override async Task <byte[]> GetDatasAsync(byte belongAddress, byte masterAddress, string startAddress, int getByteCount)
        {
            try
            {
                var inputStruct = new ReadDataModbusInputStruct(belongAddress, startAddress,
                                                                getByteCount % 2 == 0 ? (ushort)(getByteCount / 2) : (ushort)(getByteCount / 2 + 1), AddressTranslator);
                var outputStruct = await
                                   Wrapper.SendReceiveAsync(Wrapper[typeof(ReadDataModbusProtocal)], inputStruct) as
                                   ReadDataModbusOutputStruct;

                return(outputStruct?.DataValue);
            }
            catch
            {
                return(null);
            }
        }
Esempio n. 3
0
        /// <summary>
        ///     读数据
        /// </summary>
        /// <param name="startAddress">起始地址</param>
        /// <param name="getByteCount">获取字节个数</param>
        /// <returns>获取的结果</returns>
        public override async Task <byte[]> GetDatasAsync(string startAddress, int getByteCount)
        {
            try
            {
                var inputStruct = new ReadDataModbusInputStruct(SlaveAddress, startAddress,
                                                                (ushort)getByteCount, AddressTranslator);
                var outputStruct = await
                                   ProtocolWrapper.SendReceiveAsync <ReadDataModbusOutputStruct>(ProtocolWrapper[typeof(ReadDataModbusProtocal)],
                                                                                                 inputStruct);

                return(outputStruct?.DataValue);
            }
            catch (Exception e)
            {
                Log.Error(e, $"ModbusUtility -> GetDatas: {ConnectionString} error");
                return(null);
            }
        }