1

I'm at the very beginning. I'm trying to connect to a motor that is connected via CAN-bus and a USB-adapter/USB-gateway-thing to my PC. I've installed drivers and stuff and device manager (DM) tells me the device is working properly.

Now one step at a time: I want to connect to that device for reading or writing packets or whatever. Or at least I would like to find it like the DM finds it (if I unplug it, it disappears from the DM, when I plug it back in it's there again).

CreateFile seems to be able to open files as well as devices. Well, now I do not want files, I want devices. Can I get a handle to a device via WinApi or is there a better approach?


enter image description here enter image description here
Code I've tried:
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr CreateFile(string filename,
    [MarshalAs(UnmanagedType.U4)] FileAccess access,
    [MarshalAs(UnmanagedType.U4)] FileShare share,
    [Optional] IntPtr securityAttributes,
    [MarshalAs(UnmanagedType.U4)] FileMode creationDisposition,
    [MarshalAs(UnmanagedType.U4)] FileAttributes flagsAndAttributes,
    [Optional] IntPtr templateFile);

IntPtr file = CreateFile(@"USB\VID_0403&PID_ECD9", FileAccess.Read, FileShare.ReadWrite,
    IntPtr.Zero, FileMode.OpenOrCreate, FileAttributes.Device, IntPtr.Zero);`

Well the result of CreateFile here is null (GetLastError = ERROR_PATH_NOT_FOUND).

Bitterblue
  • 13,162
  • 17
  • 86
  • 124

1 Answers1

0

Your path should be like @"\?\USB#VID_0403&PID_ECD9#000000000aaa#{ae18aa60-7f6a-11d4-97dd-00010229b959}"

Anton Bakulev
  • 286
  • 2
  • 7