From: Frank Goenninger DG1SBG
Subject: USB I/O directly from Lisp ? Or libusb ?
Date: 
Message-ID: <m2d5eqdf9g.fsf@pcsde001.local>
Time to get the AVR ATmega32 microcontroller I just soldered together
running. I'd like to do this from my MacBook Pro which of course only
features USB and other stuff but no RS232C interface.

The microcontroller can be driven via a USB-to-RS232C converter - the
one I have is known working when driven by programs like UISP.

Sooo - I have that controller application being written in Lisp using
Cells and Cello2 and ... now - which lib / approach let's me talk to
USB devices, preferably via Lisp streams ... ? 

Anybode out there who has done that or a similar thing already? 

I know libusb < http://www.libusg.org > but of no (CFFI) bindings. 
I also know of the talk given by Frank Klassner at ILC2005 but he did
not respond to my emails.

I started writing CFFI bindings for libusb.

Still wondering if someone knows of better ways...

THX!

Frank

--
   Frank Goenninger
   Bempflingen, Germany
   Newbie, Level 2

From: marc spitzer
Subject: Re: USB I/O directly from Lisp ? Or libusb ?
Date: 
Message-ID: <slrne5sm5c.1qp.ms4720@sdf.lonestar.org>
On 2006-05-06, Frank Goenninger DG1SBG <·······@nomail.com> wrote:
> Time to get the AVR ATmega32 microcontroller I just soldered together
> running. I'd like to do this from my MacBook Pro which of course only
> features USB and other stuff but no RS232C interface.
>
> The microcontroller can be driven via a USB-to-RS232C converter - the
> one I have is known working when driven by programs like UISP.

Can you use kermit to get ot the device over the usb dongle?  It should
present you with a rs-232 device, or it does for me to windows laptop at
work.

marc

-- 
······@sdf.lonestar.org
SDF Public Access UNIX System - http://sdf.lonestar.org
From: Frank Goenninger DG1SBG
Subject: Re: USB I/O directly from Lisp ? Or libusb ?
Date: 
Message-ID: <m28xpccucb.fsf@pcsde001.local>
marc spitzer <······@sdf.lonestar.org> writes:

> On 2006-05-06, Frank Goenninger DG1SBG <·······@nomail.com> wrote:
>> Time to get the AVR ATmega32 microcontroller I just soldered together
>> running. I'd like to do this from my MacBook Pro which of course only
>> features USB and other stuff but no RS232C interface.
>>
>> The microcontroller can be driven via a USB-to-RS232C converter - the
>> one I have is known working when driven by programs like UISP.
>
> Can you use kermit to get ot the device over the usb dongle?  It should
> present you with a rs-232 device, or it does for me to windows laptop at
> work.

I can. Still, I'd like to have access via Lisp to do fancy stuff like
reading values from the controller, displaying them using Cells and
Cello2, sending values to the controller, monitoring the high voltage
power supply's parameters to stay within legal bounds (the controller
is working inside that power supply).

How does Kermit help here? (other than the OS presenting me a tty device I
am opening for writing and therefore emulating file access)

>
> marc
>

Thx for replying, Marc.

Cheers 
   Frank
From: marc spitzer
Subject: Re: USB I/O directly from Lisp ? Or libusb ?
Date: 
Message-ID: <slrne5v8ot.g36.ms4720@sdf.lonestar.org>
On 2006-05-08, Frank Goenninger DG1SBG <·······@microsoft.com> wrote:
> marc spitzer <······@sdf.lonestar.org> writes:
>
>> Can you use kermit to get ot the device over the usb dongle?  It should
>> present you with a rs-232 device, or it does for me to windows laptop at
>> work.
>
> I can. Still, I'd like to have access via Lisp to do fancy stuff like
> reading values from the controller, displaying them using Cells and
> Cello2, sending values to the controller, monitoring the high voltage
> power supply's parameters to stay within legal bounds (the controller
> is working inside that power supply).
>
> How does Kermit help here? (other than the OS presenting me a tty device I
> am opening for writing and therefore emulating file access)

To test if the rs232 device is working.  

You should be able to read and write from the device from lisp with
no external program needed.  You never need to speak USB just talk
to a device.   you may need to do some encoding and decoding to talk
to the device, but you should not need to use some thing "extra".

marc



-- 
······@sdf.lonestar.org
SDF Public Access UNIX System - http://sdf.lonestar.org
From: Frank Goenninger DG1SBG
Subject: Re: USB I/O directly from Lisp ? Or libusb ?
Date: 
Message-ID: <m2slnjbjqy.fsf@pcsde001.local>
marc spitzer <······@sdf.lonestar.org> writes:


> To test if the rs232 device is working.  
>
> You should be able to read and write from the device from lisp with
> no external program needed.  You never need to speak USB just talk
> to a device.   you may need to do some encoding and decoding to talk
> to the device, but you should not need to use some thing "extra".
>
> marc

Ah, right. So just forget USB and talk to the TTY device. This is what
Petter's code is also doing (provided in another post in this thread).

It will be interesting to see if I can open the TTY device more than
once from different processes (which should not be possible, of
course).

Thanks, Marc!

Frank
From: Thomas F. Burdick
Subject: Re: USB I/O directly from Lisp ? Or libusb ?
Date: 
Message-ID: <xcvslnkcmic.fsf@conquest.OCF.Berkeley.EDU>
Frank Goenninger DG1SBG <·······@nomail.com> writes:

> Time to get the AVR ATmega32 microcontroller I just soldered together
> running. I'd like to do this from my MacBook Pro which of course only
> features USB and other stuff but no RS232C interface.
> 
> The microcontroller can be driven via a USB-to-RS232C converter - the
> one I have is known working when driven by programs like UISP.
> 
> Sooo - I have that controller application being written in Lisp using
> Cells and Cello2 and ... now - which lib / approach let's me talk to
> USB devices, preferably via Lisp streams ... ? 
> 
> Anybode out there who has done that or a similar thing already? 
> 
> I know libusb < http://www.libusg.org > but of no (CFFI) bindings. 
> I also know of the talk given by Frank Klassner at ILC2005 but he did
> not respond to my emails.
> 
> I started writing CFFI bindings for libusb.
> 
> Still wondering if someone knows of better ways...

Have you tried Verranzano on the IOKit bindings?  If I were face with
the same situation, I'd wrap Apple's IOKit interface to get a
CLOSified version and use that.
From: Frank Goenninger DG1SBG
Subject: Re: USB I/O directly from Lisp ? Or libusb ?
Date: 
Message-ID: <m2zmhrbjzn.fsf@pcsde001.local>
···@conquest.OCF.Berkeley.EDU (Thomas F. Burdick) writes:

> Frank Goenninger DG1SBG <·······@nomail.com> writes:> 
>> Sooo - I have that controller application being written in Lisp using
>> Cells and Cello2 and ... now - which lib / approach let's me talk to
>> USB devices, preferably via Lisp streams ... ? 

> Have you tried Verranzano on the IOKit bindings?  If I were face with
> the same situation, I'd wrap Apple's IOKit interface to get a
> CLOSified version and use that.

Yep, very good point. As libusb also wraps the IOKit I will try to
CLOSsify the libusb API - one (so far not revealed here) requirement /
attempt is to stay platform indepenedent.

Frank
From: Petter Gustad
Subject: Re: USB I/O directly from Lisp ? Or libusb ?
Date: 
Message-ID: <87d5eow4fp.fsf@gustad.com>
Frank Goenninger DG1SBG <·······@nomail.com> writes:

> Sooo - I have that controller application being written in Lisp using
> Cells and Cello2 and ... now - which lib / approach let's me talk to
> USB devices, preferably via Lisp streams ... ? 

I've made an ISP PIC programmer driven by CMUCL under Linux. I don't
know if it is of much help, but here's some of the code I've been
using:

(defparameter *usb-dev* "/dev/tts/USB0" "filename for usb tty device")

(defmethod usb-open ((pic picdata) &optional (dev *usb-dev*))
  "open the usb serial device"
  (let ((fd (unix:unix-open dev unix:o_rdwr #o666)))
    (unless fd
      (error "unix-open error"))
    (setf (isdev pic) t)
    (setraw fd)
    (setf (ostream pic) 
          (system:make-fd-stream fd :name "picprog" 
                                 :input t :output t
                                 :element-type '(unsigned-byte 8)
                                 :buffering :none 
                                 :auto-close t)))
    pic)

setraw uses termios to set the file description in raw mode:

(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?
From: Frank Goenninger DG1SBG
Subject: Re: USB I/O directly from Lisp ? Or libusb ?
Date: 
Message-ID: <m24pzzcyrd.fsf@pcsde001.local>
Petter Gustad <·············@gustad.com> writes:

> Frank Goenninger DG1SBG <·······@nomail.com> writes:
>
>> Sooo - I have that controller application being written in Lisp using
>> Cells and Cello2 and ... now - which lib / approach let's me talk to
>> USB devices, preferably via Lisp streams ... ? 
>
> I've made an ISP PIC programmer driven by CMUCL under Linux. I don't
> know if it is of much help, but here's some of the code I've been
> using:
>
[snipped some very helpful code]

>
> Petter

Thanks, Petter! It indeed provided some insigthts on raw I/O and
stuff.

Frank