Programmers Reference - CDevice (1)
class CDevice : public CObject
#include "ConSysKernel.h"
The CDevice is the base class for all deviceses in the ConSys system. The class must be able to load dynamically (se CLibrary), so all descendant classes must be declared serial. There is no need for the serialize method, as the classes is not going to be serialised.
class KERNEL_EXT CDevice : public CObject { public: CDevice(); virtual ~CDevice(); virtual void Create(CDeviceDoc* pDoc); public: DECLARE_SERIAL(CDevice); public: virtual CDataValue* operator [](CAddress* address); // A address of NULL will return the status of the device. virtual void WriteValue(CAddress* address, CDataValue* value); // Writes a value to the device public: virtual BOOLEAN RegisterDataServer(CDeviceServer* aDataServer, const CAddress* aAddress, UINT minPollTime = 0 /* ms */); virtual BOOLEAN DeRegisterDataServer(CDeviceServer* aDataServer); public: // Functions for setting op the device. These functions is used // by the ConSysManager, and should be overwritten in decendants virtual CSingleDocTemplate* SingleDocTemplate() const; virtual CMultiDocTemplate* MultiDocTemplate() const; };
virtual void Create(CDeviceDoc* pDoc)
This method is called by the ConSys kernel when the device is loaded. This method is called directly after the device is dynamicaly created. The argument pDoc is a reference to the device document, containing the relevant information for the device. The actual runtime class of pDoc is determined by the templates returned by the SingleDocTemplate and MultiDocTemplate methods.
Minimize the initialization in the constructor of the device, and put the construction in the Create method. The constructor may be called at other time, ex. when the ConSys Manager wants to obtain a document template for handling device setup.
virtual CSingleDocTemplate* SingleDocTemplate() const
virtual CMultiDocTemplate* MultiDocTemplate() const
The document templates returned by the two methods is ued by setup programs to set up the device (se ConSys Manager). The default method simply returns the default configuration information:
CSingleDocTemplate(IDS_DEFAULT_DEVICE_TEMPLATE, RUNTIME_CLASS(CDeviceDoc), RUNTIME_CLASS(CFrameWnd), RUNTIME_CLASS(CDefaultDeviceView))
or for the multi document template
CMultiDocTemplate(IDS_DEFAULT_DEVICE_TEMPLATE, RUNTIME_CLASS(CDeviceDoc), RUNTIME_CLASS(CMDIChildWnd), RUNTIME_CLASS(CDefaultDeviceView))
Overriding method should modify the arguments to suite the own purposes. The instances templates returned by the methods is used to initiali create a document for the device class, and later to create a view for editing this document.
The instanceses of the templates must be deletetd by the calling application.
virtual CDataValue*
operator [](CAddress* address)
This is the main method in the device. It returns the data value specified by the address (se The Device Cookbook)
References:
Last Modified 10 January 2019