Announcement

Collapse
No announcement yet.

Different hardware causing error on same code - USB, HID, Stream Deck

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Different hardware causing error on same code - USB, HID, Stream Deck

    I have a bit of code that sends data to an HID device:

    Code:
      FUNCTION SEND_PACKET_TO_DEVICE(DEVICE_INDEX AS LONG, WRITE_BUFFER AS STRING *1024) AS LONG
    
      LOCAL RESULT                     AS LONG
      LOCAL MY_OutputReportByteLength  AS LONG
      LOCAL BYTES_WRITTEN              AS LONG
      LOCAL Last_Error                 AS LONG
      LOCAL HandleWriteFile            AS DWORD
    
      HandleWriteFile = HID_DEVICE_ARRAY(DEVICE_INDEX).FILE_HANDLE_WRITE
    
      RESULT = WriteFile(BYVAL HandleWriteFile, WRITE_BUFFER, 1024, BYTES_WRITTEN)
    
      Last_Error = GetLastError
    
      TEXT_TO_SCREEN FORMAT$(RESULT) + " - " + FORMAT$(LAST_ERROR)
    
     END FUNCTION 
    Using the Stream Deck Mini , this function works great - has for a few weeks. Yesterday I got a 15 button original Stream Deck. According to the Endpoint Descriptor for the new device the max packet size should be 0x200 (512) bytes. The original Stream Deck Mini I have working used a max packet size of 0x400 (1024) bytes. So I figured I needed to adjust the buffer size for my WriteFile function call. That caused error 87 ERROR_INVALID_PARAMETER. Remember this function works with the original hardware.

    We know the HandleWriteFile is correct because it works in other contexts and with the original hardware. I think the datatype of STRING *512 is correct because there are nulls in the data so it can't be ASCIIZ, right? Buffer size is just a number and BYTES_WRITTEN is just a number.

    How can hardware be causing the function to behave differently? I am thinking it might be in the HID driver.

    Here is the declaration from the JR includes - again it works with the Stream Deck Mini device:

    Code:
    DECLARE FUNCTION WriteFile IMPORT "KERNEL32.DLL" ALIAS "WriteFile" ( _
       BYVAL hFile AS DWORD _                               ' __in HANDLE hFile
     , BYREF lpBuffer AS ANY _                              ' __in LPCVOID lpBuffer
     , BYVAL nNumberOfBytesToWrite AS DWORD _               ' __in DWORD nNumberOfBytesToWrite
     , OPTIONAL BYREF lpNumberOfBytesWritten AS DWORD _     ' __out_opt LPDWORD lpNumberOfBytesWritten
     , OPTIONAL BYREF lpOverlapped AS OVERLAPPED _          ' __inout_opt LPOVERLAPPED lpOverlapped
     ) AS LONG                                              ' BOOL

    Anyone know a way to get additional error information from windows?

    I think the HID driver has a say in this as it will cause WriteFile to error if the first byte is not 2 (the report number) on the one that works. In theory you should be able to send 2 followed by NUL$(1023 ) and not have an error (tested and does work) -- Does not work with the other hardware and 2 + NUL$(511).


  • #2
    Problem solved. I was making many calls of 512 each - What was needed was one call for the entire data at once. The hardware of the StreamDeck 15 button wants two pages of 512*12 each...

    Comment

    Working...
    X