ModbusRTU extension

I have made an extension for Modbus RTU serial communication, for my own needs. It can read and write single registers and is based on my SerialOTG extension (can be expanded to read/write multiple registers). I can make it available to Appinventor users. Please return if there is any interest and any specific functions that you need.

4 Likes

Will it work over WiFi ?

If you mean ModbusTCP, then the answer is no. It is limited to ModbusRTU over serial line for now. I made this extension to be able to read and write registers in a PLC and in I/O devices from ICP-Con. It will work with the same devices as my extension SerialOTG: https://github.com/rkl099/Appinventor-SerialOTG.

There are a lot of other I/O modules and also USB-Rs485, Rs232-Rs485 converters that can be used to connect to ModbusRTU networks.
(ModusTCP may be added in the future.)

Hi rkl099,

I am looking for a ModbusRTU extension.
I am very new in programming with App Inventor, but I need a little App which can read and write some Modbus registers over Bluetooth.
So would it be possible realize this with your extension? And would you share your extension?
Thank you very much!

No, I have only implemented serial line communication, using an usb-serial adapter.
Maybe you can use an serial-bluetooth adapter instead but I have not tried that!
I have made this extension and test program available at:

1 Like

Ok, I see. Thank you very much for sharing!
I will take a look on it. :slight_smile:
Would it be a big effort to use the bluetooth interface instead of serial line?

I have examined the library that I have modified and used for my extensions. It had a Bluetooth serial class, but it only implements BT server (slave), so the external device has to initialize the connection. I think this is possible with HC-05, (not with HC-06) but this does not seems to be so useful.
One solution is to make a new Modbus extension that only do the Modbus formatting and checking. You can then use SerialOTG or a Bluetooth extensions for the communication. But this needs some work.

I have updated my ModbusRTU extension with support for BT and WIFI. I have added ModbusTCP protocol. You can also bridge ModbusRTU over BT or WIFI.

It implements single 16b read/write and a function to calculate modbusRTU CRC. You can use this to implement other Modbus functions.

The new extension can be found at:

https://github.com/rkl099/Appinventor-Modbus

I received the following email by @rkl099

Hello, I want to update information about my contributions to Appinventor

Modbus by rkl099. Support for Modbus RTU/TCP over serial, BT and WIFI

Direct link: GitHub - rkl099/Appinventor-Modbus: Appinventor ModbusRTU and ModbusTCP 1.1. Extension and app to implement single 16b/32b register read and 16b write. Uppdated for Andoid12

Thank you for listing extensions to Appinventor

Thank you @rkl099, now added in the extensions directory App Inventor Extensions | Pura Vida Apps
Taifun

I have added read of one 32bit register to the Modbus extension (user request).

The wifi can connect to Modbus tcp, but the 4G network cannot be used

I have never tested that.
Can you describe your application? Do you use static or dynamic IP? Firewall, routers, ports etc?

The mobile phone uses Wi Fi to connect to the Internet to remotely control the Modbus TCP device.Modbus TCP devices use static ip.Modbus TCP devices without firewalls and routers use port 502.Using Wi Fi to connect to the Internet can successfully remote control.
The Modbus TCP device cannot be connected to the Internet using a 4G network.

If I understand your problem, you can't connect to the remote. That is, you can't open the connection in the app.
I can't see any real reason for this except:
You have to turn off WIFI.
The connection takes to long time. (limited to 0.5 sec in the library, but can be extended by a program change)

An updated version 1.5beta is now available on my rkl099/Appinventor-Debug directory.
The time to connect to a server has been changed from 0.5s to 5 sec, and some changes to select the driver. Please test and report.

Hello, I am interested for modbus TCP.
Is that possible with your work ?
Best regards

Yes, it's possible. You can study my example and the documentation at GitHub - rkl099/Appinventor-Modbus: Appinventor ModbusRTU and ModbusTCP 1.1. Extension and app to implement single 16b/32b register read and 16b write. Appinventor_Debug has a test release, but the changes are mainly in the serial part. Main limitations are: only a few functions are implemented. You can only have one outstanding request. Timeout must be programmed in your app.

With this extension I can use the modbus function code for coil writing

Only function codes 0x03, 0x04 and 0x06 have been implemented. Not single coil write 0x05 or any read/write of multiple data (except for read double register using fc 0x03). Please see the documentation.
It is possible to implement single coil read and single coil write, but i have no way of testing it.

I need to send the command to trigger the output coils in modbus. How can I write with function 0x06?