Many people thinks that you could not do general purpose IO using the serial port. But it's
wrong. Serial port itself have 2 input pins and 2 output pins.
And many people believe that you can't do it with USB serial ports. And some believe that
you couldn't do on windows 7. All those fearful alarms were wrong ! YOU COULD.
Here we need a very simple circuit.

And here is how you should connect pins to.
And here is the source code,
Code: Select all
#ifndef __UNICODE__
#define __UNICODE__
#endif
#ifndef UNICODE
#define UNICODE
#endif
#ifndef _UNICODE
#define _UNICODE
#endif
#include <windows.h>
#include <stdio.h>
TCHAR * serial_port = L"COM2";
void BlinkLED(HANDLE hfile)
{
while(TRUE){
EscapeCommFunction(hfile,SETRTS);
sleep(1);
EscapeCommFunction(hfile,CLRRTS);
sleep(1);
}
}
int main(int argc,char** argv)
{
HANDLE hfile = CreateFile(serial_port ,GENERIC_READ |GENERIC_WRITE ,\
0,
0,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);
if (hfile==INVALID_HANDLE_VALUE)
{
MessageBox(NULL,TEXT("Serial Port Does not Exist!"),TEXT("LED ON"),NULL);
exit(0);
}
BlinkLED(hfile);
CloseHandle(hfile);
}
program as administrator.
x64 win7 compiled binary file and source file have been attached. Additional pictures:
https://picasaweb.google.com/1165913223 ... ember52012#
[if admin wants to move this discussion into electronic engineering or other section , please
allow other users to comment and add new things into the topic too]
--Thanks for Reading--