1 /* vim: set sw=8 ts=8 si et: */
\r
2 /* Windows software to initialize the com port
\r
13 int open_tty(char *comport){
\r
15 char lastError[512];
\r
19 snprintf(CommPath,40,"\\\\.\\%s",comport); // COM1 or COM2 or ...
\r
21 fd = CreateFile(CommPath,
\r
22 GENERIC_READ | GENERIC_WRITE,
\r
29 if (fd == INVALID_HANDLE_VALUE) {
\r
30 //fprintf(stderr, "CreateFile failed: CommPath (%.8x)\n", (unsigned int)GetLastError());
\r
32 FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
\r
35 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
\r
39 fprintf(stderr,"ERROR open com-port: %s\n",lastError);
\r
43 memset(&Dcb, 0x0, sizeof(DCB));
\r
44 Dcb.DCBlength = sizeof (DCB);
\r
45 ok = GetCommState(fd, &Dcb);
\r
47 fprintf(stderr, "File %s Line %d Function GetCommState failed (%.8x)\n",
\r
48 __FILE__, __LINE__,(unsigned int) GetLastError());
\r
52 // some reasonable defaults even if we do not use Tx/Rx:
\r
53 Dcb.Parity=NOPARITY;
\r
56 Dcb.StopBits=ONESTOPBIT;
\r
58 Dcb.fDtrControl = DTR_CONTROL_ENABLE;
\r
59 Dcb.fRtsControl = RTS_CONTROL_ENABLE;
\r
60 ok = SetCommState(fd, &Dcb);
\r
62 fprintf(stderr, "File %s Line %d Function SetCommState failed (%.8x)\n",
\r
63 __FILE__, __LINE__,(unsigned int) GetLastError());
\r
69 int main(int argc, char *argv[])
\r
74 printf("USAGE: ddcp-script-ttyinit COMPORT\n");
\r
75 printf("Example: ddcp-script-ttyinit COM4\n");
\r
81 Sleep(100); // sleep: units are in 1/1000 sec
\r