From 1ed2fa8262061672777bcab9a7ce9141f68a3f9e Mon Sep 17 00:00:00 2001 From: Joe Taylor Date: Thu, 5 Jan 2006 19:39:21 +0000 Subject: [PATCH] Fleshed out ptt_linux.c to control DTR/RTS lines on serial port. git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/trunk@48 ab8295b8-cf94-4d9e-aec4-7959e3be5d79 --- ptt_linux.c | 53 ++++++++++++++++++++++++++++++++--------------------- wsjt.py | 2 +- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/ptt_linux.c b/ptt_linux.c index a174cb67b..f0f0c3a6f 100644 --- a/ptt_linux.c +++ b/ptt_linux.c @@ -1,41 +1,52 @@ +#include #include +#include +#include +#include int ptt_(int *nport, int *ntx, int *iptt) { - static int open=0; - char s[10]; - // int i3,i4,i5,i6,i9,i00; + static int nopen=0; + int i; + int fd; + char s[11]; - if(*nport==0) { + if(*nport < 0) { *iptt=*ntx; return(0); } - if(*ntx && (!open)) { - sprintf(s,"COM%d",*nport); - // hFile=CreateFile(TEXT(s),GENERIC_WRITE,0,NULL,OPEN_EXISTING, - // FILE_ATTRIBUTE_NORMAL,NULL); - // if(hFile==INVALID_HANDLE_VALUE) { - // printf("PTT: Cannot open COM port %d.\n",*nport); - // return(1); - // } - open=1; + if(*ntx && (!nopen)) { + sprintf(s,"/dev/ttyS%d",*nport); + //open the device + if ((fd = open(s, O_RDWR | O_NDELAY)) < 0) { + fprintf(stderr, "device not found"); + return(1); + } + nopen=1; return(0); } - if(*ntx && open) { - // EscapeCommFunction(hFile,3); - // EscapeCommFunction(hFile,5); + //enable privileges for I/O port controls + if(ioperm(0,0x3ff,1) < 0) { + printf("Cannot set privileges for serial I/O\n"); + return(1); + } + + // ioctl(fd, TIOCMGET, &flags); //get line bits for serial port + + if(*ntx && nopen) { + i = TIOCM_RTS + TIOCM_DTR; + ioctl(fd, TIOCMSET, &i); // Set DTR and RTS *iptt=1; } else { - // EscapeCommFunction(hFile,4); - // EscapeCommFunction(hFile,6); - // EscapeCommFunction(hFile,9); - // i00=CloseHandle(hFile); + i=0; + ioctl(fd, TIOCMSET, &i); + close(fd); *iptt=0; - open=0; + nopen=0; } return(0); } diff --git a/wsjt.py b/wsjt.py index e29f59c40..fb3c16301 100644 --- a/wsjt.py +++ b/wsjt.py @@ -1,4 +1,4 @@ -#---------------------------------------------------------- WSJT +#----------------------------------------------------------- WSJT from Tkinter import * from tkFileDialog import * import Pmw