I'm helping out a friend with his Electrical Engineering project. He is building a device that will use a serial port to communicate to some software. On a windows platform (Win7), how would one read and write directly to a specific pin on the serial port? Is there an API that Windows exposes for this sort of thing?
2 Answers
Yes, essentially you open a serial port device with a special name, such as COM1, and read and write to it much as you would a file. The pins used will (naturally) be the serial transmit and receive pins.
If you want to control specific pins but not necessarily in a serial way, you might be better off working with a parallel port instead. The parallel port voltages are usually more friendly to TTL level logic and can often be driven directly.
Update: If you just need to toggle one pin as per your comment, you may be able to use the DTR line for this. See the EscapeCommFunction function documentation for how to do this.
5 Comments
You can use WaitCommEvent function to monitor a specific pin. Suppose the voltage change triggers CTS signal, it can be like this
hCommn = CreateFile("COM1", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
......
WaitCommEvent(hCommn, EV_CTS, NULL);
......