USB and serial ports

Started by
4 comments, last by Gyannea 20 years, 3 months ago
Does anyone have any information about books that explain how to program serial ports under Windows? And even more important (since serial ports are lacking on today''s computers) how to program the USB ports to use as serial ports? USB ports are everywhere, but most equipment that accepts computer control via command sequences still uses serial ports (radios, lab devices, etc.) I have five different books on Windows programming and not one of them mentions serial or USB ports. Thanks, Brian Brian Reinhold
Brian Reinhold
Advertisement
I don't think this is possible with a plain win32 application. If you want to use a device on the usb or serial port, you have to do that via the device drivers, which operate in ring 0. Ring 0 programming is similar to dos programming, for you can access ports directly, you can work with real memory addresses, etc, but you can't use all of the libraries you normally use under win32.
If you want to do ring 0 programming, you could download the microsoft driver development kit (ddk), which will probably explain how to access the usb bus.

My Site


[edited by - Quasar3D on January 15, 2004 10:17:35 AM]

[edited by - Quasar3D on January 15, 2004 10:17:55 AM]
Oh Yuulk!

I hope THAT is certainly not true. The nice thing about DOS programming was complete control of the hardware, but the nightmare was getting all the vendor specific information.

I hope that addresses to these ports are at least obtainable from the OS. At least in DOS COM1 and COM2 always had the same addresses so you could write the ASM code and it would work on all systems. I have no idea what Windows does with the serial ports and USB ports and thier access, and I dread the idea of learning how to write a Windows device driver! That sounds like an agonizing and very time consuming task for an individual.

Brian
Brian Reinhold
There are hacks to actually accessing ports through windows, but they result in fighting the OS for control over those ports. You''ll see a significant slowdown if you try any of them. Real time is out of the question.

However, looking around on google, I found this link...
Link

Would any of these libraries help you out?

~~~~~
"One Reality is worth one thousand dreams"
Download and play Slime King I.
~~~~~Screaming Statue Software. | OpenGL FontLibWhy does Data talk to the computer? Surely he's Wi-Fi enabled... - phaseburn
COM-Ports can be simply opened via CreateFile (open com1 or com2 or...) and read from and written to just like a real file.

USB-Ports cannot. You need an USB driver in between, and if its only for having a pseudo file like com ports. For making a driver you need the driver development kit though. You could also look into USBLib, which will do just that for you.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

For com ports, you just open them like files, and there''s a couple of extra function to call to configure the beahvior of the read & write functions (e.g. timeouts and baud).

Set/GetCommState, Set/GetCommTimeouts, & ClearCommError

You can use overlapped IO (maybe even io completion ports) with them to minimize the latency (and overhead) when communicating over rs-232.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

This topic is closed to new replies.

Advertisement