Answer the question
In order to leave comments, you need to log in
How to work in Lua with bytes in port?
There are two certain controllers. These controllers have ports (RS485, but not the essence) that are interconnected. Several simple devices on the MK are also connected there. One controller can throw bytes, the second controller can receive them. On Linux controllers (closed a little more than completely) and LUA. There is nothing more.
Attention, the question is: How can I send and receive in Lua not a character, not a string, but just a byte or several bytes in hexadecimal representation? Those. I send 0x15, and on the other controller I also receive 0x15.
So far, I've been tormented for an hour, and I get anything but 0x15. I did not understand whether he converts it into something when sending it, or when receiving it.
Shipping:
require('serial')
port = serial.open('/dev/RS485-2', {
baudrate = 115200,
databits = 8,
stopbits = 1,
parity = 'none',
duplex = 'half'
})
port:write(0x15)
port:close()
require('serial')
port2 = serial.open('/dev/RS485-3', {
baudrate = 115200,
databits = 8,
stopbits = 1,
parity = 'none',
duplex = 'half'
})
data = port2:read(1)
byte=string.byte(data)
log(string.format("%o, %x, %d", byte,byte,byte))
port2:close()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question