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 function code 23 (#17)
#1
Does LM support the Modbus function code 23 with profiles or with a script (luamodbus)?
Thanks.
Reply
#2
See this: https://forum.logicmachine.net/showthrea...4#pid13244
Are you sure that function 23 is needed? Usually you can do writing and reading separately.
Reply
#3
Thanks for the answer.
User manual of this device seems to require FC 23 as you can see in the picture.
It's a Modbus interface for Mastervolt Battery charger (https://www.mastervolt.it/prodotti/maste...interface/)

Attached Files Thumbnail(s)
   
Reply
#4
When trying to implement communication with this device I always get the error "Bad file descriptor".
This LM uses both Modbus RTU ports with a different configuration.
Code:
123456789101112131415161718192021
require('luamodbus') buffer = {} function logger(c) table.insert(buffer, c) end local mb2 = luamodbus.rtu() mb2:open('/dev/rs485-2', 19200, 'E', 8, 1, 'H') mb2:connect() mb2:setslave(1) mb2:setdebug(logger) values,err=mb2:writereadregisters(0,6,12,0x0A,0x1AE0F,0x0,0x1) log(table.concat(buffer)) mb2:close()

This is the RTU port configuration:

Attached Files Thumbnail(s)
   
Reply
#5
RS must be uppercase in the port name.
Reply
#6
I partially solved it using the send() function sending a string to the device.
In debug I can see the response which is complete and correct but the mb:receive() function returns a timeout error.

Code:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
require('luamodbus') function hexToString(hex)     -- Remove any spaces or invalid characters     hex = hex:gsub("([^0-9a-fA-F])", "")         -- Convert each pair of hex digits into a character     local str = ""     for i = 1, #hex, 2 do         local byte = hex:sub(i, i + 1)         str = str .. string.char(tonumber(byte, 16))     end     return str end buffer = {} function logger(c)     table.insert(buffer, c) end local mb2 = luamodbus.rtu() mb2:open('/dev/RS485-2', 19200, 'E', 8, 1, 'H') mb2:connect() mb2:setslave(1) mb2:setreceivetimeout(1.0) mb2:setresponsetimeout(1.0) mb2:setdebug(logger) local variable_number = '11'  -- in hexadecimal hex_decoded = hexToString("011700000006000000060c0a01ae0f000000" .. variable_number .. "00000000") -- Sending variabile,err_s=mb2:send(hex_decoded) -- Response local response,err = mb2:receive() -- Log the sending operation if variabile then     log("Is send successful?: ")     log(variabile) else     log("Sending error: "..err_s) end -- Log the response if response then     log("Response from device: " .. table.concat(response, ", ")) else     log("Response error: ".. err_r) end log(table.concat(buffer)) mb2:close()

Logs report:

Response error: Operation timed out

Debug:
* string: [01][17][00][00][00][06][00][00][00][06][0C][0A][01][AE][0F][00][00][00][11][00][00][00][00][91][AF]
Waiting for a indication...
<01><17><0C><0A><01><AE><0F><00><00><00><11><00><00><00><42><C1><35>ERROR Operation timed out: select

The response captured by debug is complete and correct.
I tried to change setreceivetimeout() and setresponsetimeout() with no effects.
Reply
#7
You can't use receive for master operation. The equivalent of your raw string using writereadregisters is this:
Code:
1
mb:writereadregisters(0, 0x0A01, 0xAE0F, 0, 0x0011, 0, 0, 0, 6)
Reply


Forum Jump: