示例#1
0
        public override async Task <bool> SetDatasAsync(byte belongAddress, byte materAddress, string startAddress, object[] setContents)
        {
            try
            {
                var writeRequestSiemensInputStruct  = new WriteRequestSiemensInputStruct(0xd3c8, startAddress, setContents, AddressTranslator);
                var writeRequestSiemensOutputStruct =
                    await
                    Wrapper.SendReceiveAsync(Wrapper[typeof(WriteRequestSiemensProtocal)],
                                             writeRequestSiemensInputStruct) as WriteRequestSiemensOutputStruct;

                return(writeRequestSiemensOutputStruct?.AccessResult == SiemensAccessResult.NoError);
            }
            catch (Exception)
            {
                return(false);
            }
        }
示例#2
0
        /// <summary>
        ///     写数据
        /// </summary>
        /// <param name="startAddress">开始地址</param>
        /// <param name="setContents">需要写入的数据</param>
        /// <returns>写入是否成功</returns>
        public override async Task <bool> SetDatasAsync(string startAddress, object[] setContents)
        {
            try
            {
                var writeRequestSiemensInputStruct = new WriteRequestSiemensInputStruct(SlaveAddress, MasterAddress,
                                                                                        0xd3c8, startAddress, setContents, AddressTranslator);
                var writeRequestSiemensOutputStruct =
                    await
                    Wrapper.SendReceiveAsync <WriteRequestSiemensOutputStruct>(
                        Wrapper[typeof(WriteRequestSiemensProtocal)],
                        writeRequestSiemensInputStruct);

                return(writeRequestSiemensOutputStruct?.AccessResult == SiemensAccessResult.NoError);
            }
            catch (Exception e)
            {
                //Log.Error(e, $"ModbusUtility -> SetDatas: {ConnectionString} error");
                return(false);
            }
        }