Author Topic: Adapting VB Jan's code to my needs  (Read 6201 times)

gikubik

  • Member
  • ***
  • Posts: 8
Adapting VB Jan's code to my needs
« on: January 27, 2014, 11:14:32 am »
Hello everybody,

I want to adapt Jan's code (VB one) to be able to communicate with a small device I built. The device is vendor-specific and I want to send up to three different vendor-requests during the setup stage and get up to three different answers which are a small group of bytes. I want to use only control transfers (using Full Speed, data length is enough) which is the only possibility implemented in my firmware.

I have to say that my knowledge on USB interface isn't good enough. Furthermore, I'm not a programmer, so I need some help. I opened the VB project and I was watching the VB form. I suppose that, only changing a few things could work but it's not clear because of my lack of knowledge.

Thanks a lot!
Gikubik

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Adapting VB Jan's code to my needs
« Reply #1 on: January 27, 2014, 12:01:35 pm »
If you are truly "not a programmer" you will have a learning curve in adapting my code for your use. The first question is whether your device uses a standard class such as HID or a generic driver such as WinUSB. That will determine which of my example programs to start with.


gikubik

  • Member
  • ***
  • Posts: 8
Re: Adapting VB Jan's code to my needs
« Reply #2 on: January 27, 2014, 03:47:32 pm »
Hi, thanks for your answer,

I'm using WinUSB as a driver. My device reach the configurated state correctly. So the idea is to send to it vendor-requests with control transfers (my firmware hasn't implemented any other kind of transfer). I only need the host side program because the firmware is ready to answer those vendor-requests.

I have to say that I developed my own firmware (with assembly for PIC) and I adapted Bradley Minch code (also ASM) to get the USB interface but anyway I think I'm not a programmer. VB is a high level language and Windows and APIs and all this weird things are strange for me. Of course when I look at your code I understand something, but only a bit! Anyway it can't be so difficult to receive a few bytes from a device... can be?

Thanks Jan!
Gk

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Adapting VB Jan's code to my needs
« Reply #3 on: January 27, 2014, 08:56:56 pm »
Look at the DoControlReadTransfer and DoControlWriteTransfer routines.

gikubik

  • Member
  • ***
  • Posts: 8
Re: Adapting VB Jan's code to my needs
« Reply #4 on: January 28, 2014, 07:37:06 am »
Ok I did it, and now I think I will be able to get it :) But I still have some doubts (maybe you think they are a bit silly, I'm sorry):

1) I suppose I only need to deal with DoControlReadTransfer() because I expect only to get data from my device but not to send data to it, so I can forget DoControlWriteTransfer(), Am I right?

2) Within the function DoControlReadTransfer(), setupPacket.Request = 2 means that my device will receive a setup packet with a vendor request with parameter bRequest=02h?

3) The theory: If I want to be able to pass up to 3 different vendor-requests to my device (1, 2 and 3) I should modify this function to be invoked with a third variable (not only winUsbHandle and dataStage but also for example "desired_request"), then I could do something like setupPacket.Request = desired_request. Am I in the right way?

Thanks again!
Gk