Author Topic: UsbDataReceiveEventHandler  (Read 14619 times)

r0ckb0y

  • Member
  • ***
  • Posts: 5
UsbDataReceiveEventHandler
« on: November 05, 2010, 04:06:27 pm »
HI,sorry ..Im a beginner...
i have used the com port in my project,but now i have to use usb and...
i need a code witch replace with:

Code: [Select]
comPort.DataReceived += new SerialDataReceivedEventHandler(comPort_DataReceived);
comPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{

// what i want to do when data come in com port

}

in my program.
plz help...
 :-[

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: UsbDataReceiveEventHandler
« Reply #1 on: November 05, 2010, 04:58:44 pm »
If you want to use code like this for a device attached to a USB port, use a USB virtual COM port adapter such as an FTDI FT232R. You won't have to change the application code at all.

Jan

Guido Koerber

  • Frequent Contributor
  • ****
  • Posts: 72
Re: UsbDataReceiveEventHandler
« Reply #2 on: November 05, 2010, 05:47:44 pm »
The first thing you have to do on USB is find out how your device transfers data. Contrary to RS232 which transfers byte oriented, USB uses data blocks and can have quite different modes of data transfer.

r0ckb0y

  • Member
  • ***
  • Posts: 5
Re: UsbDataReceiveEventHandler
« Reply #3 on: November 05, 2010, 06:42:08 pm »
thx 4 Ur attention my friends..but.....
i dont want to use virtual port.....and i get some open source code 4 all operation that we can do with usb...but...
they dont have any void like the codes in my previous post....
actually...i need a listener that tellme when data is in inputbuffer....
T U again :)

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: UsbDataReceiveEventHandler
« Reply #4 on: November 05, 2010, 09:40:09 pm »
There is no generic answer because as Guido said, the host application code varies with the driver the host computer assigns to the device, and that in turn depends on the device firmware.

Jan

Guido Koerber

  • Frequent Contributor
  • ****
  • Posts: 72
Re: UsbDataReceiveEventHandler
« Reply #5 on: November 06, 2010, 03:41:37 am »
What kind of device are you trying to talk to?

r0ckb0y

  • Member
  • ***
  • Posts: 5
Re: UsbDataReceiveEventHandler
« Reply #6 on: November 06, 2010, 07:41:14 am »
i make and set a wireless network with rf module...and i have to listen to the line...
it works good with com port, now....but i need to use usb ...meantime,the usb2com converter make my network down...that module isnt suitable 4 this project<i have my reason>.
afterall...what do i do? :(
no way...?

r0ckb0y

  • Member
  • ***
  • Posts: 5
Re: UsbDataReceiveEventHandler
« Reply #7 on: November 06, 2010, 07:53:31 am »
i traced your "generic_hid_cs_46" project ,Mr axelson...i think i must add a void to that projct to listen to the line....but i dont know where i must start:(
could u help me?
:-[

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: UsbDataReceiveEventHandler
« Reply #8 on: November 06, 2010, 10:36:56 am »
If you have a device that works on a COM port, use a USB/serial adapter and you will likely need no application or firmware changes.

If you prefer to redesign your device as a HID-class USB device, my HID page has links to information and example application code and firmware to get you started.

Jan

Guido Koerber

  • Frequent Contributor
  • ****
  • Posts: 72
Re: UsbDataReceiveEventHandler
« Reply #9 on: November 06, 2010, 03:28:53 pm »
Do you use the actual serial data transfer or are you abusing the handshake lines of the serial port? The second option works really badly with USB.

r0ckb0y

  • Member
  • ***
  • Posts: 5
Re: UsbDataReceiveEventHandler
« Reply #10 on: November 06, 2010, 04:12:02 pm »
i use actual serial port....i am going to listen to the Jan's advise ...i'll come back soon with good results...thx again Mr axelson :D