Remortgages | Credit Cards UK | Mortgage | Music Festival | Gas Suppliers
Interface with computer ports [Archive] - PCMech Forums

PDA

View Full Version : Interface with computer ports


mattg2k4
03-01-2003, 08:42 PM
Topic says it really. I want to learn how to interface with ports on my computer, like the parallel, serial, and usb port. I'd like to learn it for either C++ or VB, but I'd be willing to learn a new language if it would work better for this task.

Thanks!

Paul Victorey
03-02-2003, 06:08 PM
It's quite easy, for the most part. C++ is a good language choice, you'll need to learn about the windows API to handle these kinds of things (these are handled by the OS).

USB may require you to write drivers, like PCMCIA would (I've written PCMCIA drivers, actually). I don't think you have direct control over the USB port like you would a serial or parallel port, which you can easily write to/read from with API commands.

mattg2k4
03-02-2003, 09:28 PM
Thanks Paul.

Know anywhere I can find all these API calls without going through that handy little win32.hlp file you gave me?

BTW, I did find a method for programming it in VB here, http://aaroncake.net/electronics/vblpt.htm, but the dll it uses will not work under NT according to the docs due to security concerns. Will that still affect XP and 2000, being based on the NT architecture?

Paul Victorey
03-03-2003, 11:33 PM
Searching Win32.hlp is the main place to find those commands. In Win32, ports are handled just like files, so to open a port, you can do something like

HANDLE serialPort = CreateFile("COM1:", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);

// Do reads/writes here just like you would a file.
// You might need to reset data parameters for a serial I/O device

CloseHandle(serialPort); //IMPORTANT, nobody else can use it until you're done with it