Is modbus TCP possible in next time?

Give it a try, it costs you nothing !
Helmut_number_one
Posts: 97
Joined: Fri Dec 09, 2022 10:03 am
Has thanked: 41 times
Been thanked: 9 times

Re: Is modbus TCP possible in next time?

Post by Helmut_number_one »

Could it be due to the implementation at the bottom right of the" Modbus TCP to RTU " converter config page?
Interface with pure Modbus to TCP is ok.
I just get no response at all, no error message.
User avatar
cicciocb
Site Admin
Posts: 2056
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 439 times
Been thanked: 1356 times
Contact:

Re: Is modbus TCP possible in next time?

Post by cicciocb »

I've not a great experience on that, I'm sorry, I should learn before how your converter work. I'll try to give a look tomorrow
Helmut_number_one
Posts: 97
Joined: Fri Dec 09, 2022 10:03 am
Has thanked: 41 times
Been thanked: 9 times

Re: Is modbus TCP possible in next time?

Post by Helmut_number_one »

Don't stress, I'm looking forward to my first successes. It works quite well without a converter, a little better if you add a pause after Modbus connect.
Edit: 14.4.
With Modbus TCP via a Modbus TCP / RS485, only the first query always has an error.

Code: [Local Link Removed for Guests]

 
 4567 Error response: E0 - Timeout
4567 Error response: EA - IP connection failed

This program is ok with directly Modbus TCP , reads analog registers and converts them into voltage values. The breaks help keep things running smoothly.
What do I do if I also want to count up the tokens to have the appropriate number of tokens for the number of registers?

Code: [Local Link Removed for Guests]

'MODBUS example - write and read in the HOLD_REGISTER 0
READ_HOLD_REGISTER = 3
READ_INPUT_REGISTER = 4
'WRITE_HOLD_REGISTER = 6
SERVER_ID = 1
' MODBUS.CONNECT IP$, [port] [,timeout] [,idleTimeout]
onWgetAsync modbus_received 'set the event handler function
pause 200
modbus.connect "192.168.0.44", 504, 1000 'address of the remote server
pause 200
for z = 10 to 14 '     5 register   ----- Hier meine Anzahl Register die gelesen werden sollen
modbus.request 4567, SERVER_ID , READ_INPUT_REGISTER, z, 1
pause 1000
next z
end
modbus_received:
r$ = WGETRESULT$
wlog r$
print r$
token$ = word$(r$, 1) 'extract the token (first word)
if (token$ ="4567") then ' if the token correspond to the read request
  if (word$(r$, 2) <> "Error") then 'if is not an error
    'assemble the 2 bytes in one 16 bits word
    value$ = "&h"+ word$(r$, 5) + word$(r$, 6)
    wlog val(value$) 'converts from hex to integer
    MaxVolt = 33
    BiValue = 40960
    Umrechnung = (MaxVolt / BiValue)
    Wert = val(value$)
    InVolt = Umrechnung * Wert
    wlog Involt   ' Output Volt ---Ausgabe in Volt
  end if
endif
return

Last edited by Helmut_number_one on Sun Apr 14, 2024 8:07 am, edited 2 times in total.
Helmut_number_one
Posts: 97
Joined: Fri Dec 09, 2022 10:03 am
Has thanked: 41 times
Been thanked: 9 times

Re: Is modbus TCP possible in next time?

Post by Helmut_number_one »

!!!!! With tis programtest it's running with a Ehternet to Modbus RTU adapter:

Code: [Local Link Removed for Guests]

'MODBUS example - write and read in the HOLD_REGISTER 0
READ_HOLD_REGISTER = 3
READ_INPUT_REGISTER = 4
'WRITE_HOLD_REGISTER = 6
SERVER_ID = 1
' MODBUS.CONNECT IP$, [port] [,timeout] [,idleTimeout]
onWgetAsync modbus_received 'set the event handler function
pause 200
modbus.connect "192.168.0.200", 4196,  1000', 10 'address of the remote server
pause 200
for z = 1 to 100 '   read 100 * ----  100 mal lesen
modbus.request 4567, SERVER_ID , READ_HOLD_REGISTER , 4157, 1
pause 1000
next z
end
modbus_received:
r$ = WGETRESULT$
wlog r$
print r$
token$ = word$(r$, 1) 'extract the token (first word)
if (token$ ="4567") then ' if the token correspond to the read request
  if (word$(r$, 2) <> "Error") then 'if is not an error
    'assemble the 2 bytes in one 16 bits word
    value$ = "&h"+ word$(r$, 5) + word$(r$, 6)
    wlog val(value$) 'converts from hex to integer
    'MaxVolt = 33
    'BiValue = 40960
    'Umrechnung = (MaxVolt / BiValue)
    'Wert = val(value$)
   ' InVolt = Umrechnung * Wert
    'wlog Involt
  end if
endif
return

response:

Code: [Local Link Removed for Guests]

 
4567 01 03 02 3E A7 
16039
4567 01 03 02 3E A8 
16040
4567 01 03 02 3E BF 
16063
4567 01 03 02 3E BF 
16063
4567 01 03 02 3E BF 
16063
4567 01 03 02 3E BE 
16062
4567 01 03 02 3E BE 
16062
4567 01 03 02 3E BF 
16063
4567 01 03 02 3E BE 
16062
4567 01 03 02 3E BE 
16062
4567 01 03 02 3E B4 
16052
4567 01 03 02 3E B5 
16053
4567 01 03 02 3E B6 
16054
4567 01 03 02 3E B7 
16055
4567 01 03 02 3E B7 
16055
 
It is a Float32 (32Bit), how are convert this?
User avatar
cicciocb
Site Admin
Posts: 2056
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 439 times
Been thanked: 1356 times
Contact:

Re: Is modbus TCP possible in next time?

Post by cicciocb »

The answer that you receive is only 2 bytes (so 16bits :roll: ).

Probably your request
modbus.request 4567, SERVER_ID , READ_HOLD_REGISTER , 4157, 1

should be
modbus.request 4567, SERVER_ID , READ_HOLD_REGISTER , 4157, 2

After that, there is a function to convert, if I remember well is
CONVERT.FROM_IEEE754(iee754_bin)
Helmut_number_one
Posts: 97
Joined: Fri Dec 09, 2022 10:03 am
Has thanked: 41 times
Been thanked: 9 times

Re: Is modbus TCP possible in next time?

Post by Helmut_number_one »

Yes, I've already tried to enlarge it to 32 bits... so far I haven't been able to... ;-)
Edit i try it.

Code: [Local Link Removed for Guests]

value$ = "&h"+ word$(r$, 5) + word$(r$, 6 + word$(r$, 7) + word$(r$, 8)
I will do my very best....

Code: [Local Link Removed for Guests]

 
 'MODBUS example - write and read in the HOLD_REGISTER 0
READ_HOLD_REGISTER = 3
READ_INPUT_REGISTER = 4
'WRITE_HOLD_REGISTER = 6
SERVER_ID = 1
' MODBUS.CONNECT IP$, [port] [,timeout] [,idleTimeout]
onWgetAsync modbus_received 'set the event handler function
pause 200
modbus.connect "192.168.0.200", 4196,  1000', 10 'address of the remote server
pause 200
for z = 1 to 1000 ' 100 X read ----  Anzahl der Leseung
'modbus.request 4567, SERVER_ID , READ_HOLD_REGISTER , 4157, 1  ' 16 bit
modbus.request 4567, SERVER_ID , READ_HOLD_REGISTER , 4157, 2 ' 32 Bit
pause 100
next z
end
modbus_received:
r$ = WGETRESULT$
wlog r$
print r$
token$ = word$(r$, 1) 'extract the token (first word)
if (token$ ="4567") then ' if the token correspond to the read request
  if (word$(r$, 2) <> "Error") then 'if is not an error
    'assemble the 2 bytes in one 16 bits word
    'value$ = "&h"+ word$(r$, 5) + word$(r$, 6)
     'assemble the 4 bytes in one 32 bits word, it dosn't running
    value$ = "&h"+ word$(r$, 5) + word$(r$, 6) + word$(r$, 7) + word$(r$, 8)
    Ergebnis1= val(value$)
    'wlog val(value$) 'converts from hex to integer
    
   Ergebnis =  ( CONVERT.FROM_IEEE754(Ergebnis1) *1000)
   wlog Ergebnis
   ' If i read a analog 16 bit analog Register
    'MaxVolt = 33
    'BiValue = 40960
    'Umrechnung = (MaxVolt / BiValue)
   'Wert = val(value$)
    'InVolt = Umrechnung * Wert
   ' wlog Involt
  end if
endif
return

YouAreTheBest.png
only Now I would like to put the result into a query loop so that I can read 3 - 5 registers at once and get the respective result into different "tokens" or variables
You do not have the required permissions to view the files attached to this post.
User avatar
cicciocb
Site Admin
Posts: 2056
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 439 times
Been thanked: 1356 times
Contact:

Re: Is modbus TCP possible in next time?

Post by cicciocb »

Good!

What are the registers that you want use?
If they are in consecutive addresses, you can use a single query otherwise you can do several queries but with different tokens so you'll be able to distinguish them in the answer
Helmut_number_one
Posts: 97
Joined: Fri Dec 09, 2022 10:03 am
Has thanked: 41 times
Been thanked: 9 times

Re: Is modbus TCP possible in next time?

Post by Helmut_number_one »

EDit 12:00
If they are in consecutive addresses, you can use a single query.
Do the individual addresses then also receive different tokens?
This varies from application to application, Pokeys 16bit Integer 1-34
Analogs from 40 to 46
Janitza Modbus Energy 32bit Float here:
4119 Active Energy 1st phase T1, imp (kWh) x x x
Readable
values
(Energies and
other
istantaneous
measurements)
4123 Active Energy 2nd phase T1, imp (kWh)
4127 Active Energy 3rd phase T1, imp (kWh)
4131 Active Energy Σ T1, imp (kWh) x x
4135 Active Energy 1st phase T2, imp (kWh)
4139 Active Energy 2nd phase T2, imp (kWh)
4143 Active Energy 3rd phase T2, imp (kWh)
4147 Active Energy Σ T2, imp (kWh)
4151 Active Power 1st phase (kW)
4153 Active Power 2nd phase (kW)
4155 Active Power 3rd phase (kW)
4157 Active Power Σ (kW)
User avatar
cicciocb
Site Admin
Posts: 2056
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 439 times
Been thanked: 1356 times
Contact:

Re: Is modbus TCP possible in next time?

Post by cicciocb »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Sun Apr 14, 2024 9:51 am This varies from application to application, Pokeys 16bit Integer 1-34
Analogs from 40 to 46
Janitza Modbus Energy 32bit Float here:
4119 Active Energy 1st phase T1, imp (kWh) x x x
Readable
values
(Energies and
other
istantaneous
measurements)
4123 Active Energy 2nd phase T1, imp (kWh)
4127 Active Energy 3rd phase T1, imp (kWh)
4131 Active Energy Σ T1, imp (kWh) x x
4135 Active Energy 1st phase T2, imp (kWh)
4139 Active Energy 2nd phase T2, imp (kWh)
4143 Active Energy 3rd phase T2, imp (kWh)
4147 Active Energy Σ T2, imp (kWh)
4151 Active Power 1st phase (kW)
4153 Active Power 2nd phase (kW)
4155 Active Power 3rd phase (kW)
4157 Active Power Σ (kW)
Looks that all the block of addresses are not really consecutive so, you are obliged to make several requests but you can do blocks, for example Pokeys 16bit Integer 1-34

modbus.request 4567, SERVER_ID , READ_HOLD_REGISTER , 1, 34

Then you'll receive a long list , something like
4567 01 03 44 xx xx yy yy zz zz qq qq .....
where xx xx will be 1, yy yy will be 2, zz zz will be 3 .....
Helmut_number_one
Posts: 97
Joined: Fri Dec 09, 2022 10:03 am
Has thanked: 41 times
Been thanked: 9 times

Re: Is modbus TCP possible in next time?

Post by Helmut_number_one »

Ok, I have to see how I separate this, can xx xx be at 16 bits and xx xx xx xx be at 32 bits?
At moment i have no time for this, but i try it next time, thank you.
Post Reply