A newbie question about USB

J

Johnson

A newbie question about USB.
I am developing a PC application (not driver) to communicate with a USB
2.0 slave peripheral device. I would like to know, if my application
has built a connection and is talking to the USB peripheral, and I
disconnect the cable suddenly, will the application be able to identify
the event automatically, or it will still stay with the "connection"?
Another problem, if I re-connect the usb cable, will the connection be
automatically restored? Should I close my application first and then
start it again to create a connection with the USB peripheral?
Thanks in advance.
Johnson
 
S

Skeleton Man

A newbie question about USB.
I am developing a PC application (not driver) to communicate with a USB
2.0 slave peripheral device. I would like to know, if my application
has built a connection and is talking to the USB peripheral, and I
disconnect the cable suddenly, will the application be able to identify
the event automatically, or it will still stay with the "connection"?
Another problem, if I re-connect the usb cable, will the connection be
automatically restored? Should I close my application first and then
start it again to create a connection with the USB peripheral?
Thanks in advance.
Johnson

This is all driver dependant behaviour.. your software would constantly poll
the driver to find out the current status (connected, disconnected, etc).

The code might look something like this:

while (usb->connected() == true){
usb->read_from_device();
usb->write_to_device();
}

The driver is responsible for handling hardware events such as
connecting/disconnected a USB device.

You might want to post to the appropriate software group for the language you
are developing in (C, C++, etc).

Regards,
Chris
 
J

Johnson

Thank you, Chris. I had a few more questions.

1) Could two PC applications work on the same USB port? How to avoid
confliction?

2) Are the PC applications able to check the type of the USB
peripherals connected? If so I can let the first PC application
"active" when USB peripheral A is detected, and the second PC
application "active" when USB peripheral B is detected. This way
multiple PC applications can work together with one physical USB port.

3) I guess the firmware running inside of the USB slave peripherals
(not driver), has the similar behavior to the PC application's, right?
I guess the codes for the firmware also look like:
while (usb->connected() == true){
usb->read_from_device();
usb->write_to_device();
}

Johnson
 
S

Skeleton Man

1) Could two PC applications work on the same USB port? How to avoid
confliction?

Yes.. for example you install printer drivers and camera drivers onto the PC.
You can connect either device to any USB port and the OS knows which software to
launch. I'm sure there are also methods to launch a generic application
regardless of which device is connected.
2) Are the PC applications able to check the type of the USB
peripherals connected? If so I can let the first PC application
"active" when USB peripheral A is detected, and the second PC
application "active" when USB peripheral B is detected. This way
multiple PC applications can work together with one physical USB port.

Again it would be the job of the driver to report the type and identity of the
device connected. I should assume most API's would have a simple method that is
called for this (e.g. device_id = usb->probe()). This method would probe the
device with some generic command, which instructs the firmware to report basic
information (like ID, version, etc).
3) I guess the firmware running inside of the USB slave peripherals
(not driver), has the similar behavior to the PC application's, right?
I guess the codes for the firmware also look like:
while (usb->connected() == true){
usb->read_from_device();
usb->write_to_device();
}

I should think the firmware would function in much the same way as the drives
yes, but don't take my word on it. I'm not a developer of USB or any hardware
based communications, I'm largely a web programmer (my experience with devices
is based on paralell/serial communications, I've never worked with USB).

Again you would be best to post to a software group as they would be much more
knowledgable.

Regards,
Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top