I have the following Problem using Modbus via Codesys:
I'm trying to implement a Modbus Device into my codesys project. The device is a Router from Teltonika (RUT956) and it can communicate via Modbus. Currently I'm trying to implement it into my codesys prject as a slave and I'm using my windows computer as master. As it is not a codesys device (the codesys application is not uploaded to device as it has its own software) I'm having problems requesting and reading registers from the router. I've set up my windows computer as Master and implemented the router as slave. When I go online on my master device it sais that it has established a connection to the slave (router)(So I'm thinking this could work as there is a connection?). The goal is to read the GPS (latitude and longitude) data and on the homepage of teltonika you can find the register address and number of registers (adress 143 for latitude and 145 for longitude; both have a number of two registers).
I've found tutorials how to read specific registers via their register address with other modbus programs (like modbus-cli), but as my entire project is established in codesys I was hoping to read these specific registers via codesys so that I can show the GPS data on my dashboard.
I've tried establishing slave channels but that hasn't been working. I tried read input register channels of the length 4 but it's not possible to define specific register addresses to read via codesys so that didn't work (I jsut get a slaves device failure) and I've also tried establishing 516 (total number of registers the router sends I think?) read inputregister channels but that has the samle failure...
So i guess the problem I'm having is establishing slave channels to read these specific registers. Does anyone know how to tackle this problem and has maybe had the same problem? Or maybe someone knows a workaround? I'm quite new to codesys so maybe I'm also lacking expertise...
π
1
Last edit: eoahe 2025-03-01
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
According to the documentation: https://wiki.teltonika-networks.com/view/RUT956_Modbus
You need to create a Channel to read 2 registers from address 143 to get the lattitude.
It doesn't specify if you need to read it as a Holding Register or as an Input Register. You could try both.
So in the Teltonika router, you need to enable it as being a Modbus Server.
Then in CODESYS add an Ethernet Adapter, then a Modbus Client (Master) and to the Client (Master) add the Modbus Server (Slave).
Set the IP address and add the Channel.
The please consider that CODESYS doesn't update any variables when they are not used in the application. In the I/O mapping tab of your I/O configuration, you can set the "Always update" to enabled.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Might be a good idea first to try out the connection and the device with some handy software, like Modbus Poll.
There you can see better, what's really going on...
- Is it really connected?
- What error code does it return?
- Can it read from the register address?
- Maybe try Input registers and Holding Registers - can make a difference
- Sometimes register addresses are messed up: shifted +-1 (mixing of 2 standards)
- Sometimes register addresses start with offset 30000, 40000 ...
- Are you using the right protocol?
- Is it RTU or TCP? Maybe ASCII?
- Can even have a look at the data packets, etc...
All this is easier to figure out first with some modbus utility...
and then to set it up in CODESYS should not be an issue.
P.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hey Guys :)
I have the following Problem using Modbus via Codesys:
I'm trying to implement a Modbus Device into my codesys project. The device is a Router from Teltonika (RUT956) and it can communicate via Modbus. Currently I'm trying to implement it into my codesys prject as a slave and I'm using my windows computer as master. As it is not a codesys device (the codesys application is not uploaded to device as it has its own software) I'm having problems requesting and reading registers from the router. I've set up my windows computer as Master and implemented the router as slave. When I go online on my master device it sais that it has established a connection to the slave (router)(So I'm thinking this could work as there is a connection?). The goal is to read the GPS (latitude and longitude) data and on the homepage of teltonika you can find the register address and number of registers (adress 143 for latitude and 145 for longitude; both have a number of two registers).
I've found tutorials how to read specific registers via their register address with other modbus programs (like modbus-cli), but as my entire project is established in codesys I was hoping to read these specific registers via codesys so that I can show the GPS data on my dashboard.
I've tried establishing slave channels but that hasn't been working. I tried read input register channels of the length 4 but it's not possible to define specific register addresses to read via codesys so that didn't work (I jsut get a slaves device failure) and I've also tried establishing 516 (total number of registers the router sends I think?) read inputregister channels but that has the samle failure...
So i guess the problem I'm having is establishing slave channels to read these specific registers. Does anyone know how to tackle this problem and has maybe had the same problem? Or maybe someone knows a workaround? I'm quite new to codesys so maybe I'm also lacking expertise...
Last edit: eoahe 2025-03-01
more posts ...
According to the documentation: https://wiki.teltonika-networks.com/view/RUT956_Modbus
You need to create a Channel to read 2 registers from address 143 to get the lattitude.
It doesn't specify if you need to read it as a Holding Register or as an Input Register. You could try both.
So in the Teltonika router, you need to enable it as being a Modbus Server.
Then in CODESYS add an Ethernet Adapter, then a Modbus Client (Master) and to the Client (Master) add the Modbus Server (Slave).
Set the IP address and add the Channel.
The please consider that CODESYS doesn't update any variables when they are not used in the application. In the I/O mapping tab of your I/O configuration, you can set the "Always update" to enabled.
Hi,
Might be a good idea first to try out the connection and the device with some handy software, like Modbus Poll.
There you can see better, what's really going on...
- Is it really connected?
- What error code does it return?
- Can it read from the register address?
- Maybe try Input registers and Holding Registers - can make a difference
- Sometimes register addresses are messed up: shifted +-1 (mixing of 2 standards)
- Sometimes register addresses start with offset 30000, 40000 ...
- Are you using the right protocol?
- Is it RTU or TCP? Maybe ASCII?
- Can even have a look at the data packets, etc...
All this is easier to figure out first with some modbus utility...
and then to set it up in CODESYS should not be an issue.
P.