FreeBSD port

Supporting 2.6 and up
brooks

FreeBSD port

Postby brooks » Fri Nov 25, 2005 8:29 pm

I've created a port of the Linux version to FreeBSD under the ports framework. The major changes were removal of all refrences to the embeded copy of libusb so that the FreeBSD port can be used and a large patch to chidlinux.cpp which rewrites CHIDOpenHandle(). The rewrite addresses some missing error handling that was causing crashes on FreeBSD as well as using continue statements instead of nested if statements to reduce the level of indents so I could read the code more easily. That change should be portable. The patch is here:

http://perforce.freebsd.org/fileViewer.cgi?FSPC=//depot/user/brooks/ports/phidget20/files/patch%2dchidlinux.cpp&REV=1

I've been able to run a hacked up copy of InterfacekitTest.cpp and an unmodified version of IFKex1.java with my Interface Kit 8/8/8. I haven't done anything actually useful though. At this point, users should avoid unplugging their devices when using them since this causes a kernel panic (this is not a Phidget problem). It is also necessicary to not the uhid driver in your kernel or loaded so the devices won't be bound as hid devices. I plan to add some sort of blacklist support to the uhid driver in the future.

I plan to commit the port to the FreeBSD ports collection shortly so others can try it out. If possible, I'd like permission to let the source files be mirrored on the FreeBSD mirror sites rather than forcing everyone to to through phidgets.com.

-- Brooks

fitchett
Site Admin
Posts: 262
Joined: Fri Dec 05, 2003 3:45 pm
Location: Canada
Contact:

Postby fitchett » Fri Nov 25, 2005 9:06 pm

We'll review your work and consider adding a chidbsd.cpp to our source distribution.

I'm sure we can give permission to distribute your port; but I'll have to discuss it first.

Chester

brooks

Postby brooks » Fri Nov 25, 2005 10:57 pm

A chidbsd.cpp shouldn't be necessicary. I just fixed some error handling and refactored a bit relative to the linux version. A more generic name like chidlibusb might be appropriate.

For distribution there are several levels that various ports support:
- No automatic distribution. This is usually commercial or very weirdly licensed software.
- Automatic download of source files, but no mirroring or pre-built packages (this is how I currently have the port configured).
- Automatic download and mirroring on FreeBSD servers of source files, but don't distribute pre-built packages.
- Distribute pre-built packages and source via mirror servers, but don't include on CDs (usually due to a "no for-profit distribution" clause, we often get specific exceptions for inclusion as part of a package set since a package is only one of nearly 14000 so the total "profit" from a given package is likely quite small)
- Full distribution where we distribute source files and pre-built packages on our mirror network and on CD/DVD distributions by vendors who sell FreeBSD on media.

Thanks,
Brooks

Guest

Postby Guest » Wed Mar 15, 2006 8:22 pm

What's the state with the FreeBSD port? I'm noticing that it's not in the BSD port tree and I'm not seeing any other mention of FreeBSD versions/patches anywhere else on Phidgets.com.

Guest

Postby Guest » Mon May 15, 2006 4:41 am

yes, please let us know the status

mgades

FreeBSD status

Postby mgades » Mon Aug 20, 2007 2:48 pm

Is there any possibility to get the Phidget running in FreeBSD (6.2)?
I guess it will just be a minor rewrite somewhere. The device shows up in /var/log/messages when I plug it in, but I get no output from either ./examples/ifkit or ./examples/manager:

Code: Select all

Aug 20 21:39:01 lagavulin kernel: uhub2: vendor 0x0451 product 0x2046, class 9/0, rev 1.10/1.25, addr 2
Aug 20 21:39:01 lagavulin kernel: uhub2: 4 ports with 4 removable, self powered
Aug 20 21:39:02 lagavulin kernel: uhid0: Phidgets Inc. PhidgetInterfaceKit, rev 1.10/8.17, addr 3, iclass 3/0

[root@lagavulin ~]# usbdevs
addr 1: UHCI root hub, VIA
 addr 2: product 0x2046, vendor 0x0451
  addr 3: PhidgetInterfaceKit, Phidgets Inc.
addr 1: EHCI root hub, VIA


Am I missing something? Googling "freebsd phidget" doesn't lead me anywhere useful.

Thanks in advance!
Morten

User avatar
Patrick
Lead Developer
Posts: 3100
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Postby Patrick » Mon Aug 20, 2007 5:09 pm

Download libusb and run configure. Then stick the source files into the libusb folder of the phidget library, add bsd.c and remove linux.c from the phidget21 Makefile and make the phidgets library. If LibUSB is well-written, this should just work, but I've never tried it.

-Patrick

mgades

Postby mgades » Mon Aug 20, 2007 5:45 pm

Hi there

Thanks for the rapid reply - i copied the sources from the ports distfiles, ran configure and copied everything to phidget21/libusb. Replaced linux.c with bsd.c in the phidget21/Makefile and ran gmake. Everything compiled and linked fine and the library was installed by 'gmake install'.

But when I try to 'gmake -lphidget21 ifkit' in phidget21/examples I get the following error:

Code: Select all

/usr/lib/libphidget21.so: undefined reference to `usb_cleanup'

mgades

Postby mgades » Mon Aug 20, 2007 5:52 pm

mgades wrote:But when I try to 'gmake -lphidget21 ifkit' in phidget21/examples I get the following error:

Code: Select all

/usr/lib/libphidget21.so: undefined reference to `usb_cleanup'


I commented out the reference to usb_cleanup() in cusblinux.c and it compiled fine. Though still no luck in contacting the device...

I'll get some sleep and look in to it tomorrow :)

mgades

Postby mgades » Tue Aug 21, 2007 9:53 am

I can't seem to get further.

The following code exits with "0 Phidget Devices attached.".

Code: Select all

#include <stdio.h>
#include <phidget21.h>

int gotDetach(CPhidgetHandle phid, void *ptr);
int gotAttach(CPhidgetHandle phid, void *ptr);

int main(void)
{
   int deviceCount, i, serialNumber, version;
   const char *type;
   CPhidgetManagerHandle manager;
   CPhidgetHandle *phidgetDevices;
       
   // Create & Open the PhidgetManager
   CPhidgetManager_create(&manager);
   CPhidgetManager_set_OnAttach_Handler(manager, gotAttach, NULL);
   CPhidgetManager_set_OnDetach_Handler(manager, gotDetach, NULL);
   CPhidgetManager_open(manager);
   
   // Get info about the attached devices
   CPhidgetManager_getAttachedDevices(manager, &phidgetDevices, &deviceCount);
   
   printf("%d Phidget Devices attached.\n", deviceCount);
   for(i = 0; i < deviceCount; i++)
   {
      CPhidget_getDeviceType(phidgetDevices[i], &type);
      CPhidget_getSerialNumber(phidgetDevices[i], &serialNumber);
      CPhidget_getDeviceVersion(phidgetDevices[i], &version);
      printf("\t(%d): %s (s/n: %d, ver: %d)\n", i, type, serialNumber, version);
   }
   
   
   return 0;
}

int gotAttach(CPhidgetHandle phid, void *ptr)
{
   char *id;
   int serial, version;
   int status;
   
   //print out some info 
   CPhidget_getSerialNumber(phid, &serial);
   CPhidget_getDeviceVersion(phid, &version);
   CPhidget_getDeviceStatus(phid, &status);
   CPhidget_getDeviceType((CPhidgetHandle)phid,(const char **)&id);
   printf("Device Added: %s, Serial: %d, Version: %d, Status: %s\n",id,serial,version, status? "Attached" : "Not Attached");
   
   return 0;
}

int gotDetach(CPhidgetHandle phid, void *ptr)
{
   char *id;
   int serial, version;
   
   //print out some info     
   CPhidget_getSerialNumber(phid, &serial);
   CPhidget_getDeviceVersion(phid, &version);
   CPhidget_getDeviceType((CPhidgetHandle)phid,(const char **)&id);
   printf("Device Removed: %s, Serial: %d, Version: %d\n",id,serial,version);
   
   return 0;
}


How is the phidget21 lib interfacing the USB bus other than through libusb?

What else would I need to look at?[/code]


Return to “Linux”

Who is online

Users browsing this forum: No registered users and 1 guest