Hi there, I found an example for i/o on a comport, although, I don't believe I'm getting anything on the read side of things, can anybody point me in the right direction
serial.h
/** Serial.h
*
* A very simple serial port control class that does NOT require MFC/AFX.
*
* License: This source code can be used and/or modified without restrictions.
* It is provided as is and the author disclaims all warranties, expressed
* or implied, including, without limitation, the warranties of
* merchantability and of fitness for any purpose. The user must assume the
* entire risk of using the Software.
*
* @author Hans de Ruiter
*
* @version 0.1 -- 28 October 2008
*/
#ifndef __SERIAL_H__
#define __SERIAL_H__
#include <string>
#include <windows.h>
typedef std::basic_string<TCHAR> tstring;
class Serial
{
private:
HANDLE commHandle;
public:
Serial(tstring &commPortName, int bitRate = 115200);
virtual ~Serial();
/** Writes a NULL terminated string.
*
* @param buffer the string to send
*
* @return int the number of characters written
*/
int write(constchar buffer[]);
/** Writes a string of bytes to the serial port.
*
* @param buffer pointer to the buffer containing the bytes
* @param buffLen the number of bytes in the buffer
*
* @return int the number of bytes written
*/
int write(constchar *buffer, int buffLen);
/** Reads a string of bytes from the serial port.
*
* @param buffer pointer to the buffer to be written to
* @param buffLen the size of the buffer
* @param nullTerminate if set to true it will null terminate the string
*
* @return int the number of bytes read
*/
int read(char *buffer, int buffLen, bool nullTerminate = true);
/** Flushes everything from the serial port's read buffer
*/
void flush();
};
#endif
What is the physical port being used for the serial comms? Assuming it is USB, then one way is to get a USB-to RS232 DB9 convertor (preferably with lights). Something like:
DB 9 connector, connect together pins 2 & 3 (assuming no hardware flow control). Then whatever is sent to the serial will come back as received. This is what used to be known as a serial loop-back connector.
As the convertor has lights, you can see the serial data being sent and received to help with testing/debugging.
*Well, obviously Windows "knows" if the PC has COM ports or not, you can see what COM ports are available by the Device Manager app, so it is possible to programmatically to find out what COM ports are available. To actually read and write to those ports requires a device attached, though.
> do I have any options to emulate writing something to a virtual comport and my app reading it?
> I don't have any HW devices and it's for a distant project so I won't ever get to test hands on.