Serial Port Monitoring Control - ActiveX Component Library for RS232 Data Monitoring, API for Software Developers
Docs

How To Receive Monitored Events

This section describes the steps you need to carry in order to receive monitored events in your code.

  1. Obtain the Monitor object, as described in this tutorial.

  2. Add your listener object (for native code) to the Monitor object or connect event handlers (for managed code):

    class CMyListener : CComObjectRoot<CMyListener>, public INativeListener
    {
    public:
        // override all pure virtual methods in the INativeListener
    };
    
    ...
    
    CComObject<CMyListener> pMyListenerObject;
    CComObject<CMyListener>::CreateInstance(&pMyListenerObject);
    CComPtr<INativeListener> pMyListener;
    pMyListenerObject->QueryInterface(&pMyListener);
    pMonitor->AddNativeListener(pMyListener);
    
    monitor.OnOpen += new hhdspmcLib._IMonitoringEvents_OnOpenEventHandler(monitor_OnOpen);
    monitor.OnPurge += new hhdspmcLib._IMonitoringEvents_OnPurgeEventHandler(monitor_OnPurge);
    monitor.OnRead += new hhdspmcLib._IMonitoringEvents_OnReadEventHandler(monitor_OnRead);
    ...
    
  3. Attach the Monitor object to the serial device:

    • Attach to the given serial device:
    pMonitor->Connect(CComVariant(pDevice));
    
    monitor.Connect(device);
    
    • Attach to the serial device connected to the COM port:
    pMonitor->Connect(CComVariant(L"COM1"));
    
    monitor.Connect("COM1");
    
    • Attach to the next serial device the user plugs into the computer:
    pMonitor->Connect(CComVariant {VT_EMPTY});
    
    monitor.Connect();