Archived

This topic is now archived and is closed to further replies.

Gyannea

USB and serial ports

Recommended Posts

Gyannea    122
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

Share this post


Link to post
Share on other sites
quasar3d    814
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]

Share this post


Link to post
Share on other sites
Gyannea    122
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

Share this post


Link to post
Share on other sites
dede    132
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.

Share this post


Link to post
Share on other sites
Endurion    5411
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.

Share this post


Link to post
Share on other sites
Shannon Barber    1681
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.

Share this post


Link to post
Share on other sites