Is modbus TCP possible in next time?

Give it a try, it costs you nothing !
Post Reply
Tymon Elektryk
Posts: 6
Joined: Mon Apr 19, 2021 4:24 pm
Been thanked: 3 times

Re: Is modbus TCP possible in next time?

Post by Tymon Elektryk »

I am correcting my previous post
Everything works great

Code: [Local Link Removed for Guests]

READ_INPUT_REGISTER = 3
WRITE_HOLD_REGISTER = 6
SERVER_ID = 1
onWgetAsync modbus_received 'set the event handler function
modbus.setupRTU 3,1,2 ' by default is 9600,N,8,1

do
pause 1000  '     reading                              adres  2 register 16bit  
modbus.requestRTU 1234, SERVER_ID, READ_INPUT_REGISTER, 7016, 2  '  send view from  RS485 terminal  01 03 1B 68 00 02 43 33
pause 5000     ' recording                           adres , data write
modbus.requestRTU  4567, SERVER_ID, WRITE_HOLD_REGISTER,4010,8  'send view from  RS485 terminal  01 06 0F AA 00 08 AB 38 
' slave Modbus RTU reply in the same way 
pause 5000
loop
end

modbus_received:
r$ = WGETRESULT$
wlog r$  ' 1234 01 03    04 42 48 11 C3 
token$ = word$(r$, 1) 'extract the token (first word)
if (token$ ="1234") then  ' if the token correspond to the read request
if (word$(r$, 2) <> "Error") then  'if is not an error
    temp$ = "&h"+ word$(r$,5) + word$(r$,6)   +   word$(r$,7) +  word$(r$,8)
    wlog temp$ '        &h   42  48  11  C3         2 reg 16 bit 
    a = val(temp$)
   
   WLOG CONVERT.FROM_IEEE754(A) '  50.017345 -  frequency

end if
endif
return
view from the terminal
1234 01 03 04 42 47 E6 4D
&h4247E64D
49.974903
4567 01 06 0F AA 00 08
1234 01 03 04 42 48 01 23
&h42480123
50.00111
4567 01 06 0F AA 00 08
1234 01 03 04 42 47 FC 1C
&h4247FC1C
49.996201
4567 01 06 0F AA 00 08
Post Reply