EasyManua.ls Logo

Embedded Systems LogiMachine5 Power - Page 225

Embedded Systems LogiMachine5 Power
254 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
225
Examples
Write to port
port:write('test data')
Blocking read (script will block until 10 characters are read)
data=port:read(10)
Timeout read (script will wait for 10 characters for 20 seconds)
data=port:read(10, 20)
Close serial port
port:close()
Resident script, RS-485 echo test
-- open port on first call
if not port then
require('serial')
port = serial.open('/dev/RS485-1', { baudrate = 9600, parity = 'even', duplex = 'half' })
port:flush()
end
-- port ready
if port then
-- read one byte
char = port:read(1, 1)
-- send back if read succeeded
if char then
port:write(char)
end
end
HEX to RS-485 example
require('serial')
port = serial.open('/dev/RS485-1', {
baudrate = 4800,
parity = 'none',
duplex = 'half'
})
cmd = string.char(0xAB, 0xF1, 0xFF, 0xFF, 0xFF, 0xFF, 0xBE, 0xD1, 0x01, 0xFE, 0xFF, 0xFF,
0x0A, 0x24)
cmd = 'ABF1FFFFFFFFBED101FEFFFF0A24'
port:write(cmd)
Check which cmd works for you, as it can be either hex-encoded readable data or hex
representation of binary data. You might also need to change the parity config
http://openrb.com/docs/serial.htm

Table of Contents