erjiang / usbscale

Reads weight data from USB scales.
GNU General Public License v3.0
90 stars 22 forks source link

Does not compile in OS X Mavericks 10.9.1 #5

Closed staze closed 10 years ago

staze commented 10 years ago

Sure this wasn't an OS you targeted, but it would be cool if it worked.

make gives the following:

gcc -Os -Wall usbscale.c scales.h -lm -lusb-1.0 -o usbscale clang: error: cannot specify -o when generating multiple output files make: *\ [usbscale] Error 1

This is the issue, I think: http://stackoverflow.com/questions/19913319/osx-mavericks-causes-cannot-specify-o-when-generating-multiple-output-files

But, I'm not a C expert, so I'm not exactly sure what this means. I think it has to do with the Makefile line, but changing that doesn't seem to progress anything.

Thoughts?

erjiang commented 10 years ago

Based at the stackoverflow link, I tried changing the Makefile to rely less on Make magic. That is, the rule is now hardcoded to exclude the header file, probably because I'm using the header file in a slightly non-standard way. Can you try it?

Also, how did you set up libusb for Mac? I just got access to a Mac recently so I might have some time to try it in the future.

staze commented 10 years ago

okay, I must be blind... I'm not seeing the makefile having a new commit. Or should I change something on the master download?

erjiang commented 10 years ago

Sorry, that's my fault. The push didn't go through. This time I actually double-checked Github and it's there:

https://github.com/erjiang/usbscale/commit/82cab8804b4765c1f01760b8d9f5e27e88141afd

staze commented 10 years ago

Okay, so, tried a make, and first time it said it couldn't find libusb-1.0/libusb.h.

gcc -Os -Wall usbscale.c -lm -lusb-1.0 -o usbscale usbscale.c:37:10: fatal error: 'libusb-1.0/libusb.h' file not found

include <libusb-1.0/libusb.h>

     ^

1 error generated. make: *\ [usbscale] Error 1

So, copied the libusb directory out of the libusb-1.0.9 source directory into usbscale-master as libusb-1.0. Then a make turns up:

gcc -Os -Wall usbscale.c -lm -lusb-1.0 -o usbscale usbscale.c:37:10: error: 'libusb-1.0/libusb.h' file not found with include; use "quotes" instead

include <libusb-1.0/libusb.h>

     ^~~~~~~~~~~~~~~~~~~~~
     "libusb-1.0/libusb.h"

1 error generated. make: *\ [usbscale] Error 1

So, I changed those angles to quotes, and then it gives:

gcc -Os -Wall usbscale.c -lm -lusb-1.0 -o usbscale ld: library not found for -lusb-1.0 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *\ [usbscale] Error 1

Now, I have no idea where to go.

erjiang commented 10 years ago

You need to have the libusb library on your computer - that's another adventure altogether. A quick search on Google turned up this that could work: http://libusbx.org/

staze commented 10 years ago

I did get the source (libusb-1.0.9), did a configure, make, and install. This was all before even trying to build usbscale.

libusb is in /usr/local/include/libusb-1.0

Changed the include in usbscale.c to be the full /usr/local/include/libusb-1.0/libusb.h, and still get:

gcc -Os -Wall usbscale.c -lm -lusb-1.0 -o usbscale ld: library not found for -lusb-1.0 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *\ [usbscale] Error 1

tried adding -I /usr/local/include/ to the CFLAGS in the makefile, no luck.

erjiang commented 10 years ago

The flag "-lusb-1.0" causes gcc to look for a library file called "libusb-1.0.a". The places it searches are all the standard locations plus any specified by "-L/path/to/additional/dir". Maybe you can try searching your Mac for a file called "libusb-1.0.a"?

staze commented 10 years ago

yeah, /usr/local/lib/libusb-1.0.a.

Hmm, so, finding that, I changed CFLAGS to read:

CFLAGS=-Os -Wall -L/usr/local/lib/ -I /usr/local/include/

and it built!

But... running it results in:

Error in USB transfer

Even with sudo. The scale is the stamps.com 510, Product ID: 0x6a73, Vendor ID: 0x1446. =/

Recompiled with debug, and it would seem to indicate something else has USB tied up (nothing that I know of). Here's the complete "dump"... thoughts?

libusb: 0.000000 info [process_new_device] allocating new device for location 0x15000000 libusb: 0.000080 info [darwin_check_configuration] active config: 1, first config: 1 libusb: 0.000089 warning [process_new_device] Got unknown device speed 3 libusb: 0.000110 info [process_new_device] found device with address 128 at 128-05ac-8007-09-00 libusb: 0.000526 info [process_new_device] allocating new device for location 0x1a000000 libusb: 0.000580 info [darwin_check_configuration] active config: 1, first config: 1 libusb: 0.000591 info [process_new_device] found device with address 1 at 001-05ac-8006-09-00 libusb: 0.000973 info [process_new_device] allocating new device for location 0x14000000 libusb: 0.001025 info [darwin_check_configuration] active config: 1, first config: 1 libusb: 0.001035 info [process_new_device] found device with address 129 at 129-05ac-8007-09-00 libusb: 0.001404 info [process_new_device] allocating new device for location 0x1d000000 libusb: 0.001456 info [darwin_check_configuration] active config: 1, first config: 1 libusb: 0.001467 info [process_new_device] found device with address 1 at 001-05ac-8006-09-00 libusb: 0.001825 info [process_new_device] allocating new device for location 0x1a100000 libusb: 0.001996 info [darwin_check_configuration] active config: 1, first config: 1 libusb: 0.002005 info [process_new_device] found device with address 2 at 002-8087-0024-09-00 libusb: 0.002327 info [process_new_device] allocating new device for location 0x1d100000 libusb: 0.002496 info [darwin_check_configuration] active config: 1, first config: 1 libusb: 0.002505 info [process_new_device] found device with address 2 at 002-8087-0024-09-00 libusb: 0.002822 info [process_new_device] allocating new device for location 0x1d180000 libusb: 0.002992 info [darwin_check_configuration] active config: 1, first config: 1 libusb: 0.003003 info [process_new_device] found device with address 3 at 003-0424-2512-09-00 libusb: 0.003388 info [process_new_device] allocating new device for location 0x1d181000 libusb: 0.192026 info [process_new_device] allocating new device for location 0x1a110000 libusb: 0.193318 info [darwin_check_configuration] active config: 1, first config: 1 libusb: 0.193358 info [process_new_device] found device with address 3 at 003-05ac-8510-ef-02 libusb: 0.194246 info [process_new_device] allocating new device for location 0x1d182000 libusb: 0.195144 info [darwin_check_configuration] active config: 1, first config: 1 libusb: 0.195194 info [process_new_device] found device with address 5 at 005-05ac-0249-00-00 libusb: 0.195880 info [process_new_device] allocating new device for location 0x1d181300 libusb: 0.382856 warning [darwin_cache_device_descriptor] could not retrieve device descriptor 05ac:821f: device not responding. skipping device libusb: 0.384443 info [process_new_device] allocating new device for location 0x1a120000 libusb: 0.385451 info [darwin_check_configuration] active config: 3, first config: 1 libusb: 0.385475 info [process_new_device] found device with address 4 at 004-05ac-12a8-00-00 libusb: 0.386319 info [process_new_device] allocating new device for location 0x14100000 libusb: 0.399118 info [darwin_check_configuration] active config: 1, first config: 1 libusb: 0.399202 info [process_new_device] found device with address 1 at 001-1446-6a73-00-00 Found scale 1446:6a73 (bus 20, device 1) It has descriptors: manufc: 1 prodct: 2 serial: 3 class: 0 subclass: 0 libusb: 0.400853 info [darwin_open] device open for access libusb: 0.402897 info [darwin_async_io_callback] an async io operation has completed libusb: 0.402985 info [op_handle_events] checking fd 4 with revents = 0 libusb: 0.403003 info [op_handle_events] checking fd 6 with revents = 1 libusb: 0.403018 info [darwin_handle_callback] handling control completion with kernel status 0 libusb: 0.409848 info [darwin_async_io_callback] an async io operation has completed libusb: 0.409950 info [op_handle_events] checking fd 4 with revents = 0 libusb: 0.409977 info [op_handle_events] checking fd 6 with revents = 1 libusb: 0.409999 info [darwin_handle_callback] handling control completion with kernel status 0 Manufacturer: ELANE libusb: 0.411569 info [darwin_open] device open for access libusb: 0.412142 error [darwin_claim_interface] USBInterfaceOpen: another process has device opened for exclusive access libusb: 0.412159 info [ep_to_pipeRef] converting ep address 0x81 to pipeRef and interface libusb: 0.412163 warning [ep_to_pipeRef] no pipeRef found with endpoint address 0x81. libusb: 0.412168 error [submit_bulk_transfer] endpoint not found on any open interface libusb: 0.412175 info [ep_to_pipeRef] converting ep address 0x81 to pipeRef and interface libusb: 0.412178 warning [ep_to_pipeRef] no pipeRef found with endpoint address 0x81. libusb: 0.412182 error [submit_bulk_transfer] endpoint not found on any open interface Error in USB transfer libusb: 0.412377 info [event_thread_main] thread exiting

rspeed commented 10 years ago

I was able to compile no problem on 10.9.1 using libusb installed via homebrew. Getting the same "Error in USB transfer" message.

Edit: The scale is a Mettler Toledo PS60

erjiang commented 10 years ago

One enhancement to try would be to print out the return code when it says "Error in USB transfer" to match up against the list of libusb error codes. I'm not sure why I didn't do that already.

staze commented 10 years ago

I could be completely off base, but I'm wondering if this might be related to what we're seeing: http://www.libusb.org/ticket/89

staze commented 10 years ago

looking more likely. here's info on codeless kext: https://developer.apple.com/library/mac/documentation/Darwin/Conceptual/KEXTConcept/KEXTConceptAnatomy/kext_anatomy.html

going to try this tomorrow. for now, need sleep.

erjiang commented 10 years ago

So if that bug discussion is true, then that would prevent usbscale from working (since usbscale is a user-space program accessing an HID device). I'm going to close this for now, but if a solution is found, then we can definitely try to integrate it.