2005-12-22 11:40:53 -05:00
|
|
|
#include <windows.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2012-05-22 10:28:39 -04:00
|
|
|
int ptt_(int *nport, int *ntx, int *iptt)
|
2005-12-22 11:40:53 -05:00
|
|
|
{
|
|
|
|
static HANDLE hFile;
|
|
|
|
static int open=0;
|
|
|
|
char s[10];
|
2012-11-19 11:45:42 -05:00
|
|
|
int i3=1,i4=1,i5=1,i6=1,i9=1,i00=1;
|
2005-12-22 11:40:53 -05:00
|
|
|
|
|
|
|
if(*nport==0) {
|
|
|
|
*iptt=*ntx;
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(*ntx && (!open)) {
|
2012-11-19 11:45:42 -05:00
|
|
|
sprintf(s,"\\\\.\\COM%d",*nport);
|
2005-12-22 11:40:53 -05:00
|
|
|
hFile=CreateFile(TEXT(s),GENERIC_WRITE,0,NULL,OPEN_EXISTING,
|
|
|
|
FILE_ATTRIBUTE_NORMAL,NULL);
|
|
|
|
if(hFile==INVALID_HANDLE_VALUE) {
|
2012-05-22 10:28:39 -04:00
|
|
|
// printf("PTT: Cannot open COM port %d.\n",*nport);
|
|
|
|
return 1;
|
2005-12-22 11:40:53 -05:00
|
|
|
}
|
|
|
|
open=1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(*ntx && open) {
|
2012-10-28 11:47:43 -04:00
|
|
|
i3=EscapeCommFunction(hFile,3);
|
|
|
|
i5=EscapeCommFunction(hFile,5);
|
2005-12-22 11:40:53 -05:00
|
|
|
*iptt=1;
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
2012-10-28 11:47:43 -04:00
|
|
|
i4=EscapeCommFunction(hFile,4);
|
|
|
|
i6=EscapeCommFunction(hFile,6);
|
|
|
|
i9=EscapeCommFunction(hFile,9);
|
2005-12-22 11:40:53 -05:00
|
|
|
i00=CloseHandle(hFile);
|
|
|
|
*iptt=0;
|
|
|
|
open=0;
|
|
|
|
}
|
2012-11-19 11:45:42 -05:00
|
|
|
/*
|
2012-10-28 11:47:43 -04:00
|
|
|
if(i3==0) return 3;
|
|
|
|
if(i4==0) return 4;
|
|
|
|
if(i5==0) return 5;
|
|
|
|
if(i6==0) return 6;
|
|
|
|
if(i9==0) return 9;
|
|
|
|
if(i00==0) return 10;
|
2012-11-19 11:45:42 -05:00
|
|
|
*/
|
2012-05-22 10:28:39 -04:00
|
|
|
return 0;
|
2005-12-22 11:40:53 -05:00
|
|
|
}
|