LibUSB on Raspberry Pi Linux

239 views
Skip to first unread message

Louis LaBrunda

unread,
Sep 27, 2024, 3:27:05 PM9/27/24
to VAST Community Forum
Hi,

Does anyone know how to install LibUSB on a Raspberry Pi Linux system and what name needs to go into the .ini file?

Lou

Louis LaBrunda

unread,
Sep 28, 2024, 4:08:49 PM9/28/24
to VAST Community Forum
Hi,

Adding the line below this gets me talking to the LinUSB interface.

LibUSB=/usr/lib/aarch64-linux-gnu/libusb-1.0.so

All the sunit tests work.

I think the problem described below is really has more to do with Linux than Smalltalk.  Seth and I wrote the interface to LibUSB.  We developed and tested it under Windows.  I don't think either one of us has tested it under Linux and probably not on a Raspberry Pi.  The program is intended to run on a Raspberry Pi because it utilizes its GPIO pins but I develop it mostly under windows and test the USB part there where it works just fine.  The trouble I have here is when I test it in the development environment on the Raspberry Pi.

First I try to clean things up (see below).  That fails with:

09/28/24 12:52:16 - Unable to release interface.
(ExKscLibUsbError) An exception has occurred: libusb_release_interface: (LIBUSB_ERROR_NOT_FOUND): Entity not found

This failure may be fine.  The handle may be old (from other testing).  So I move on to trying to check the LibUSB status and version and that seems fine.

Next I get a default context, which seems to work.
Next I get the device I'm Interested in, also seems to work.
Next I open the device and get a handle for the device, also seems to work.
Then I reset the device, also seems to work.
The I try to set the configuration, which fails:

09/28/24 12:52:16 - Unable to set configuration.
(ExKscLibUsbError) An exception has occurred: libusb_set_configuration: (LIBUSB_ERROR_BUSY): Resource busy

I will try to recreate the problem in a workspace but will have to try to find a USB device that most of us may have.

Thanks for any ideas.

Lou


cleanUpX10
"Clean up our X10 device connection."
| errorMsgStream |

errorMsgStream := String new writeStream.
x10Handle notNil ifTrue: [
[x10Handle releaseInterface: 0; close] on: Exception do: [:ex |
ex = ExHalt ifTrue: [ex signal].
errorMsgStream nextPutAll: 'Unable to release interface.'; cr; tab; nextPutAll: ex description; cr.
TtyLogClass log: errorMsgStream contents.
].
].

doX10Command: x10Action
"Do the X10 command: x10Action."
| errorMsgStream context x10Device command controlData codes |

self cleanUpX10.

errorMsgStream := String new writeStream.
"Perform libusb status check"
(KscLibUsbVersion printStatusCheckOn: errorMsgStream) ifFalse: [
errorMsgStream cr; nextPutAll: 'You either don''t have libusb-1.0..., don''t have it mapped in the ini... or the version you have is too old'.
^TtyLogClass log: errorMsgStream contents.
].

"Check that the default context is set"
[context := KscLibUsbContext default] on: Exception do: [:ex |
ex = ExHalt ifTrue: [ex signal].
^TtyLogClass log: 'Error...could not create context'.
].

"Get the X10 controller and a handle."
x10Device := context deviceForVendor: X10VendorId product: X10productId.

x10Handle := [x10Device open] on: Exception do: [:ex |
ex = ExHalt ifTrue: [ex signal].
errorMsgStream nextPutAll: 'Unable to open the device.'; cr; tab; nextPutAll: ex description; cr.
^TtyLogClass log: errorMsgStream contents.
].

[x10Handle resetDevice] on: Exception do: [:ex |
ex = ExHalt ifTrue: [ex signal].
errorMsgStream nextPutAll: 'Unable to reset the device.'; cr; tab; nextPutAll: ex description; cr.
^TtyLogClass log: errorMsgStream contents.
].

[x10Handle configuration: 1] on: Exception do: [:ex |
ex = ExHalt ifTrue: [ex signal].
errorMsgStream nextPutAll: 'Unable to set configuration.'; cr; tab; nextPutAll: ex description; cr.
^TtyLogClass log: errorMsgStream contents.
].

[x10Handle claimInterface: 0] on: Exception do: [:ex |
ex = ExHalt ifTrue: [ex signal].
errorMsgStream nextPutAll: 'Unable to claim interface.'; cr; tab; nextPutAll: ex description; cr.
^TtyLogClass log: errorMsgStream contents.
].

command := KscX10ControlData commandStringForHouse: x10Action house unit: x10Action unit verb: x10Action command asSymbol.
controlData := KscX10ControlData dataForCommand: command.
codes := controlData codes.
[x10Handle interuptTransfer: codes endpoint: 2 timeout: 1000] on: Exception do: [:ex |
ex = ExHalt ifTrue: [ex signal].
errorMsgStream := String new writeStream.
errorMsgStream nextPutAll: 'Unable to send the '; nextPutAll: codes size printString;
nextPutAll: ' bytes ('; nextPutAll: codes;
nextPutAll: ') to the CM19a.'; cr; tab; nextPutAll: ex description; cr.
TtyLogClass log: errorMsgStream contents.
ex exitWith: 0.
].

Louis LaBrunda

unread,
Sep 28, 2024, 6:18:36 PM9/28/24
to VAST Community Forum
I think I have this solved/working.  On Linux (at least raspberry Pi Linux) one has to libusb_detach_kernel_driver.  I'm not sure if I have to do anything else like put things back afterward.  Any information is appreciated.

Lou

Reply all
Reply to author
Forward
0 new messages