I have this C# Code, and it is producing an error on the Console.WriteLine($"Register {startAddress + i}={registers[i]}");
line. I have tried double ))
, and placed it everywhere in the statement. I simply cannot see where the error is. I am probably missing something simple and I'm just not seeing it.
namespace NModbus.TestDriver
{
using System;
using System.Net.Sockets;
using Modbus.Device;
using NModbus;
class Program
{
static void Main(string[] args)
{
using (TcpClient client = new TcpClient("192.168.111.169", 502))
{
client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
var master = ModbusIpMaster.CreateIp(client);
// read five input values
byte slaveId = 1;
ushort startAddress = 1;
ushort numRegisters = 5;
// read five registers
ushort[] registers = master.ReadHoldingRegisters(slaveId, startAddress, numRegisters);
for (int i = 0; i < numRegisters; i++)
{
Console.WriteLine($"Register {startAddress + i}={registers[i]}");
}
}
}
}
}
Try defining the string before doing
Console.WriteLine
-- so the for loop is like this