I am currently in the process of writing a c# program in VS where it reads the holding registers of a Panasonic KW9M-A Power Meter using Modbus-RTU. The holding register i'm trying to read is: 00A4H to 00A5H; Unsigned 32bit
Note: I wrote this in Console app. I used NModbus4 by Maxwe11 Idk what i'm missing since i'm a beginner in programming. Can someone please assist me? Thank you in advance :)
Here is what i have so far:
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Console_ye
{
class Program
{
public static void Main(string[] args)
{
SerialPort serialPort = new SerialPort("COM13", 115200, Parity.Odd, 8, StopBits.One);
serialPort.Open();
Console.WriteLine("This is the beginning: ");
string hex_add = "0x00A4";
ushort dec_add = Convert.ToUInt16(hex_add, 16);
Console.WriteLine("Value of hex: " + hex_add);
Console.WriteLine("Value of ushort: " + dec_add);
byte slaveId = 1;
ushort startAddress = dec_add;
ushort numberOfPoints = 8;
IModbusMaster masterRTU = ModbusSerialMaster.CreateRtu (serialPort);
ushort[] ushortArray = masterRTU.ReadHoldingRegisters(slaveId, startAddress, numberOfPoints);
Console.WriteLine("Here " + ushortArray[0]);
foreach (ushort item in ushortArray)
{
Console.WriteLine(string.Join ("\n", item));
}
}
}
}