First of all, the port opens and works fine with Hyperterm. However, I'm trying to run a simple program to open and setup the port, but cannot make it work. Here is a code snip:
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
int _tmain(int argc, _TCHAR* argv[])
{
DCB dcb;
HANDLE hCom;
BOOL fSuccess;
hCom = CreateFile( (LPCTSTR)"COM1",
GENERIC_READ | GENERIC_WRITE,
0, // must be opened with exclusive-access
NULL, // no security attributes
OPEN_EXISTING, // must use OPEN_EXISTING
0, // not overlapped I/O
NULL // hTemplate must be NULL for comm devices
);
if (hCom == INVALID_HANDLE_VALUE)
{
// Handle the error.
printf ("CreateFile failed with error %d.\n", GetLastError());
while(!kbhit());
Sleep(50);
return (1);
}
This always fails and returns error code 2. I successfully use COM1 with Hyperterm, but I always close the terminal program before trying this code.