Skip to content

Commit 0279aaf

Browse files
Wer-WolfCalcProgrammer1
authored andcommitted
Allow for setting DTR on a serial port
1 parent 1996d34 commit 0279aaf

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

serial_port/serial_port.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,53 @@ void serial_port::serial_break()
660660
#endif
661661
}
662662

663+
void serial_port::serial_set_dtr(bool dtr)
664+
{
665+
/*-----------------------------------------------------*\
666+
| Windows-specific code path for serial set DTR |
667+
\*-----------------------------------------------------*/
668+
#ifdef _WIN32
669+
if(dtr)
670+
{
671+
EscapeCommFunction(file_descriptor, SETDTR);
672+
}
673+
else
674+
{
675+
EscapeCommFunction(file_descriptor, CLRDTR);
676+
}
677+
#endif
678+
679+
/*-----------------------------------------------------*\
680+
| Linux-specific code path for serial set DTR |
681+
\*-----------------------------------------------------*/
682+
#ifdef __linux__
683+
const int DTRFLAG = TIOCM_DTR;
684+
if(dtr)
685+
{
686+
ioctl(file_descriptor, TIOCMBIS, &DTRFLAG);
687+
}
688+
else
689+
{
690+
ioctl(file_descriptor, TIOCMBIC, &DTRFLAG);
691+
}
692+
#endif
693+
694+
/*-----------------------------------------------------*\
695+
| MacOS-specific code path for serial set DTR |
696+
\*-----------------------------------------------------*/
697+
#ifdef __APPLE__
698+
const int DTRFLAG = TIOCM_DTR;
699+
if(dtr)
700+
{
701+
ioctl(file_descriptor, TIOCMBIS, &DTRFLAG);
702+
}
703+
else
704+
{
705+
ioctl(file_descriptor, TIOCMBIC, &DTRFLAG);
706+
}
707+
#endif
708+
}
709+
663710
void serial_port::serial_set_rts(bool rts)
664711
{
665712
/*-----------------------------------------------------*\

serial_port/serial_port.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class serial_port
126126
void serial_flush_tx();
127127
void serial_break();
128128

129+
void serial_set_dtr(bool dtr);
129130
void serial_set_rts(bool rts);
130131

131132
int serial_available();

0 commit comments

Comments
 (0)