Android Question modbus help

billyrudi

Active Member
Licensed User
hi i'm new on modbus,
can
someone share with me some library or code to work with modbus devices?
i have a device on tcpip that have data on the service 0x04 at the resgistry 0x30001 and so..

can you help me?

regards Paolo Lops
 

Cableguy

Expert
Licensed User
hi i'm new on modbus,
can
someone share with me some library or code to work with modbus devices?
i have a device on tcpip that have data on the service 0x04 at the resgistry 0x30001 and so..

can you help me?

regards Paolo Lops
How does this relate to android app development and/or b4a?
 

mark35at

Well-Known Member
Licensed User
I am not sure that you can do this without a protocol driver for modbus. But with TCPIP it may be possible to directly address the device.

As far as I can remember, modbus requires an integer "command" and returns an integer value based on the reolution of the A/D converter.

Example: 20°C with an 16 bit converter (65536).

resolution of DAQ x °C / Maximum measurable Temperature = 65536 x 20 /1100 = 1191.56 Modbus would transmit 1191 and then you convert it back.

Establish communication with your device, telling it to wait for a command. Then send the integer 40001 (4 is the command to read a register, 0 is the register in this case). Not sure why you want to read using the command 3! Careful if the device is 32 bit, as the result will be in two registers, high bit and low bit for a floating point value. You will probably need to scale the resulting value as well. Never tried this with android.
I have no idea what library you can use but try searching for microprocessor control here in the forum. People control all sorts of things here!!

If you get this working, I would be very interested in how. Good luck.
 

billyrudi

Active Member
Licensed User
Hi to all,
i have solved my problem using wagoid library ( i have found it in this forum) and the network library linked!!!!

Dim modbus as Wagoid

modbus.Ip("192.168.1.11")
modbus.Connected

Dim i As Int
i = modbus.Read_input_analog (196617)

where 196617 i the registry in decimal of my registry 0x30009

regards Paolo
 

billyrudi

Active Member
Licensed User
Hi to all i share some code to help you:
for android network error
i must insert
B4X:
Sub DisableStrictMode
   Dim jo As JavaObject
   jo.InitializeStatic("android.os.Build.VERSION")
   If jo.GetField("SDK_INT") > 9 Then
     Dim policy As JavaObject
     policy = policy.InitializeNewInstance("android.os.StrictMode.ThreadPolicy.Builder", Null)
     policy = policy.RunMethodJO("permitAll", Null).RunMethodJO("build", Null)
     Dim sm As JavaObject
     sm.InitializeStatic("android.os.StrictMode").RunMethod("setThreadPolicy", Array(policy))
   End If
End Sub

for read signed short
i must declare

Dim j As Short
j = s.Read_input_analog (196614)
Global.Potenzarete = j

then it return the correct value :
65534 if i read with integer variable
-2 if a read with short variable.

i hope that this can help you.
bye
 
Top