Example #1
0
        public override async Task <byte[]> GetDatasAsync(byte belongAddress, byte materAddress, string startAddress, int getByteCount)
        {
            try
            {
                var readRequestSiemensInputStruct  = new ReadRequestSiemensInputStruct(0xd3c7, SiemensTypeCode.Byte, startAddress, (ushort)getByteCount, AddressTranslator);
                var readRequestSiemensOutputStruct =
                    await
                    Wrapper.SendReceiveAsync(Wrapper[typeof(ReadRequestSiemensProtocal)],
                                             readRequestSiemensInputStruct) as ReadRequestSiemensOutputStruct;

                return(readRequestSiemensOutputStruct?.GetValue);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Example #2
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 readRequestSiemensInputStruct = new ReadRequestSiemensInputStruct(SlaveAddress, MasterAddress,
                                                                                      0xd3c7, SiemensTypeCode.Byte, startAddress, (ushort)getByteCount, AddressTranslator);
                var readRequestSiemensOutputStruct =
                    await
                    Wrapper.SendReceiveAsync <ReadRequestSiemensOutputStruct>(
                        Wrapper[typeof(ReadRequestSiemensProtocal)],
                        readRequestSiemensInputStruct);

                return(readRequestSiemensOutputStruct?.GetValue);
            }
            catch (Exception e)
            {
                //Log.Error(e, $"SiemensUtility -> GetDatas: {ConnectionString} error");
                return(null);
            }
        }