Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Modbus RTU #4

Open
ganehag opened this issue Sep 26, 2024 · 1 comment
Open

Support for Modbus RTU #4

ganehag opened this issue Sep 26, 2024 · 1 comment

Comments

@ganehag
Copy link
Owner

ganehag commented Sep 26, 2024

While Modbus RTU is not currently supported in the protocol, it is possible to extend the system to include this feature.

Current protocol;

0 <COOKIE> <IP_TYPE> <IP> <PORT> <TIMEOUT> <SLAVE_ID> <MODBUS_FUNCTION> <REGISTER_NUMBER> <REGISTER_COUNT/VALUE> <DATA>

New protocol:

0 <COOKIE> <COMM_TYPE> <DEVICE> <COMM_SETTINGS> <TIMEOUT> <SLAVE_ID> <MODBUS_FUNCTION> <REGISTER_NUMBER> <REGISTER_COUNT/VALUE> <DATA>

The IP_TYPE field would become the COMM_TYPE field, with 3 denoting serial communication. When the type is 3, the IP field would become the device path, and the PORT field would become a comma-separated list of settings.

Adding Modbus RTU support would require modifications not only to the handle_request code but also to the filtering code. This would involve adding a device field to match on Modbus RTU requests, as the current setup expects ip and port fields.

Another approach could be to implement a TCP-to-serial gateway directly within the program. This would allow multiple devices to be configured and mapped to available IPs on the device. While this approach doesn't require protocol changes and offers a more static configuration, it addresses security concerns related to specifying a device by path within the protocol. These security concerns could be mitigated by restricting the program's access to relevant devices using basic filesystem permissions.

An example of a configuration structure if we were to implement a TCP to serial gateway.

config serial_gateway
	option ip '192.168.1.100'  # Assign an IP for the serial gateway
	option port '502'  # TCP port for the gateway
	option device '/dev/ttyUSB0'  # Serial device path
	option baudrate '9600'  # Baud rate for serial communication
	option parity 'none'  # Parity setting (none, even, odd)
	option stop_bits '1'  # Number of stop bits
	option data_bits '8'  # Number of data bits
	option slave_id '2'  # Slave ID for this serial device
@sgralton
Copy link

sgralton commented Sep 26, 2024

For clarity, the Teltonika (at least as it is implemented on the TRB145) method for this is:
1 <COOKIE> <SERIAL_DEVICE_ID> <TIMEOUT> <SERVER_ID> <MODBUS_FUNCTION> <FIRST_REGISTER> <REGISTER_COUNT/VALUES>, where the leading 1 specifies RTU rather than 0 for TCP. SERIAL_DEVICE_ID points to the serial configuration that is set up on the Teltonika modem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants