From 10c40d7d5098aed3bb94fa895bae79b615042520 Mon Sep 17 00:00:00 2001 From: torque Date: Tue, 2 Jul 2024 21:37:41 -0700 Subject: [PATCH] deps.labjack: fiddle with Windows support a little I will probably spend more time on this than I plan to, though I am not really writing this to run on Windows. At this point, Windows compilation works but when the driver attempts to read the HID descriptor, the response is only 45 bytes instead of the expected 75 (which is what it gets when run on Linux). I was under the impression that this response was just raw data from the device itself, but it's clearly handled differently on the different platforms, so I think it will be somewhat interesting to dig into what is different between the two and why. It's possible I may actually learn something along the way, unfortunately. --- deps/labjack/exodriver/build.zig | 4 ++++ deps/labjack/exodriver/liblabjackusb/labjackusb.c | 2 ++ deps/labjack/ljacklm/build.zig | 4 ++++ deps/labjack/ljacklm/libljacklm/ljacklm.c | 11 +++++++++++ 4 files changed, 21 insertions(+) diff --git a/deps/labjack/exodriver/build.zig b/deps/labjack/exodriver/build.zig index d42361d..b468bf2 100644 --- a/deps/labjack/exodriver/build.zig +++ b/deps/labjack/exodriver/build.zig @@ -17,6 +17,10 @@ pub fn build(b: *std.Build) !void { .link_libc = true, }); + if (optimize == .Debug) { + liblabjackusb.defineCMacro("LJ_DEBUG", "1"); + } + liblabjackusb.addCSourceFile(.{ .file = b.path("liblabjackusb/labjackusb.c") }); liblabjackusb.installHeader(b.path("liblabjackusb/labjackusb.h"), "labjackusb.h"); diff --git a/deps/labjack/exodriver/liblabjackusb/labjackusb.c b/deps/labjack/exodriver/liblabjackusb/labjackusb.c index d37d6a2..511206d 100644 --- a/deps/labjack/exodriver/liblabjackusb/labjackusb.c +++ b/deps/labjack/exodriver/liblabjackusb/labjackusb.c @@ -505,6 +505,7 @@ static HANDLE LJUSB_OpenSpecificDevice(libusb_device *dev, const struct libusb_d return NULL; } +#if defined(_WIN32) // Test if the kernel driver has the U12. if (desc->idProduct == U12_PRODUCT_ID && libusb_kernel_driver_active(devh, 0)) { #if LJ_DEBUG @@ -521,6 +522,7 @@ static HANDLE LJUSB_OpenSpecificDevice(libusb_device *dev, const struct libusb_d return NULL; } } +#endif // _WIN32 r = libusb_claim_interface(devh, 0); if (r < 0) { diff --git a/deps/labjack/ljacklm/build.zig b/deps/labjack/ljacklm/build.zig index 7cb124f..5eba962 100644 --- a/deps/labjack/ljacklm/build.zig +++ b/deps/labjack/ljacklm/build.zig @@ -17,6 +17,10 @@ pub fn build(b: *std.Build) !void { .link_libc = true, }); + if (optimize == .Debug) { + libljacklm.defineCMacro("LJ_DEBUG", "1"); + } + if (target.result.os.tag == .windows) { libljacklm.defineCMacro("LJACKLM_USE_WINDOWS_MUTEX_SHIM", "1"); } diff --git a/deps/labjack/ljacklm/libljacklm/ljacklm.c b/deps/labjack/ljacklm/libljacklm/ljacklm.c index eddb20c..d4b434f 100644 --- a/deps/labjack/ljacklm/libljacklm/ljacklm.c +++ b/deps/labjack/ljacklm/libljacklm/ljacklm.c @@ -7220,6 +7220,17 @@ long GetU12Information( HANDLE hDevice, temp = (unsigned long)LJUSB_GetDeviceDescriptorReleaseNumber(hDevice) * 65536; //upper two bytes of serial # result = LJUSB_GetHIDReportDescriptor(hDevice, repDesc, 75); + +#if defined(LJ_DEBUG) + + fprintf(stderr, "U12 HID ReportDescriptor (hex, %lu B): ", result); + for (int idx = 0; idx < result; idx++) { + fprintf(stderr, "%02hhX", repDesc[idx]); + } + fprintf(stderr, "\n"); + +#endif // LJ_DEBUG + if(result < 75) { //Failed getting descriptor. First capability would of been input, so