Hello!
I'm trying to use a com port from sbcl.
My test code is as follows:
(defun tvs-open ()
(let ((fd (sb-posix:open "/dev/ttyS3" sb-posix:o-noctty sb-posix:o-rdwr)))
(setf *tvs-fd* fd))))
(defun tvs-close ()
(sb-posix:close *tvs-fd*))
(defun tvs-write ()
(cffi:with-foreign-object (buf :unsigned-char 512)
(setf (cffi:mem-aref buf :unsigned-char 0) 2)
(setf (cffi:mem-aref buf :unsigned-char 1) 1)
(setf (cffi:mem-aref buf :unsigned-char 2) 3)
(setf (cffi:mem-aref buf :unsigned-char 0) 2)
(setf (cffi:mem-aref buf :unsigned-char 0) #xb0)
(setf (cffi:mem-aref buf :unsigned-char 0) 3)
(sb-unix:unix-write 1 buf 0 3)
(sb-unix:unix-write 1 buf 3 3)))
(defun tvs-read ()
(cffi:with-foreign-object (buf :unsigned-char 512)
(sb-unix:unix-read *tvs-fd* buf 512)
(dotimes (i 32)
(format t "~a "
(cffi:mem-aref buf :unsigned-char i)))
(terpri)))
Alternatively, I can
(sb-sys:make-fd-stream fd :input :output :element-type '(unsigned-byte 8))
and then use READ-BYTE or WRITE-BYTE.
The problem is: reading works, writing doesn't.
UNIX-WRITE says NIL 9, that's "Bad file descriptor"
WRITE-BYTE complains that is't not a binary stream...
In the same time, C program
char buf[6];
int fd=open("/dev/ttyS3",O_NOCCTY,O_RDWR);
write(fd,buf,0,6);
perror("");
says "Success"...
What's wrong?
Thanks for any advice,
Dmitri
|