1
\$\begingroup\$

Why is it that when I plug in a USB device mouse/ 2D scanner, the host computer is able to detect and recognize it automatically, allowing it to do whatever it is supposed to do (i.e. move my cursor/ input a string followed by a carriage return when I scan a QR code)? But for devices that I have made/wired up myself, I have to set the exact COM port and baud rate before the computer is able to recognize it?

Where is this missing piece of code stored in these manufactured devices (mouse/ 2D scanner) and how do I implement it in my own projects?

I have a IR thermometer that outputs TTL and I'm using a TTL-USB converter to convert the signals to USB signals. Do I need a microcontroller? If so, where do I find sample codes for this?

\$\endgroup\$
3
  • 1
    \$\begingroup\$ The USB identity of these devices is specific to their purpose. That of a serial UART is generic, so identifying it is left up to you. You could customize the details but then you would need to provide your own driver (or at least rules file) for each host operating system \$\endgroup\$ Commented Dec 15, 2020 at 3:31
  • \$\begingroup\$ which IR thermometer ? where is the datasheet ? \$\endgroup\$ Commented Dec 15, 2020 at 4:32
  • 3
    \$\begingroup\$ The USB specification includes a set of per-definded device classes. In the case of a mouse, the PC reads the USB descriptors and determines that it is an HID (Human Interface Device). Windows has a default driver for an HID, so you are able to use the mouse. If the mouse had any special functions not defined in the HID class then you would need a special driver for that. \$\endgroup\$
    – user4574
    Commented Dec 15, 2020 at 5:12

4 Answers 4

2
\$\begingroup\$

The USB standard defines device classes.

Some classes are directly supported by the system, like some HID (Human Interface Device), as for mouse and keyboard, those are HID Mouse or HID Keyboard classes.

The COM port is a serial communication called CDC Class that is also directly supported by the system was made to keep backward compatibility with the old serial port on computers.

Some other classes are Mass Storage, for a flash dongle, and some other audio and printers.

One thing to know is that USB devices are identified with a VID (Vendor ID) and PID (product ID). You need to pay a fee to the USB foundation to get your own VID.

Then if your device needs specific communication, you can make your own driver. For example, you can make an HID Device class device that would require a driver. For USB devices usually, you can find drivers from the stack supplier (like a microchip, Atmel) and modify the .inf file to match your product VID and PID without having to write the driver yourself, but since win10 you need a driver signing certificate to sign your drivers in order to install them.

Often on a simple dev board, COM Serial is the most used communication standard because it's easy to implement, although not the best as you have to parameterize the system (set com port, baud rate...).

If you want to keep the COM port. a trick on Windows (and probably on other platforms), you can list the com port and find their VID and PID if they are USB. This way you can find what COM port is your device without needing user input.

Better if you make your own device driver, you can implement that with many micro-controller like Atmel, Microchip amongst many others. You can download the USB stack code and get started. The best way is to start with some dev board from a specific vendor.

Overall, now most of the microcontroller manufacturers will provide the USB stack, and is often "easily" done through some configuration and a bit of code.

USB might seem a bit dompting when you want to make your own driver and it takes some time to have everything figured between firmware, hardware, driver, but it's worth it if you want to make any sorts of device that communicates with a computer.

In 2020, I still see so many, even recent, industrial equipment using the old COM port as the engineer didn't know better, and always gives the feel that the equipment is subpar. Isn't that neat when you connect your device that it lists itself with the device name, your company name and that the software automatically finds it rather than having an old COM configuration window from the 90s?

\$\endgroup\$
0
\$\begingroup\$

Why is it that when I plug in a USB device mouse/ 2D scanner, the host computer is able to detect and recognize it automatically, allowing it to do whatever it is supposed to do (i.e. move my cursor/ input a string followed by a carriage return when I scan a QR code)?

It is so because the driver code for that mouse/keyboard is already available inside your operating system. For your particular sensor you will have to write the rule files yourself.

I have a IR thermometer that outputs TTL and I'm using a TTL-USB converter to convert the signals to USB signals. Do I need a microcontroller? If so, where do I find sample codes for this? Its not compulsory to use a micro-controller, it totally depends on your application. You can use both.

In both cases you have to provide to the sensor some sort of start signal and read the sensor's output (see in sensor datasheet). The start signal can be provided by computer as well as by a micro-controller. If you go with computer I recommend you use a python script which is easy to implement. Just a quick Google search can help you: "Python USB communication".

\$\endgroup\$
2
  • \$\begingroup\$ The end goal that I have in mind is to have my sensor plugged in and the data being fed to the host automatically for all PCs, just like the mouse/2D scanner. If I were to write a python script, then it would only work where the python is installed and running and nowhere else, which is not the case for a mouse. So I guess my question is how do I make my device compliant to some sort of code/ protocol such that any PC can recognize it. Btw, the sensor is constantly pushing serial data from the moment it turns on, there's no need for a start signal, its a pretty simple (or dumb) device. \$\endgroup\$
    – jay_aechh
    Commented Dec 15, 2020 at 5:57
  • \$\begingroup\$ If I were to write a python script, then it would only work where the python is installed and running and nowhere else, which is not the case for a mouse why you are comparing your device with mouse,is your device used universally world wide?obviously not. Drivers for mouse is inside your host machine(operating system provide support for them) not in mouse. so your device never behave like mouse,for that you have to first install your custom made software(a small script) in host machine and then use it. \$\endgroup\$ Commented Dec 15, 2020 at 7:07
0
\$\begingroup\$

Actually, there is no difference. If you plug in 10 identical or even different scanners, the USB IDs are known and drivers for them can be loaded to have a list of 10 scanners in the system, but of course you must select which one you want to use to scan a paper.

Basically the same applies to say 10 computer mice as well, their ID is detected and they are added to the list of mice, it's just that the OS by default uses all of them to control the single mouse cursor on screen.

And the same applies to your custom devices, and it looks like they all are USB serial ports so USB serial port drivers are loaded and the decices appear as USB serial ports. If you want to talk to a certain device, only you know which COM port is which device, and COM ports do not themselves know what settings to use. If you make a device and matcinh PC software for it, of course you can assume the settings so you can simply ask the user which COM port to use.

\$\endgroup\$
0
\$\begingroup\$

Why is it that when I plug in a USB device ... host computer is able to detect and recognize it automatically, allowing it to do whatever it is supposed to do...

Well-known devices detect automatically. Usb Devices are represented by classes. The behavior of the class is predefined. 2-D scanner is keyboard-class, for example. 2-D scaner isn't give the picture, it gives the read keyboard-text. The mouse is well-know device.

Where is this missing piece of code stored in these manufactured devices (mouse/ 2D scanner) and how do I implement it in my own projects?

This code isnt't open source. Pieces of code can be found on the git and on the internet. In general, this is not solvable without large experience.

I have a IR thermometer that outputs TTL and I'm using a TTL-USB converter to convert the signals to USB signals. Do I need a microcontroller? If so, where do I find sample codes for this?

  • Simple case: take com-usb converter and connect signals. Your device is com-port.
  • Other case: choose microcontroller and learn how it works.
  • Happy case: find same microcontroller sollution with firmware and reproduce it.
\$\endgroup\$

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