Re: Talking to Mindstorms over USB



"ansofive@xxxxxxxxx" <ansofive@xxxxxxxxx> writes:

Hi,

I've broken out my old Mindstorms kit and I'm working on a simple
package to send commands to the brick from my workstation. You send
data to the brick over a USB device so I open the device file (/dev/
usb/legousbtower0) and write my packet - Works fine, lasts a long
time. Here's what I have so far:

(defun send-message (message &key (port *port*))
"Send a list of bytes to the brick and wait for the reply."
(with-open-file (stream port
:direction :io
:if-does-not-exist :create
:if-exists :overwrite
:element-type '(unsigned-byte 8))
(write-sequence (mk-packet message) stream)
#+ignore(read-packet stream)))

(defun read-packet (stream)
(let ((buffer (make-array 8 :element-type '(unsigned-byte 8))))
(read-sequence buffer stream)
buffer))

My problem is in the read-packet form - I would like to read any reply
that is sent by the brick in response to the packet. I've tried a
couple of different ways to read from the device - looping until read-
byte fails and read-sequence both seem to simply wait forever. I am
assuming that they seem to hang because the "file" is a character
device and not a file-system file - there is no end-of-file condition
to tell the read-stuff functions that there is no more data. It could
also be that the USB receive queue is empty by the time the read-
sequence is called and the read is simply waiting for the next byte.

How do I read the response from the USB device? Eventually I would
like to be able to read much larger chunks of data from the brick, the
maximum would be 32KB as that is the size of the RAM on the device.
Any clues are appreciated.

You ay use CL:LISTEN to learn whether a byte is available or not.

Using CL:LISTEN and CL:READ-BYTE, you should be able to avoid blocking
in a portable way.

--
__Pascal Bourguignon__
http://www.informatimago.com
.



Relevant Pages

  • Talking to Mindstorms over USB
    ... package to send commands to the brick from my workstation. ... (with-open-file (stream port ... byte fails and read-sequence both seem to simply wait forever. ... How do I read the response from the USB device? ...
    (comp.lang.lisp)
  • Re: Contest Number on PowerFlarm (US)??
    ... It is easy to see if the parameters specifications that you uploaded has been accepted by the brick. ... Include this command in you config file: ... After power up has completed wait a couple of minutes then remove the USB device. ...
    (rec.aviation.soaring)