Error on USB writePipe (not initialized)

I am trying to learn to use the WinUSBMBS plugin. In the code below, it stops after the first line checks for LastError and displays error1.

Can anyone help me get past this? If I remove the return code, the app shuts down saying "NIL object exception WinUSBMBS not initialized "

Also, if anyone with experience with writepipe and controlTransfer with these plugins can help me out I would pay a fee to get some help.

[code] dim w as new WinUSBMBS(path) //path is global

log "Lasterror: "+str(w.Lasterror) //<<<<<<<<<<<<<<<<<<<<<<<<, getting error 1
if w.Lasterror <>0 then Return

log "DeviceHandle: "+hex(w.DeviceHandle)

log "PipePolicyMaximumTransferSize: “+str(w.PipePolicyMaximumTransferSize(&h82))+” "+str(w.PipePolicyMaximumTransferSize(1))
log "PipePolicyRawIO: “+str(w.PipePolicyRawIO(&h82))+” "+str(w.PipePolicyRawIO(1))
log "PipePolicyPipeTransferTimeout: “+str(w.PipePolicyPipeTransferTimeout(&h82))+” "+str(w.PipePolicyPipeTransferTimeout(1))

dim mb as new MemoryBlock(ReportLength+1)

mb.Int8Value(0) = &h41
mb.Int8Value(1) = 0
text1.text = str(w.WritePipe(1, mb))
log "Lasterror: "+str(w.Lasterror)[/code]

I declared Path as a shared global string so it could be used in various places with writepipe, etc.

This is the app Open code

[code] dim m as new WinHIDMBS

if m.FindFirstDevice then
do

  if left(m.Product,3)="CP2" then // my test device    //if left(m.Product,3)="RF1" then // my test device
    //List.AddRow "Device opened."
    if m.Connect then
      
      w = m
      
      ReportLength = w.OutputReportByteLength
      //  Use WindowsDeviceMBS class to find USB devices and their device paths.
      //dim path as string
      path = w.DevicePath

      List.AddRow "Device opened."
      List.AddRow "OutputReportByteLength: "+str(w.OutputReportByteLength)
      List.AddRow "InputReportByteLength: "+str(w.InputReportByteLength)
      List.AddRow "FeatureReportByteLength: "+str(w.FeatureReportByteLength)   //DevicePath
      List.AddRow "Product: "+str(w.Product)  
      List.AddRow "Path: "+str(w.DevicePath)  
      
      Return
    end if
  end if
loop until not m.FindNextDevice

end if

MsgBox “Failed to find device.”
[/code]

lasterror 1 = windows ERROR_INVALID_FUNCTION

you can’t write without connecting.

Thanks, but the device is connected, an LED turns on when I press connect and it goes off when I disconnect.

This code will show the device turning on an LED that says it is connected. But when it gets to the WinUSBMBS(path) it returns error 1 for lasterror on any attempt to use the plugin. This code faults to Nil Object = WinUSBMSB not initialized. If I can’t solve this today then I will switch to adding the C libraries that come with the HID device. If anyone has an understanding of adding C libraries to Xojo and offers hourly consulting, please let me know.

[code] //return
//Use WindowsDeviceMBS class to find USB devices and their device paths

dim m as new WinHIDMBS

if m.FindFirstDevice then
do

if left(m.Product,3)=“CP2” then // my test device //if left(m.Product,3)=“RF1” then // my test device
//List.AddRow “Device opened.”
if m.Connect then
w = m
ReportLength = w.OutputReportByteLength
TextArea1.text = TextArea1.text +“ReportLength=” + str(ReportLength) + endofline
'// Use WindowsDeviceMBS class to find USB devices and their device paths.
List.AddRow “Device opened.”
TextArea1.text = TextArea1.text + “Device opened.” + endofline
List.AddRow "OutputReportByteLength: "+str(w.OutputReportByteLength)
TextArea1.text = TextArea1.text + "OutputReportByteLength: "+str(w.OutputReportByteLength) + endofline
List.AddRow "InputReportByteLength: "+str(w.InputReportByteLength)
TextArea1.text = TextArea1.text + "InputReportByteLength: "+str(w.InputReportByteLength)+ endofline
List.AddRow "FeatureReportByteLength: "+str(w.FeatureReportByteLength) //DevicePath
TextArea1.text = TextArea1.text + "FeatureReportByteLength: "+str(w.FeatureReportByteLength) + endofline
List.AddRow "Product: "+str(w.Product)
TextArea1.text = TextArea1.text +"Product: "+str(w.Product) + endofline
List.AddRow "Path: "+str(w.DevicePath)
TextArea1.text = TextArea1.text +"Path: "+str(w.DevicePath) + endofline
//List.AddRow "Path: "+str(w.DeviceHandle) // no work
path = w.DevicePath
log "HidHandle: "+str(w.HidHandle ) //getting error 1
TextArea1.text = TextArea1.text +"HidHandle: "+str(w.HidHandle ) + endofline

      dim x as new WinUSBMBS(path)
      log "Lasterro new winr: "+str(x.Lasterror)      //getting error 1
      TextArea1.text = TextArea1.text +"Lasterror new WinUSBMBS: "+str(x.Lasterror)   + endofline
      x.constructor(path)
      log "Lasterror Constr: "+str(x.Lasterror)      //getting error 1
      TextArea1.text = TextArea1.text +"Lasterror Constructor: "+str(x.Lasterror)     + endofline
      log "DeviceHandle: "+hex(x.DeviceHandle)
      TextArea1.text = TextArea1.text +"DeviceHandle: "+hex(x.DeviceHandle)   + endofline
      log "Lasterror dev hand: "+str(x.Lasterror)      //getting error 1
      TextArea1.text = TextArea1.text +"Lasterror dev handle: "+str(x.Lasterror)    + endofline
      log "USBHandle: "+hex(x.USBHandle)
      TextArea1.text = TextArea1.text +"USBHandle: "+hex(x.USBHandle)    + endofline
      log "Lasterror usb hand: "+str(x.Lasterror)      //getting error 1
      
      //attempt to write pipe test
      dim mb as new MemoryBlock(ReportLength+1)
      mb.Int8Value(0) = &h41
      mb.Int8Value(1) = 0
      text1.text =  str(x.WritePipe(1, mb))   // tested 0, 1, 2, 3
      log "Lasterror write: "+str(x.Lasterror)
      TextArea1.text = TextArea1.text +"Lasterror write: "+str(w.Lasterror) + endofline
      
      Return
    end if
  end if
loop until not m.FindNextDevice

end if

MsgBox “Failed to find device.”

[/code]

Here is the output from the code above

ReportLength=64
Device opened.
OutputReportByteLength: 64
InputReportByteLength: 64
FeatureReportByteLength: 64
Product: CP2110 HID USB-to-UART Bridge
Path: \\\\?\\hid#vid_10c4&pid_ea80#7&20956a2&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
HidHandle: 724
Lasterror new WinUSBMBS: 1
Lasterror Constructor: 1
DeviceHandle: 2E4
Lasterror dev handle: 1
USBHandle: 0