I would like to control an instrument operation by using a c++ program.
How do I use boost asio library to set the RTS pin to logical true or logical false? This is for a RS-232 serial port.
I would like to control an instrument operation by using a c++ program.
How do I use boost asio library to set the RTS pin to logical true or logical false? This is for a RS-232 serial port.
I ended up using the windows api (OS specific) approach to solve my problem.
#include <iostream>
#include <cstdlib>
#include <string>
#include <windows.h>
namespace comm{
class rs232
{
const HANDLE commDevice;
const DWORD clear_RTS = 4;
const DWORD set_RTS = 3;
public:
rs232( HANDLE commDeviceIn ): commDevice(commDeviceIn) {}
rs232( std::string commName )
: commDevice(CreateFileA(commName.data(),
GENERIC_READ | GENERIC_WRITE,
0,
0,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
0)) {}
void send_RTS_signal( void ) {
EscapeCommFunction( commDevice, set_RTS );
}
void clear_RTS_signal( void ) {
EscapeCommFunction( commDevice, clear_RTS );
}
};
}