QHYCCD

Using libusb on mac for QHY5L-II

Using libusb on mac for QHY5L-II
« on: October 03, 2017, 03:02:10 am »
Alright; I wish to thank Coolios for giving the examples on Windows 7, and then my life turned away for a while.

Now I am starting back up on this project, and have switched to my Mac because it has a more comfortable working environment for me.  I have created simple programs to learn to use libusb-1.0, and I can successfully query the devices, configurations, interfaces, and endpoints.  On other devices, not the cameras, this information seems correct.  For the cameras, some of it seems confusing.  I have questions:

1.  Is there anything that needs to be uploaded to the camera when I attach it to the Mac?  On windows, I see "Installing device driver" in a popup window; I do not know if that means the driver is being installed into the OS, or if there is something being uploaded to the camera.

2.  For the QHY5L-II, I see one device with one configuration with one interface, and then 4 AltSettings.  Is that what I should expect?

3. For the QHY163M, I see one device with one configuration and one interface, with AltSetting that has no endpoints.  That seems wrong.  Could these be because there is not enough power provided on this USB port?

4. I cannot write to either camera.  I do not do any initialization or configuration except claiming the interface.  I will post the code and the output for the QHY5L-II.

Thanks for any suggestions!

Re: Using libusb on mac for QHY5L-II
« Reply #1 on: October 03, 2017, 03:23:05 am »
This is the output when I query the details of the QHY5L-II:

Code: [Select]
Supports Capability        = Yes
Supports HotPlug           = Yes
Supports HIDAccess         = No
Supports DetachDriver      = No

Device [0]
    USBRelease             =   512 : x0200
    DeviceClass            = Vendor-specific
    DeviceSubClass         = 255 : xFF
    DeviceProtocol         = 255 : xFF
    MaxPacketSize0         =  64 : x40
    Vendor                 =  5656 : x1618
    Product                =  2336 : x0920
    DeviceRelease          =     0 : x0000
    Manufacturer           = (undefined)
    Product                = (undefined)
    Serial Number          = (undefined)
    NumConfiguration       = 1
    Bus                    =  29 : x1D
    Port                   =   3 : x03
    Ports                  = 001:x01 003:x03
    DeviceAddress          =   5 : x05
    Speed                  = High
    Config [0]
        NumInterfaces          =   1 : x01
        ConfigValue            =   1 : x01
        Config                 = (undefined)
        Attributes             = x80
        MaxPower               = 50
        Extra                  = []
        Interface [0]
            NumAltsettings         = 4
            AltSetting [0]
                InterfaceNumber        = 0
                AlternateSetting       =   0 : x00
                NumEndpoints           = 0
                InterfaceClass         = 255 : xFF
                InterfaceSubClass      = 255 : xFF
                InterfaceProtocol      = 255 : xFF
                Interface              = (undefined)
                Extra                  = []
            AltSetting [1]
                InterfaceNumber        = 0
                AlternateSetting       =   1 : x01
                NumEndpoints           = 6
                InterfaceClass         = 255 : xFF
                InterfaceSubClass      = 255 : xFF
                InterfaceProtocol      = 255 : xFF
                Interface              = (undefined)
                Extra                  = []
                EndPoint [0]
                    Address                =   1 : x01
                    Attributes             = x0002
                    MaxPacketSize          = 512
                    Interval               = 0
                    Refresh                = 0
                    SyncAddress            =   0 : x00
                    Extra                  = []
                EndPoint [1]
                    Address                = 129 : x81
                    Attributes             = x0002
                    MaxPacketSize          = 512
                    Interval               = 0
                    Refresh                = 0
                    SyncAddress            =   0 : x00
                    Extra                  = []
                EndPoint [2]
                    Address                =   2 : x02
                    Attributes             = x0002
                    MaxPacketSize          = 512
                    Interval               = 0
                    Refresh                = 0
                    SyncAddress            =   0 : x00
                    Extra                  = []
                EndPoint [3]
                    Address                =   4 : x04
                    Attributes             = x0002
                    MaxPacketSize          = 512
                    Interval               = 0
                    Refresh                = 0
                    SyncAddress            =   0 : x00
                    Extra                  = []
                EndPoint [4]
                    Address                = 134 : x86
                    Attributes             = x0002
                    MaxPacketSize          = 512
                    Interval               = 0
                    Refresh                = 0
                    SyncAddress            =   0 : x00
                    Extra                  = []
                EndPoint [5]
                    Address                = 136 : x88
                    Attributes             = x0002
                    MaxPacketSize          = 512
                    Interval               = 0
                    Refresh                = 0
                    SyncAddress            =   0 : x00
                    Extra                  = []
            AltSetting [2]
                InterfaceNumber        = 0
                AlternateSetting       =   2 : x02
                NumEndpoints           = 6
                InterfaceClass         = 255 : xFF
                InterfaceSubClass      = 255 : xFF
                InterfaceProtocol      = 255 : xFF
                Interface              = (undefined)
                Extra                  = []
                EndPoint [0]
                    Address                =   1 : x01
                    Attributes             = x0003
                    MaxPacketSize          = 64
                    Interval               = 1
                    Refresh                = 0
                    SyncAddress            =   0 : x00
                    Extra                  = []
                EndPoint [1]
                    Address                = 129 : x81
                    Attributes             = x0003
                    MaxPacketSize          = 64
                    Interval               = 1
                    Refresh                = 0
                    SyncAddress            =   0 : x00
                    Extra                  = []
                EndPoint [2]
                    Address                =   2 : x02
                    Attributes             = x0003
                    MaxPacketSize          = 512
                    Interval               = 1
                    Refresh                = 0
                    SyncAddress            =   0 : x00
                    Extra                  = []
                EndPoint [3]
                    Address                =   4 : x04
                    Attributes             = x0002
                    MaxPacketSize          = 512
                    Interval               = 0
                    Refresh                = 0
                    SyncAddress            =   0 : x00
                    Extra                  = []
                EndPoint [4]
                    Address                = 134 : x86
                    Attributes             = x0003
                    MaxPacketSize          = 512
                    Interval               = 1
                    Refresh                = 0
                    SyncAddress            =   0 : x00
                    Extra                  = []
                EndPoint [5]
                    Address                = 136 : x88
                    Attributes             = x0002
                    MaxPacketSize          = 512
                    Interval               = 0
                    Refresh                = 0
                    SyncAddress            =   0 : x00
                    Extra                  = []
            AltSetting [3]
                InterfaceNumber        = 0
                AlternateSetting       =   3 : x03
                NumEndpoints           = 6
                InterfaceClass         = 255 : xFF
                InterfaceSubClass      = 255 : xFF
                InterfaceProtocol      = 255 : xFF
                Interface              = (undefined)
                Extra                  = []
                EndPoint [0]
                    Address                =   1 : x01
                    Attributes             = x0003
                    MaxPacketSize          = 64
                    Interval               = 1
                    Refresh                = 0
                    SyncAddress            =   0 : x00
                    Extra                  = []
                EndPoint [1]
                    Address                = 129 : x81
                    Attributes             = x0003
                    MaxPacketSize          = 64
                    Interval               = 1
                    Refresh                = 0
                    SyncAddress            =   0 : x00
                    Extra                  = []
                EndPoint [2]
                    Address                =   2 : x02
                    Attributes             = x0001
                    MaxPacketSize          = 512
                    Interval               = 1
                    Refresh                = 0
                    SyncAddress            =   0 : x00
                    Extra                  = []
                EndPoint [3]
                    Address                =   4 : x04
                    Attributes             = x0002
                    MaxPacketSize          = 512
                    Interval               = 0
                    Refresh                = 0
                    SyncAddress            =   0 : x00
                    Extra                  = []
                EndPoint [4]
                    Address                = 134 : x86
                    Attributes             = x0001
                    MaxPacketSize          = 512
                    Interval               = 1
                    Refresh                = 0
                    SyncAddress            =   0 : x00
                    Extra                  = []
                EndPoint [5]
                    Address                = 136 : x88
                    Attributes             = x0002
                    MaxPacketSize          = 512
                    Interval               = 0
                    Refresh                = 0
                    SyncAddress            =   0 : x00
                    Extra                  = []

Re: Using libusb on mac for QHY5L-II
« Reply #2 on: October 03, 2017, 03:24:50 am »
This is the code I'm using to try to read and write to the QHY5L-II:

Code: [Select]
...

#define QHY 0x1618
#define QHY5L_II_M 2336
#define QHY163M 0xC163

int main (int argc, char *argv [])
{
    libusb_context *ctx = 0;
    setbuf (stdout, NULL);

    Pcheck (libusb_init (&ctx));
    libusb_set_debug (ctx, 4);
    uint32_t c;
    printf ("Supports Capability = %s\n", YesNo (libusb_has_capability (LIBUSB_CAP_HAS_CAPABILITY)));
    printf ("Supports HotPlug = %s\n", YesNo (libusb_has_capability (LIBUSB_CAP_HAS_HOTPLUG)));
    printf ("Supports HIDAccess = %s\n", YesNo (libusb_has_capability (LIBUSB_CAP_HAS_HID_ACCESS)));
    printf ("Supports DetachDriver = %s\n", YesNo (libusb_has_capability (LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER)));
    printf ("\n");

    libusb_device **devlist;
    ssize_t ndev = libusb_get_device_list (ctx, &devlist);

    libusb_device *dev = 0;
    libusb_device_descriptor desc;
    for (int i = 0; i < ndev; ++i) {
Pcheck (libusb_get_device_descriptor (devlist [i], &desc));

switch (desc.idVendor) {
case QHY:
    switch (desc.idProduct) {
    case QHY5L_II_M:
    case QHY163M:
dev = devlist [i];
break;
    default:
printf ("Unrecognized QHY camera %d/%d ignored\n", desc.idVendor, desc.idProduct);
    }
}
    }
    if (dev == 0) {
printf ("No camera found.\n");
exit (1);
    }

    Pcheck (libusb_get_device_descriptor (dev, &desc));

    libusb_device_handle *cam;
    Pcheck (libusb_open (dev, &cam));

    printf ("Camera %04x/%04x found and opened.\n", desc.idVendor, desc.idProduct);
    // libusb_free_device_list (devlist, 1);

    int cx;
    Pcheck (libusb_get_configuration (cam, &cx));
    printf ("Current configuration = %d\n", cx);

    printf ("Claiming...\n");
    Pcheck (libusb_claim_interface (cam, 0));

    sleep (3);

    unsigned int TimeOut = 3000;
    unsigned char buff [1024];

    memset (buff, '\0', sizeof (buff));

    int e;
    unsigned req = 0x00 | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE;

    printf ("Reading...\n");
    e = libusb_control_transfer (cam, 0x80 | req,
0xD2, 0, 0, buff, 64, TimeOut);
    printf ("%s\n", ByteString (buff, 64));

    memset (buff, '\0', sizeof (buff));
    buff [0] = 0xA0;
    buff [1] = 0x01;
    buff [2] = 0x00;
    buff [3] = 0x01;
    buff [4] = 0x00;
    buff [5] = 0x01;

    printf ("Writing...\n");
    e = libusb_control_transfer (cam, req, 0xD1, 0, 0, buff, 16, TimeOut);
    Pcheck (e);

    libusb_close (cam);

    libusb_exit (ctx);
    return 0;
}

Re: Using libusb on mac for QHY5L-II
« Reply #3 on: October 03, 2017, 03:26:06 am »
Here is the output when I try to read or write from the QHY5L-II:

Code: [Select]
Supports Capability = Yes
Supports HotPlug = Yes
Supports HIDAccess = No
Supports DetachDriver = No

[timestamp] [threadID] facility level [function call] <message>
--------------------------------------------------------------------------------
[ 0.012670] [00000513] libusb: debug [libusb_get_device_list]
[ 0.012708] [00000513] libusb: debug [discovered_devs_append] need to increase capacity
[ 0.012721] [00000513] libusb: debug [libusb_get_device_descriptor]
[ 0.012725] [00000513] libusb: debug [libusb_get_device_descriptor]
[ 0.012728] [00000513] libusb: debug [libusb_get_device_descriptor]
[ 0.012731] [00000513] libusb: debug [libusb_get_device_descriptor]
[ 0.012734] [00000513] libusb: debug [libusb_get_device_descriptor]
[ 0.012737] [00000513] libusb: debug [libusb_get_device_descriptor]
[ 0.012741] [00000513] libusb: debug [libusb_get_device_descriptor]
[ 0.012744] [00000513] libusb: debug [libusb_get_device_descriptor]
[ 0.012747] [00000513] libusb: debug [libusb_get_device_descriptor]
[ 0.012750] [00000513] libusb: debug [libusb_get_device_descriptor]
[ 0.012753] [00000513] libusb: debug [libusb_get_device_descriptor]
[ 0.012756] [00000513] libusb: debug [libusb_get_device_descriptor]
[ 0.012759] [00000513] libusb: debug [libusb_get_device_descriptor]
[ 0.012763] [00000513] libusb: debug [libusb_get_device_descriptor]
[ 0.012766] [00000513] libusb: debug [libusb_open] open 29.5
[ 0.012885] [00000513] libusb: debug [darwin_open] device open for access
Camera 1618/0920 found and opened.
[ 0.012903] [00000513] libusb: debug [libusb_get_configuration]
[ 0.012910] [00000513] libusb: debug [libusb_get_configuration] active config 1
Current configuration = 1
Claiming...
[ 0.012923] [00000513] libusb: debug [libusb_claim_interface] interface 0
[ 0.013414] [00000513] libusb: debug [get_endpoints] building table of endpoints.
[ 0.013445] [00000513] libusb: debug [darwin_claim_interface] interface opened
Reading...
[ 3.018197] [00000513] libusb: debug [libusb_alloc_transfer] transfer 0x7fae89e00c08
[ 3.018207] [00000513] libusb: debug [libusb_submit_transfer] transfer 0x7fae89e00c08
[ 3.018268] [00000513] libusb: debug [libusb_get_next_timeout] no URB with timeout or all handled by OS; no timeout!
[ 3.018282] [00000513] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 3.018290] [00000513] libusb: debug [handle_events] poll fds modified, reallocating
[ 3.018301] [00000513] libusb: debug [handle_events] poll() 1 fds with timeout in 60000ms
[ 6.514857] [00000a0f] libusb: debug [darwin_async_io_callback] an async io operation has completed
[ 6.514901] [00000513] libusb: debug [handle_events] poll() returned 1
[ 6.514914] [00000513] libusb: debug [handle_events] caught a fish on the event pipe
[ 6.514919] [00000513] libusb: debug [darwin_handle_transfer_completion] handling control completion with kernel status -536854447
[ 6.514923] [00000513] libusb: warning [darwin_transfer_status] transfer error: timed out
[ 6.514927] [00000513] libusb: debug [usbi_handle_transfer_completion] transfer 0x7fae89e00c08 has callback 0x10de5b0c4
[ 6.514931] [00000513] libusb: debug [sync_transfer_cb] actual_length=0
[ 6.514947] [00000513] libusb: debug [libusb_free_transfer] transfer 0x7fae89e00c08
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Writing...
[ 6.514973] [00000513] libusb: debug [libusb_alloc_transfer] transfer 0x7fae89f00338
[ 6.514977] [00000513] libusb: debug [libusb_submit_transfer] transfer 0x7fae89f00338
[ 6.515036] [00000513] libusb: debug [libusb_get_next_timeout] no URB with timeout or all handled by OS; no timeout!
[ 6.515042] [00000513] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 6.515045] [00000513] libusb: debug [handle_events] poll() 1 fds with timeout in 60000ms
[10.517777] [00000a0f] libusb: debug [darwin_async_io_callback] an async io operation has completed
[10.517820] [00000513] libusb: debug [handle_events] poll() returned 1
[10.517849] [00000513] libusb: debug [handle_events] caught a fish on the event pipe
[10.517855] [00000513] libusb: debug [darwin_handle_transfer_completion] handling control completion with kernel status -536854447
[10.517859] [00000513] libusb: warning [darwin_transfer_status] transfer error: timed out
[10.517863] [00000513] libusb: debug [usbi_handle_transfer_completion] transfer 0x7fae89f00338 has callback 0x10de5b0c4
[10.517867] [00000513] libusb: debug [sync_transfer_cb] actual_length=0
[10.517873] [00000513] libusb: debug [libusb_free_transfer] transfer 0x7fae89f00338
Operation timed out

QiuHY

  • *****
  • 4833
    • View Profile
    • Email
Re: Using libusb on mac for QHY5L-II
« Reply #4 on: October 03, 2017, 01:17:57 pm »
Hello,

       Please make sure that you have upload the firmware of that with the low level protocol version. These version can be found in the forum board low level protocol. If you find these HEX or IMG file from other position, maybe not the correct version which has included the low level protocol codes.


Best regards,
Qiu Hongyun
Qiu Hongyun

Re: Using libusb on mac for QHY5L-II
« Reply #5 on: November 21, 2017, 06:24:16 pm »
Hadn't noticed this post until just now.

As far as I'm aware (have tested it in the past, but just upgraded to High Sierra and don't have everything reinstalled yet), oacapture works on OSX with the QHY5L-II.  It uses libusb to communicate with the camera, but recognises when the firmware isn't loaded and makes a call to a copy of the fxload binary to load the firmware if necessary.  The driver was written a few years back when documentation was scant, but I haven't got around to revisiting the code yet.

Source for oacapture is here if you wish to poke about and see how I did it: https://github.com/openastroproject/openastro

Binaries for MacOS can be downloaded from http://www.openastroproject.org/downloads/ but if you have the necessary bits installed from macports then the sources do build (again, untested as yet on High Sierra) and there's a script to make a DMG.  I believe they should work on anything from Snow Leopard onwards.

You do need a recent release of libusb if you're building stuff yourself.  Apple did some weird stuff with their USB implementation in El Capitan(?) and broke all sorts of things for older libusb releases.

James