This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Modbus > writeregisters for INT
#1
Hi all,

I'm working with Lua scripts to manage a Modbus slave (RS485 mode), but I got errors using
writeregisters(reg,value) when "reg" is an INT (signed 16) one.

No problems with UINT registers, I can read and write with "writeregisters" and "readregisters" instructions.
So... I have a problem !

Could you help me please ?

Many thank's in advance,
Dominique | Sigma Tec
Reply
#2
What kind of error are you getting? Provide your script if possible. Also why don't you use profiles instead of scripts?
Reply
#3
Hi,

when I write an INT16 in the register concerned, the value is taken into account by the slave, but the slave then goes into error when its "time out" time is reached. It seems that the Modbus frame is misinterpreted.

This does not happen when I write UINT16 in the registers of the same slave.

Here is my script (reduced to the problem section) :

------------------------------------------------------------------------------
modbus_slave_num = 7

-- eval temps execution de ce script
local ts, tus = os.microtime()

-- nom de ce script
log("--------------------------------------------------------------------")
log(_SCRIPTNAME)

-- Init Modbus
modbus_slave_num = 7

if not mb then
require('luamodbus')
mb = luamodbus.rtu()
mb:open("/dev/RS485", 19200, "E", 8, 1,"H")
mb:connect()
end

mbConfusedetslave(modbus_slave_num)

-- register 11410 = INT16 <<<<<<<<< PROBLEM >>>>>>>>>>>>>
result1 = mb:writeregisters(11410, 130)
log ("Result1 = ",result1)

-- Fermer la connexion Modbus
mb:close()

-- eval temps execution de ce script
log("TEMPS EXCE : ", os.udifftime(ts, tus))

------------------------------------------------------------------------------

Have a nice end of day,
Dominique
Reply
#4
You might have wrong register address or multiple scripts try to access RS-485 bus at the same time. You should really use profiles.

To debug your problem log both return values:
Code:
res, err = mb:writeregisters(11410, 130)
log ("Result1 = ", res, err)
Reply
#5
(08.11.2018, 15:00)admin Wrote: You might have wrong register address or multiple scripts try to access RS-485 bus at the same time. You should really use profiles.

To debug your problem log both return values:
Code:
res, err = mb:writeregisters(11410, 130)
log ("Result1 = ", res, err)

Ok Admin, I will try this...

many thank's
Reply


Forum Jump: