From: Jonathon McKitrick
Subject: Serial port access
Date: 
Message-ID: <1132269319.978206.130870@f14g2000cwb.googlegroups.com>
Hi all,

I used to use pyserial to control instruments with serial input, and
I'm trying to find something similar for CL.  I'm able to open the port
(/dev/cuaa0) but I cannot tell what combination of read/write and
byte/char/line I need to get it to work correctly.  I feel like right
now I'm just trying the shotgun approach, and I'd like something more
methodical.  Obviously, part of the trick is getting the timeout value
correct.

Running SBCL 0.9.5 on FreeBSD
Serial parameters: straight ascii commands @ 9600 baud, 8-N-1, nothing
special.

From: ·········@cern.ch
Subject: Re: Serial port access
Date: 
Message-ID: <yzoy83mfhze.fsf@cern.ch>
Jonathon> Running SBCL 0.9.5 on FreeBSD
Jonathon> Serial parameters: straight ascii commands @ 9600 baud,
Jonathon> 8-N-1, nothing special.

The *nix serial ports are for connecting terminals and modems, so
please consider any other use *special*:-) 

Supposing your *nix has termios, I suggest you take a look at `man
cfmakeraw' and friends. If you can't find an SBCL interface to termios
you might find the CMUCL implementation useful for a starting point.

Ole
From: Petter Gustad
Subject: Re: Serial port access
Date: 
Message-ID: <87wtj6p53f.fsf@filestore.home.gustad.com>
"Jonathon McKitrick" <···········@bigfoot.com> writes:

> I used to use pyserial to control instruments with serial input, and
> I'm trying to find something similar for CL.  I'm able to open the port
> (/dev/cuaa0) but I cannot tell what combination of read/write and
> byte/char/line I need to get it to work correctly.  I feel like right
> now I'm just trying the shotgun approach, and I'd like something more
> methodical.  Obviously, part of the trick is getting the timeout value
> correct.

I've been using the USB serial driver under Linux with CMUCL to talk
to some hardware that I've designed. Here's some extracts from the
code.

  (let ((fd (unix:unix-open dev unix:o_rdwr #o666)))
...
    (setraw fd)

    (system:make-fd-stream fd :name "picprog" 
                              :input t :output t
                              :element-type '(unsigned-byte 8)
                              :buffering :none 
                              :auto-close t)))

setraw is using the termios interface:

(alien:def-alien-type tcflag-t (alien:unsigned 32))
(alien:def-alien-type speed-t (alien:unsigned 32))
(alien:def-alien-type cc-t (alien:unsigned 8))
(alien:def-alien-type termios
    (alien:struct termios
                  (iflag tcflag-t)
                  (oflag tcflag-t)
                  (cflag tcflag-t)
                  (lflag tcflag-t)
                  (cc-line cc-t)
                  (cc (array cc-t 32))
                  (ispeed speed-t)
                  (ospeed speed-t)))

(defun setraw (fd)
  "set the file descriptor interface to raw mode using termios"

  (alien:with-alien ((tio (alien:struct termios)))
    (alien:alien-funcall 
     (alien:extern-alien "tcgetattr" (alien:function c-call:int c-call:int (* termios)))
     fd
     (alien:addr tio)))
  
  (alien:with-alien ((tio (alien:struct termios)))
    (alien:alien-funcall 
     (alien:extern-alien "cfmakeraw" (alien:function c-call:int (* termios)))
     (alien:addr tio)))
  
  (alien:with-alien ((tio (alien:struct termios)))
    (alien:alien-funcall 
     (alien:extern-alien "tcsetattr" (alien:function c-call:int c-call:int c-call:int (* termios)))
     fd
     0
     (alien:addr tio))))


Petter

-- 
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?