Skip to content

Commit d7720e0

Browse files
committed
Set baud rate in COM port
1 parent 8cca943 commit d7720e0

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

include/com.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,26 @@ class com : public gui
100100
return myCOMHandle != 0;
101101
}
102102

103+
int baud()
104+
{
105+
if( ! isOpen() )
106+
return 0;
107+
DCB dcbSerialParams = { 0 }; // Initializing DCB structure
108+
dcbSerialParams.DCBlength = sizeof(dcbSerialParams);
109+
GetCommState(myCOMHandle, &dcbSerialParams);
110+
return dcbSerialParams.BaudRate;
111+
}
112+
void baud( int rate )
113+
{
114+
if( ! isOpen() )
115+
return;
116+
DCB dcbSerialParams = { 0 }; // Initializing DCB structure
117+
dcbSerialParams.DCBlength = sizeof(dcbSerialParams);
118+
GetCommState(myCOMHandle, &dcbSerialParams);
119+
dcbSerialParams.BaudRate = rate;
120+
SetCommState(myCOMHandle, &dcbSerialParams);
121+
}
122+
103123
/** blocking read from COM port
104124
@param[in] needed byte count, -1 to read whatever becomes available
105125

0 commit comments

Comments
 (0)