Logic Machine Forum
RS-232 Projector control - 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: RS-232 Projector control (/showthread.php?tid=4651)



RS-232 Projector control - SevenP - 15.03.2023

Hello,
I am trying to control a projector via RS232 protocol. I own LogicMachine 5 Lite.
So far it has created a virtual object for simple on/off control, I have attached an event-script to it:


Code:
require('serial')

device = '/dev/RS232'

port = serial.open(device, { baudrate = 9600, parity = 'none', databits = 8, stopbits = 1, duplex = full })
port:flush()

-- get value of KNX object
value = event.getvalue()
log(value)

if (value == true) then
  -- send power on command with returns to make them stick
  char = "\r*pow=on#\r"
  log("wyslka on")
  res, err = port:write(char)
  log('blad:', err)
else
  -- send power off command
  char = "\r*pow=off#\r"
  log("wyslka off")
  res, err = port:write(char)
  log('blad: ', err)
end

-- close port
port:close()

Is the above script sufficient? I understand that by defining the communication in the script I don't need to set anything else in the tab with "Modbus"?
In the logs it seems to me that the script returns a "nil" error when writing, what does this mean?

I have the LM5 Lite + Ext (i.MX6) firmware uploaded.
The cable issues can be dismissed, I have swapped TX with RX more than once.

I would be grateful for any help.

Log response in attachment.


RE: RS-232 Projector control - Daniel - 15.03.2023

Are you sure it is RS232 and not TTL? Drop some documentation.


RE: RS-232 Projector control - SevenP - 15.03.2023

(15.03.2023, 14:36)Daniel Wrote: Are you sure it is RS232 and not TTL? Drop some documentation.

Yes, I am pretty sure it is RS232.
In attachment there are documentation which I got from producer.


RE: RS-232 Projector control - admin - 15.03.2023

nil means no error. You don't need to change anything in Modbus, it is not related to using serial ports in scripts. Check that projector has the same baud rate as the script. Check if you get any reply before closing the port:
Code:
res, err = port:read(-1, 2)
log(res, err)
-- close port
port:close()
Do this with reversed RX/TX as well. Make sure that GND is connected between the projector and LM.