Hello everyone
I'm trying to use EasyModbus .NET as an RTU client but I really can't figure out a couple of things:
Loading the library works fine: (Using Powershell but should not matter much) Add-Type -Path '.\EasyModbus.dll'
as does creating the object. According to http://easymodbustcp.net/modbusclient-methods
i should be able to create an RTU client using: $modbusclient = [EasyModbus.ModbusClient]::new("COM3")
but this does not work, as it always returns a TCP client:
Connected : False
IPAddress : 127.0.0.1
Port : 502
UDPFlag : False
UnitIdentifier : 0
Baudrate : 9600
Parity : Even
StopBits : One
ConnectionTimeout : 500
btw this: $modbusclient = [EasyModbus.ModbusClient]::new()
or this.. $modbusclient = [EasyModbus.ModbusClient]::new("127.0.0.1",502) do work as intended, but even if I can set the properties of Baudrate, the connection remains TCP.
I'm also able to set the protocol this way, $modbusproto = [EasyModbus.ModbusProtocol+ProtocolType]::ModbusRTU
but I don't understand where to tell the client to use this protocol.
also I can't figure out the difference between [EasyModbus.ModbusProtocol+ProtocolType] and [EasyModbus.ModbusProtocol]
Can someone please shed some light? Thanks!
Thanks!
Last edit: Ilgrank 2016-05-01
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
to use Modbus RTU, it is important to create the Client Object using the constructor "ModbusClient(string ipAddress, int port)". Although all properties for Modbus TCP are still present, Modbus RTU is used, ad only properties for Modbus RTU connection are relevant.
Constructors "ModbusClient( string serialPort)" and ModbusClient( ) are using Modbus TCP
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks Stefan! It was it!
Now I can read correctly!
About the values returned.. I expected two floats, but I received a two INTs(?) array which have different values than expected.
Again, many thanks for your help
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
..please, I'm just asking for a little bit of support.
If there was some RTU example around, I'd follow it, but RTU seem to be not too well documented..
Thanks!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Do you use the latest Version 2.1? Baucause in Previous Versions, there was a Problem changing the Baurate.
Modbus RTU uses even parity and 9600 baud by default.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
this does NOT mean they're wrong.. just maybe they need some sort of.. translation?
I expected something like
4362 09E9
in return (it is a live voltage reading, and should output two 16 bit register representing a float from 220Volts to 240Volts.. in the above example (4362 09E9) -> 226,03871V
Many thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Stefan was so kind and he spent a good part of the morning helping me find out what I was doing wrong.
If someone is having my same problem:
1st: you need to set the UnitIdentifier!
I had erroneously tought the default was 1, but it is not.
2nd. If you have, like me, a device with no parity, you'll have to step back 1 unit.. ie: if you need to read input register 30001, you'll need to enter 0 (ZERO)
if you need to read 30029,you'll need to enter 28.
Finally, here's the working code for the EASTRON SDM220 energy meter:
Hello everyone
I'm trying to use EasyModbus .NET as an RTU client but I really can't figure out a couple of things:
Loading the library works fine: (Using Powershell but should not matter much)
Add-Type -Path '.\EasyModbus.dll'
as does creating the object. According to
http://easymodbustcp.net/modbusclient-methods
i should be able to create an RTU client using:
$modbusclient = [EasyModbus.ModbusClient]::new("COM3")
but this does not work, as it always returns a TCP client:
btw this:
$modbusclient = [EasyModbus.ModbusClient]::new()
or this..
$modbusclient = [EasyModbus.ModbusClient]::new("127.0.0.1",502)
do work as intended, but even if I can set the properties of Baudrate, the connection remains TCP.
I'm also able to set the protocol this way,
$modbusproto = [EasyModbus.ModbusProtocol+ProtocolType]::ModbusRTU
but I don't understand where to tell the client to use this protocol.
also I can't figure out the difference between
[EasyModbus.ModbusProtocol+ProtocolType] and [EasyModbus.ModbusProtocol]
Can someone please shed some light? Thanks!
Thanks!
Last edit: Ilgrank 2016-05-01
Hello,
to use Modbus RTU, it is important to create the Client Object using the constructor "ModbusClient(string ipAddress, int port)". Although all properties for Modbus TCP are still present, Modbus RTU is used, ad only properties for Modbus RTU connection are relevant.
Constructors "ModbusClient( string serialPort)" and ModbusClient( ) are using Modbus TCP
Sorry but I don't get you.
If I initialize the client this way:
I get a "Connection Error", even tho COM3 is readily accessible.
I've downloaded the only .NET module available on the download page.. is there a separate RTU module elsewhere?
Thanks!
Last edit: Ilgrank 2016-05-02
Call "Connect()" Method to open the serial port.
Thanks Stefan! It was it!
Now I can read correctly!
About the values returned.. I expected two floats, but I received a two INTs(?) array which have different values than expected.
Again, many thanks for your help
To be more specific, the read should return two 16 bits registers, using other tools for example,here I have

bytes: 4362 09E9 -> 226,03871
but issuing
I have in return:
I'm surely missing something here.. but I'm close :)
thanks!
Last edit: Ilgrank 2016-05-03
..please, I'm just asking for a little bit of support.
If there was some RTU example around, I'd follow it, but RTU seem to be not too well documented..
Thanks!
Sorry for late anwer.
Do you use the latest Version 2.1? Baucause in Previous Versions, there was a Problem changing the Baurate.
Modbus RTU uses even parity and 9600 baud by default.
Hi Stefan
Sorry for the double post, I had fear of having been unnoticed :)
Thanks for your reply
yes, I'm on 2.1 and as per my post of 2n of May, I do initialize the client in this way:
but alas, I do get that 'strange' values (other sw tools are reading correctly, so I know my Modbus device is answering with the right data)
Many thanks
Last edit: Ilgrank 2016-05-19
Which tool do you use as Slave device? Is it available for free?
Hi Stefan
It's a hardware (ie: non software) device.
It is a energy meter.
But please tell me any way I can be useful in testing it
thanks!
Hello,
just released a Version with some Bugfixes. Could you please try?
Hi Stefan
Thanks for the update
Installed the new (2.2) library, but I still get values I don't understand:
this does NOT mean they're wrong.. just maybe they need some sort of.. translation?
I expected something like
4362 09E9
in return (it is a live voltage reading, and should output two 16 bit register representing a float from 220Volts to 240Volts.. in the above example (4362 09E9) -> 226,03871V
Many thanks
Hi,
is there any possibility to have a look via teamviewer or something similar?
Thanks for you offer Stefan, I've sent you a private message
thanks!
Stefan was so kind and he spent a good part of the morning helping me find out what I was doing wrong.
If someone is having my same problem:
1st: you need to set the UnitIdentifier!
I had erroneously tought the default was 1, but it is not.
2nd. If you have, like me, a device with no parity, you'll have to step back 1 unit.. ie: if you need to read input register 30001, you'll need to enter 0 (ZERO)
if you need to read 30029,you'll need to enter 28.
Finally, here's the working code for the EASTRON SDM220 energy meter:
Thanks again Stefan!