PORTS Forum

Ports and Interfaces => USB => Topic started by: r0ckb0y on November 05, 2010, 04:06:27 pm

Title: UsbDataReceiveEventHandler
Post by: r0ckb0y 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...
 :-[
Title: Re: UsbDataReceiveEventHandler
Post by: Jan Axelson 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
Title: Re: UsbDataReceiveEventHandler
Post by: Guido Koerber 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.
Title: Re: UsbDataReceiveEventHandler
Post by: r0ckb0y 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 :)
Title: Re: UsbDataReceiveEventHandler
Post by: Jan Axelson 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
Title: Re: UsbDataReceiveEventHandler
Post by: Guido Koerber on November 06, 2010, 03:41:37 am
What kind of device are you trying to talk to?
Title: Re: UsbDataReceiveEventHandler
Post by: r0ckb0y 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...?
Title: Re: UsbDataReceiveEventHandler
Post by: r0ckb0y 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?
:-[
Title: Re: UsbDataReceiveEventHandler
Post by: Jan Axelson 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
Title: Re: UsbDataReceiveEventHandler
Post by: Guido Koerber 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.
Title: Re: UsbDataReceiveEventHandler
Post by: r0ckb0y 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