1

Am trying to figure how can I make some software and USB hardware.

Let's put the hardware thing aside for now. For software, how can I send data to a USB port?

C++ / Java or any other language (prefer to be working on Linux).

2
  • You might want to look into using libusb. Jan 17, 2012 at 12:43
  • I think you should think of hardware first because it depends on the hardware how you should send the data. For instance, if the hardware emulates a serial port, then the hardware is seen as a serial port by the OS and you can just use standard serial communication on the PC. If the hardware is just 'plain' USB, then you can use libusb.
    – rve
    Jan 17, 2012 at 14:01

5 Answers 5

3

USB ports are not like "dumb" RS-232 serial ports. It's a bus, that requires quite complicated handling, all driven by the host (the computer, typically). Very low-level operations such as "sending ones and zeros" to the data pins are more or less impossible.

The easiest way to program USB from user-space in Linux is probably to use libusb.

On the client (your custom USB hardware) end, either look for a system featuring a built-in USB controller, or a software stack. I don't think writing your own software stack is feasible, since you (no offense) don't seem to be quite at that level regarding your knowledge of USB.

V-USB is a software USB stack for Atmel's AVR microcontrollers, for instance.

0
1

As others have pointed out you have to write a driver for the USB device.

Another option is to communicate with the device using a serial protocol over USB, then your hardware needs an USB to serial chip. The best answer regarding USB over serial is in the question How to get C++ to perform I/O from a USB Port like a Serial Port by Mike DeSimone

1

If you want to bitbang I/O using USB, then you can connect a FTDI chip like the FT232 (which is used in many USB to serial cables) to the USB port. On the PC you can use libFTDI to bitbang the I/O pins of the FTDI chip.

I think this is the easiest way for controlling I/O pins using USB.

1
  • The FT232R chip bit-banging mode is the most easy and practical way to control 8 IO from Windows or Linux. You can get an FT232R breakout board for $10. Do not buy the fake one generally less than $7 on ebay. The Nusbio library offers support for .C# and VB.NET. github.com/madeintheusb/Nusbio.Samples Apr 6, 2017 at 14:21
1

An alternative to serial port emulation is USB HID (Human Input Device), which is supported on Linux out of the box. You'd use the "HIDAPI" to communicate with your device.

-2

A usb port is just a serial port. Therefore, the first place that you want to look is writing a sofware to handle serial port communication.

Be aware that the OS may assign a different port number to the device whenever it's connected.

4
  • On Linux, that can be handled via a couple of udev rules that assign fixed device names, port numbers etc.
    – arne
    Jan 17, 2012 at 12:43
  • 1
    "A usb port is just a serial port." Err no. It may have serial in the name but the protocols involved in sending data over USB are far more complex than sending raw bits over an RS-232 port.
    – adelphus
    Jan 17, 2012 at 13:06
  • ah - I was confusing the times that I've used USB to serial convertors. I guess that the protocol handling was done by the driver for the USB device then.
    – ChrisBD
    Jan 17, 2012 at 13:29
  • Indeed, as it's such a common device most OS'es have standard drivers for USB-to-RS232 adaptors.
    – MSalters
    Jan 17, 2012 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.