Help with RS-232 comms

Q&A's, tips, howto's
Locked
electrifiedspam
Posts: 27
Joined: Sat Nov 06, 2010 11:39 pm

Help with RS-232 comms

Post by electrifiedspam »

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.

electrifiedspam
Posts: 27
Joined: Sat Nov 06, 2010 11:39 pm

Re: Help with RS-232 comms

Post by electrifiedspam »

Please forgive me, I am so new and constantly over my head.

I see that the result symbol is only capturing true and not the message.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: Help with RS-232 comms

Post by Lutz »

no, no, the 'result variable actually is receivng the return value of the expression and the whole 'catch' expression returns true.

Code: Select all

> (catch (+ 2 3) 'result)
true
> result
5
> 
what probably is happening in your case is, that (int (-12 5 buff)) returning nil because the contents of (-12 5 buff) is not a number. If buff contains 0 characters it will stop printing at that place. You could insert a (print (-12 5 buff)) to see the contents. Or do a (print (map char (explode (-12 5 buff)))) to see what's in that piece of buff. Or inspect the entire buffer with (println (map char (explode buff)))

Locked