Allow for setting DTR on a serial port

This commit is contained in:
Armin Wolf 2023-09-01 21:18:25 +02:00 committed by Adam Honse
parent 1996d34650
commit 0279aafb97
2 changed files with 48 additions and 0 deletions

View file

@ -660,6 +660,53 @@ void serial_port::serial_break()
#endif
}
void serial_port::serial_set_dtr(bool dtr)
{
/*-----------------------------------------------------*\
| Windows-specific code path for serial set DTR |
\*-----------------------------------------------------*/
#ifdef _WIN32
if(dtr)
{
EscapeCommFunction(file_descriptor, SETDTR);
}
else
{
EscapeCommFunction(file_descriptor, CLRDTR);
}
#endif
/*-----------------------------------------------------*\
| Linux-specific code path for serial set DTR |
\*-----------------------------------------------------*/
#ifdef __linux__
const int DTRFLAG = TIOCM_DTR;
if(dtr)
{
ioctl(file_descriptor, TIOCMBIS, &DTRFLAG);
}
else
{
ioctl(file_descriptor, TIOCMBIC, &DTRFLAG);
}
#endif
/*-----------------------------------------------------*\
| MacOS-specific code path for serial set DTR |
\*-----------------------------------------------------*/
#ifdef __APPLE__
const int DTRFLAG = TIOCM_DTR;
if(dtr)
{
ioctl(file_descriptor, TIOCMBIS, &DTRFLAG);
}
else
{
ioctl(file_descriptor, TIOCMBIC, &DTRFLAG);
}
#endif
}
void serial_port::serial_set_rts(bool rts)
{
/*-----------------------------------------------------*\

View file

@ -126,6 +126,7 @@ public:
void serial_flush_tx();
void serial_break();
void serial_set_dtr(bool dtr);
void serial_set_rts(bool rts);
int serial_available();