0
votes

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.

1
Boost isn't up to that job, writing cross-platform code invariably involves cutting corners. You need to use the OS api to do this. Don't keep it a secret. - Hans Passant
Does this mean that the boost asio library is not able to manually manipulate pins/signals on a serial cable? - Raymond Valdes

1 Answers

1
votes

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 );
  }
};

}