Beispiel #1
0
        public void WriteFloatTagValue(FloatTag tag)
        {
            int addressindex = 0;

            foreach (var item in tag.GetAddresses())
            {
                master.WriteSingleRegisterAsync((ushort)(item - 1), tag.GetWriteValue()[addressindex]);
                addressindex++;
                if (addressindex == 2)
                {
                    break;
                }
            }
        }
 public async Task <bool> WriteSingleRegisterAsync(int address, ushort value)
 {
     if (this.CheckConnection())
     {
         try {
             using TcpClient client = new TcpClient(this.IpAddress, this.Port);
             ModbusIpMaster master = ModbusIpMaster.CreateIp(client);
             if (this.SlaveAddress != 0)
             {
                 await master.WriteSingleRegisterAsync(this.SlaveAddress, (ushort)address, value);
             }
             else
             {
                 await master.WriteSingleRegisterAsync((ushort)address, value);
             }
             client.Close();
             master.Dispose();
             return(true);
         } catch {
             return(false);
         }
     }
     return(false);
 }
Beispiel #3
0
 public Task WriteSpeedInletPump(short speed)
 {
     return(Task.Run(() => {
         ushort Speed = Convert.ToUInt16(speed);
         _master.WriteSingleRegisterAsync(1, Speed);
     }));
 }