我有这个 C# 代码,它正在产生一个错误Console.WriteLine($"Register {startAddress + i}={registers[i]}");
。我试过 double ))
,并将它放在声明中的任何地方。我根本看不到错误在哪里。我可能错过了一些简单的东西,我只是没有看到它。
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]}");
}
}
}
}
}