Help with RS-232 comms
Posted: Tue Dec 28, 2010 6:02 am
When running the following code:
; Initialization
(define (com-init)
(exec "mode COM1 BAUD=9600 PARITY=O DATA=8 STOP=1"))
; Getting data from COM-port
(define (start-listening)
(local (hndl buff)
(set 'hndl (open "COM1" "r"))
(read hndl buff 40 (char 0x0D))
(close hndl)
(int (-12 5 buff))))
(com-init)
(if (catch (start-listening) 'result)
(println "Message: " result)
(println "no link"))
--------------------------------------------------
My message returns nil.
I assume that it is looking for printable characters, but how can I capture the hex of the message.
My ultimate goal is to write a Modbus module for newlisp. That would allow me to use it at work as most of the equipment we use supports Modbus.
; Initialization
(define (com-init)
(exec "mode COM1 BAUD=9600 PARITY=O DATA=8 STOP=1"))
; Getting data from COM-port
(define (start-listening)
(local (hndl buff)
(set 'hndl (open "COM1" "r"))
(read hndl buff 40 (char 0x0D))
(close hndl)
(int (-12 5 buff))))
(com-init)
(if (catch (start-listening) 'result)
(println "Message: " result)
(println "no link"))
--------------------------------------------------
My message returns nil.
I assume that it is looking for printable characters, but how can I capture the hex of the message.
My ultimate goal is to write a Modbus module for newlisp. That would allow me to use it at work as most of the equipment we use supports Modbus.