Modbus > writeregisters for INT - Printable Version +- Logic Machine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8) +--- Thread: Modbus > writeregisters for INT (/showthread.php?tid=1703) |
Modbus > writeregisters for INT - SigmaTec - 08.11.2018 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 RE: Modbus > writeregisters for INT - admin - 08.11.2018 What kind of error are you getting? Provide your script if possible. Also why don't you use profiles instead of scripts? RE: Modbus > writeregisters for INT - SigmaTec - 08.11.2018 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 mbetslave(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 RE: Modbus > writeregisters for INT - admin - 08.11.2018 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) RE: Modbus > writeregisters for INT - SigmaTec - 08.11.2018 (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. Ok Admin, I will try this... many thank's |