WINDEX
Public Member Functions | List of all members
wex::com Class Reference

read / write to COM serial port More...

#include <com.h>

Inheritance diagram for wex::com:
wex::gui

Public Member Functions

 com (gui *parent)
 CTOR. More...
 
bool open ()
 Open connection to port. More...
 
void close ()
 
void read (int needed)
 blocking read from COM port More...
 
std::vector< unsigned char > readData ()
 get reference to buffer containg data that was read
 
void read_async (int bytes)
 non-blocking read from COM port More...
 
int write (const std::vector< unsigned char > &buffer)
 Write buffer of data to the COM port.
 
int write (const std::string &msg)
 Write string of data to the COM port.
 
Setters
void port (const std::string &port)
 Set port number to which connection will be made.
 
void overlapped (bool f=true)
 Enable/Disable open connection overlapped. More...
 
void CTSFlowControl (bool f=true)
 Enable/Disable CTS flow control. More...
 
void DeviceControlString (const std::string &controlString)
 Configure device. More...
 
void baud (int rate)
 
void deviceInputBuffer (int length)
 set device input buffer length More...
 
Getters
const std::string & portNumber () const
 
int baud ()
 
bool isOpen ()
 true if connected
 
std::string configText ()
 Get human readable port configuration. More...
 
std::string & errorMsg ()
 
- Public Member Functions inherited from wex::gui
 gui ()
 Construct top level window with no parent. More...
 
 gui (gui *parent, const char *window_class="windex", unsigned long style=WS_CHILD, unsigned long exstyle=WS_EX_CONTROLPARENT)
 Construct child of a parent. More...
 
void child (gui *w)
 register child on this window
 
children_t & children ()
 get vector of children
 
guiparent ()
 
guifind (int id)
 find child window with specified id
 
void focus ()
 
void bgcolor (int color)
 Change background color. More...
 
void nobgerase ()
 
void enable (bool f=true)
 Enable/Disable, default enable.
 
bool isEnabled () const
 
void fontHeight (int h)
 Change font height for this and all child windows.
 
void fontName (const std::string &name)
 
void icon (const std::string &iconfilename)
 Change icon. More...
 
void cursor (char *cursorID)
 
int id ()
 
int bgcolor () const
 
void textColor (int c)
 Set text color. More...
 
void text (const std::string &text)
 
std::string text () const
 
void scroll (bool fHoriz=true)
 Add scrollbars. More...
 
void scrollRange (int width, int height)
 Set the scrolling range. More...
 
sMouse getMouseStatus ()
 Get mouse status. More...
 
void run ()
 Run the windows message loop. More...
 
void tooltip (const std::string &text, int width=0)
 Add tooltip that pops up helpfully when mouse cursor hovers over widget. More...
 
virtual LRESULT WindowMessageHandler (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
virtual void show (bool f=true)
 Show window and all children.
 
void showModal (gui &appWindow)
 Show this window and suspend all other windows interactions until this is closed. More...
 
void endModal ()
 Stop modal interaction and close window.
 
void update ()
 force widget to redraw completely More...
 
void move (const std::vector< int > &r)
 Move the window. More...
 
void size (int w, int h)
 Change size without moving top left corner. More...
 
void move (int x, int y)
 Change position without changing size. More...
 
void move (int x, int y, int w, int h)
 
std::vector< int > size ()
 Size of window client area. More...
 
std::vector< int > lefttop ()
 
eventhandlerevents ()
 Get event handler.
 
HWND handle ()
 get window handle
 
void delete_list (std::vector< HWND > *list)
 set delete list for when gui is detroyed
 
void setfont (LOGFONT &logfont, HFONT &font)
 change font for this and all child windows
 
void setAsyncReadCompleteMsgID (int id)
 

Additional Inherited Members

- Protected Member Functions inherited from wex::gui
void Create (HWND parent, const char *window_class, DWORD style, DWORD exstyle=0, int id=0)
 Create the managed window. More...
 
void font (LOGFONT &logfont, HFONT &font)
 get font details More...
 
void createNewFont ()
 Replace font used by this and child windows from logfont.
 
virtual void draw (PAINTSTRUCT &ps)
 
int NewID ()
 Create new, unique ID for gui element. More...
 
int scrollMove (SCROLLINFO &si, int code)
 
- Protected Attributes inherited from wex::gui
HWND myHandle
 
guimyParent
 
eventhandler myEvents
 
int myBGColor
 
int myTextColor
 
HBRUSH myBGBrush
 
LOGFONT myLogFont
 
HFONT myFont
 
std::vector< HWND > * myDeleteList
 
std::string myText
 
int myID
 
std::vector< gui * > myChild
 gui elements to be displayed in this window
 
bool myfModal
 true if element is being shown as modal
 
bool myfEnabled
 true if not disabled
 
bool myfnobgerase
 
HWND myToolTip
 
unsigned int myAsyncReadCompleteMsgID
 handle to tooltip control for this gui element
 
char * myCursorID
 
bool myfScrollHoriz
 

Detailed Description

read / write to COM serial port

For sample code, see https://github.com/JamesBremner/windex/blob/master/demo/com.cpp

Constructor & Destructor Documentation

◆ com()

wex::com::com ( gui parent)
inline

CTOR.

Parameters
[in]parentwindow which will receive messages when async read has completed

Member Function Documentation

◆ configText()

std::string wex::com::configText ( )
inline

Get human readable port configuration.

Returns
string

◆ CTSFlowControl()

void wex::com::CTSFlowControl ( bool  f = true)
inline

Enable/Disable CTS flow control.

Parameters
[in]ftrue to enable, default true

If this is TRUE, the CTS (clear-to-send) signal is monitored for output flow control. If this is TRUE and CTS is turned off, output is suspended until CTS is sent again.

This must be called before the port is opened.

◆ DeviceControlString()

void wex::com::DeviceControlString ( const std::string &  controlString)
inline

Configure device.

Parameters
[in]controlStringThe device-control information.

The device must be open.

Control sring format [baud=b][parity=p][data=d][stop=s][to={on|off}][xon={on|off}][odsr={on|off}][octs={on|off}][dtr={on|off|hs}][rts={on|off|hs|tg}][idsr={on|off}]

For example, the following string specifies a baud rate of 1200, no parity, 8 data bits, and 1 stop bit:

baud=1200 parity=N data=8 stop=1

◆ deviceInputBuffer()

void wex::com::deviceInputBuffer ( int  length)
inline

set device input buffer length

Parameters
lengthoutput buffer remains at defualt ( 4K ) This must be called before the call to open

◆ open()

bool wex::com::open ( )
inline

Open connection to port.

Returns
true if succesful

Opens with default configuration "baud=9600 parity=N data=8 stop=1"

Reconfigure with DeviceControlString()

On error, a mesage will be available by calling errorMsg();

◆ overlapped()

void wex::com::overlapped ( bool  f = true)
inline

Enable/Disable open connection overlapped.

Parameters
[in]ftrue to enable overlapped, default true

If the COM port is opened overlapped

  • read/writes are asynvhronous
  • port csn be used for both reading and writing

This must be called before the port is opened.

◆ read()

void wex::com::read ( int  needed)
inline

blocking read from COM port

Parameters
[in]neededbyte count, -1 to read whatever becomes available

Data will be read into a vector of bytes, com::ReadData() provides a reference to this.

◆ read_async()

void wex::com::read_async ( int  bytes)
inline

non-blocking read from COM port

Parameters
[in]bytesbyte count to be read, -1 to read whatever becomes available

This will return imediatly.

When the specified bytes have been read the parent window event <pr>asyncReadComplete will invoke its read handler in the thread that created the parent window. No multithreading is required by the application code.

This uses the message

id = WM_APP+1

, which must NOT be used anywhere in the application code.


The documentation for this class was generated from the following file: