Added handling of serial port DCB for Windows

This commit is contained in:
pe-jot 2021-02-23 16:24:04 +01:00
parent fe6cba2b0d
commit 4dff8ad93f
1 changed files with 46 additions and 32 deletions

View File

@ -180,17 +180,51 @@ typedef int HANDLE;
#if __WIN32__ #if __WIN32__
#define RTS_ON(fd) EscapeCommFunction(fd,SETRTS); void setRTS(HANDLE fd, unsigned char state)
#define RTS_OFF(fd) EscapeCommFunction(fd,CLRRTS); {
#define DTR_ON(fd) EscapeCommFunction(fd,SETDTR); if (!EscapeCommFunction(fd, state ? SETRTS : CLRRTS)) {
#define DTR_OFF(fd) EscapeCommFunction(fd,CLRDTR); return;
}
DCB dcb;
if (!GetCommState(fd, &dcb)) {
return;
}
dcb.fRtsControl = state ? RTS_CONTROL_ENABLE : RTS_CONTROL_DISABLE;
SetCommState(fd, &dcb);
}
void setDTR(HANDLE fd, unsigned char state)
{
if (!EscapeCommFunction(fd, state ? SETDTR : CLRDTR)) {
return;
}
DCB dcb;
if (!GetCommState(fd, &dcb)) {
return;
}
dcb.fDtrControl = state ? DTR_CONTROL_ENABLE : DTR_CONTROL_DISABLE;
SetCommState(fd, &dcb);
}
#else #else
#define RTS_ON(fd) { int stuff; ioctl (fd, TIOCMGET, &stuff); stuff |= TIOCM_RTS; ioctl (fd, TIOCMSET, &stuff); } void setRTS(HANDLE fd, unsigned char state)
#define RTS_OFF(fd) { int stuff; ioctl (fd, TIOCMGET, &stuff); stuff &= ~TIOCM_RTS; ioctl (fd, TIOCMSET, &stuff); } {
#define DTR_ON(fd) { int stuff; ioctl (fd, TIOCMGET, &stuff); stuff |= TIOCM_DTR; ioctl (fd, TIOCMSET, &stuff); } int bit = TIOCM_RTS;
#define DTR_OFF(fd) { int stuff; ioctl (fd, TIOCMGET, &stuff); stuff &= ~TIOCM_DTR; ioctl (fd, TIOCMSET, &stuff); } ioctl(fd, state ? TIOCMBIS : TIOCMBIC, &bit);
}
void setDTR(HANDLE fd, unsigned char state)
{
int bit = TIOCM_DTR;
ioctl(fd, state ? TIOCMBIS : TIOCMBIC, &bit);
}
#define LPT_IO_ADDR 0x378 #define LPT_IO_ADDR 0x378
@ -1182,21 +1216,11 @@ void ptt_set (int ot, int chan, int ptt_signal)
if (save_audio_config_p->achan[chan].octrl[ot].ptt_line == PTT_LINE_RTS) { if (save_audio_config_p->achan[chan].octrl[ot].ptt_line == PTT_LINE_RTS) {
if (ptt) { setRTS(ptt_fd[chan][ot], ptt);
RTS_ON(ptt_fd[chan][ot]);
}
else {
RTS_OFF(ptt_fd[chan][ot]);
}
} }
else if (save_audio_config_p->achan[chan].octrl[ot].ptt_line == PTT_LINE_DTR) { else if (save_audio_config_p->achan[chan].octrl[ot].ptt_line == PTT_LINE_DTR) {
if (ptt) { setDTR(ptt_fd[chan][ot], ptt);
DTR_ON(ptt_fd[chan][ot]);
}
else {
DTR_OFF(ptt_fd[chan][ot]);
}
} }
/* /*
@ -1205,21 +1229,11 @@ void ptt_set (int ot, int chan, int ptt_signal)
if (save_audio_config_p->achan[chan].octrl[ot].ptt_line2 == PTT_LINE_RTS) { if (save_audio_config_p->achan[chan].octrl[ot].ptt_line2 == PTT_LINE_RTS) {
if (ptt2) { setRTS(ptt_fd[chan][ot], ptt2);
RTS_ON(ptt_fd[chan][ot]);
}
else {
RTS_OFF(ptt_fd[chan][ot]);
}
} }
else if (save_audio_config_p->achan[chan].octrl[ot].ptt_line2 == PTT_LINE_DTR) { else if (save_audio_config_p->achan[chan].octrl[ot].ptt_line2 == PTT_LINE_DTR) {
if (ptt2) { setDTR(ptt_fd[chan][ot], ptt2);
DTR_ON(ptt_fd[chan][ot]);
}
else {
DTR_OFF(ptt_fd[chan][ot]);
}
} }
/* else neither one */ /* else neither one */