Author Topic: Simplest way to send and receive data in the USB  (Read 48755 times)

diegogalanti

  • Member
  • ***
  • Posts: 15
Simplest way to send and receive data in the USB
« on: January 04, 2011, 08:19:59 am »
Di,

My name is Diego and I'm a developer in Brazil.

We are working on a project where a program needs to send text commands to a device, that is also being developed by us, and read the responses. Some of these commands are large and it is not possible to send them by the serial RS232 port, so we decided to use the USB port.

The device is a ALIX 2D2 board.

Reading the USB complete book, I realized that we need to:
- use the bulk tranfer.
- use the hight speed.
- buy a Vendor ID

The questions are:

- Is it possible to use a bulk transfer without implement a class?
- If it is not possible, what is the better class for send and receive text comands?

Thank you and sorry about my english.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Simplest way to send and receive data in the USB
« Reply #1 on: January 04, 2011, 10:41:09 am »
You can do bulk transfers with a USB standard class or a vendor-specific or generic driver.

Some options are:

virtual serial port (communications class). If you use the FT2232H for the device hardware, you can use the embedded Vendor and Product IDs.
mass storage if you can store the commands as files.

Generic driver:

http://www.lvr.com/usb_host_software.htm#generic_drivers

Jan

diegogalanti

  • Member
  • ***
  • Posts: 15
Re: Simplest way to send and receive data in the USB
« Reply #2 on: January 04, 2011, 11:59:45 am »
Hi Jan, thank you for the reply,

About the options:

Virtual serial port:
We can not use this option due specific issues of the project.

Vendor-specific
We would have to create a driver right? We are trying to avoid it...

USB standard class
Could you give more information about this option?

Generic driver
With this option, the device does not have to implement any usb class?

Thanks

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Simplest way to send and receive data in the USB
« Reply #3 on: January 04, 2011, 12:22:35 pm »
Vendor-specific
We would have to create a driver right? We are trying to avoid it...


yes

USB standard class
Could you give more information about this option?


The standard USB classes are mass storage, communications, etc.

Generic driver
With this option, the device does not have to implement any usb class?


Correct. The "class" in the descriptor is "vendor defined" (FFh).

Jan

diegogalanti

  • Member
  • ***
  • Posts: 15
Re: Simplest way to send and receive data in the USB
« Reply #4 on: January 04, 2011, 12:40:48 pm »
Hi Jan thank you again,

When the device is designed to work with a generic driver, is it necessary to define what the generic driver? or the developer to the host can choose any one, like winUSB or libusb.

thanks

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Simplest way to send and receive data in the USB
« Reply #5 on: January 04, 2011, 12:49:59 pm »
Assuming a Windows host, the INF file that you provide matches the Vendor ID and Product ID from the descriptors with the driver specified in the INF file.

Jan

diegogalanti

  • Member
  • ***
  • Posts: 15
Re: Simplest way to send and receive data in the USB
« Reply #6 on: January 04, 2011, 01:15:36 pm »
Hi Jan,

With the examples of descriptors that you show in chapter 14 of your book "Using winUSB is vendor-Defined Functions" Could I only change the INF file to use libusb-win32 or another generic driver?

thank you.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Simplest way to send and receive data in the USB
« Reply #7 on: January 04, 2011, 01:39:19 pm »
Most drivers provide example INF files and instructions for modifying. I would start with that.

Jan

diegogalanti

  • Member
  • ***
  • Posts: 15
Re: Simplest way to send and receive data in the USB
« Reply #8 on: January 05, 2011, 04:12:19 am »
Hi Jan,

Some more doubts:

1 - I understand that to the host have access to the device it will always have to use a driver and make a tranfer (control, bulk, interrupt or isochronous) to one of the device endpoints, right?
But how the device send data to the host?

2 - About use mass storage and store the command as files, is it possible the device and the host access the same memory without the host eject the device?

thank you.


Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Simplest way to send and receive data in the USB
« Reply #9 on: January 05, 2011, 10:52:04 am »
1. The device sends data in response to IN token packets from the host. If it's an interrupt endpoint, the host will send periodic IN token packets. If it's a bulk or control endpoint, an application can cause the driver to request data, for example, by requesting to read a file from a device.

2. Yes, the host must have a way of knowing about any changes the device makes to the media's contents. When the device has control of the media, device firmware can set the SENSE KEY field to NOT READY and set ASC and ASCQ to MEDIUM NOT PRESENT. After accessing the media on its own (not by host request), the device firmware can generate a SCSI UNIT ATTENTION condition of NOT READY TO READY CHANGE, MEDIUM MAY HAVE CHANGED. My USB Mass Storage book has more about these other SCSI conditions and commands.

Jan

diegogalanti

  • Member
  • ***
  • Posts: 15
Re: Simplest way to send and receive data in the USB
« Reply #10 on: January 05, 2011, 12:10:57 pm »
Hi Jan,

The project I'm working on isn't the creating of a hardware, it is the creation of a specification of the format of
 the commands and responses, and the communication interface between them.

The format of the commands have been defined and will be like this:

Command:

<command>
    <command_type>1</command_type>
    <data>add date here</data>
</command>

Answer:

<response>
    <response_type>1</response_type>
    <data>OK</data>
</response>

Now I'm working in the interface between the device and the host.

My idea is to define the USB stardands descriptors and other three endpoints descriptor:

control endpoint 0: tha is the obrigatory control endpoint to identify the host device.
bulk OUT endpoint 1: that is where the host will write commands.
Bulk IN endpoint 1: that is where the hsot will read responses.

The descriptors will be standardized and manufacturers will not edit them. Exception to the Vendor ID and Product ID.

But the device manufacturer can decide if will provide a generic driver or a custom-driver.

My question is:

1 - This model is valid? Namely, it is possible that devices with the same descriptor work with different drivers?
2 - The size of the package that I use is 512bytes, but do not know if it is the duty of the hardware or driver breaking the message when it large then 512bytes.

Thank you.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Simplest way to send and receive data in the USB
« Reply #11 on: January 05, 2011, 09:42:18 pm »
If the descriptors identify the class as vendor-specified, the INF file (assuming Windows) containing the Vendor ID and Product ID determines the driver. Any driver that understands the device's protocols can work.

For OUT transfers, the host driver divides large transfers into 512-byte transactions. For IN transfers, the host requests the data in multiple transactions and the device sends it in 512-byte data packets.

Jan

diegogalanti

  • Member
  • ***
  • Posts: 15
Re: Simplest way to send and receive data in the USB
« Reply #12 on: January 06, 2011, 07:05:27 am »
Hi Jan thank you again for the reply,

So assuming I'll make a transfer to a bulk endpoint with packet size of 512 bytes and I'll send more than 512 bytes, the driver is responsible to separate it into several transactions right?

1 - But who is the resposanvel by separating the transaction into packets (token, data and handshake)?
2 - Who is responsible for adding the PID and CRC in packets?
3 - The 512 bytes are reserved only for the date field in the data packet?
4 - In your last reply whein you said "host driver", it's the host controller driver or the usb driver?

thank you

« Last Edit: January 06, 2011, 09:46:48 am by diegogalanti »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Simplest way to send and receive data in the USB
« Reply #13 on: January 06, 2011, 11:56:57 am »
1 and 2. Typically, the device hardware. See your device's data sheet for details.

3. yes

4. The class or device driver requests a transfer that can consist of one or more transactions. The bus and host controller drivers schedule the transactions on the bus.

Jan

diegogalanti

  • Member
  • ***
  • Posts: 15
Re: Simplest way to send and receive data in the USB
« Reply #14 on: January 07, 2011, 07:03:11 am »
Hello Jan,

1 - What identifies the beginning and end of a transfer?
2 - When an application uses a generic driver like winUSB, who is responsible for dividing the transfer into transitions? the app or the generic driver?

Thank you.