C12Adapter Opensource C++ Interface
MChannelOpticalProbe Class Reference

Optical probe is a channel based on serial port that is able to control the batteries of the probe (if it exists). More...

Inheritance diagram for MChannelOpticalProbe:

Public Member Functions

 MChannelOpticalProbe ()
 Object constructor.
 
virtual ~MChannelOpticalProbe ()
 Object destructor.
 
virtual void Connect ()
 Establishes the connection to the meter using the optical probe. More...
 
virtual void Disconnect ()
 Disconnect brings down the connection and releases the serial port resource. More...
 
bool GetBatteryState () const
 
void SetBatteryState (bool power)
 
bool GetBatteryControlDtrHigh () const
 
void SetBatteryControlDtrHigh (bool yes)
 
bool GetBatteryControlRtsHigh () const
 
void SetBatteryControlRtsHigh (bool yes)
 
- Public Member Functions inherited from MChannelSerialPort
 MChannelSerialPort ()
 Construct serial port channel.
 
virtual ~MChannelSerialPort ()
 Destructor.
 
virtual void FlushOutputBuffer (unsigned numberOfCharsInBuffer=UINT_MAX)
 Ensure that the characters from the output buffer are sent. More...
 
virtual bool IsConnected () const
 Returns the current connection state of the serial port channel.
 
virtual void WaitForNextIncomingConnection (bool reinitialize=true)
 When GetAutoAnswer true, wait for the incoming connection without disconnecting the channel. More...
 
void SetParameters (unsigned baud, int dataBits, char parity, int stopBits)
 SetParameters is a convenience function for setting the properties baud rate, number of data bits, parity, and number of stop bits in a single call.
 
bool GetDCD () const
 The current state of the DCD signal of the port. More...
 
virtual MStdString GetMediaIdentification () const
 Return a string that will identify the media through which this channel is talking to. More...
 
const MStdStringGetPortName () const
 
void SetPortName (const MStdString &portName)
 
unsigned GetBaud () const
 
void SetBaud (unsigned baud)
 
char GetParity () const
 
void SetParity (char p)
 
int GetStopBits () const
 
void SetStopBits (int stopBits)
 
int GetDataBits () const
 
void SetDataBits (int dataBits)
 
bool GetCtsFlow () const
 
void SetCtsFlow (bool isCtsFlow)
 
bool GetDsrFlow () const
 
void SetDsrFlow (bool isDsrFlow)
 
bool GetDsrSensitivity () const
 
void SetDsrSensitivity (bool isDsrSens)
 
char GetDtrControl () const
 
void SetDtrControl (char dtrControl)
 
char GetRtsControl () const
 
void SetRtsControl (char rtsControl)
 
MSerialPortGetPort ()
 
const MSerialPortGetPort () const
 
- Public Member Functions inherited from MChannel
virtual MChannelCreateClone () const
 Virtual copy constructor, creates the channel, which is a clone of current. More...
 
virtual ~MChannel ()
 The destructor is public, and virtual. More...
 
void WriteBytes (const MByteString &buffer)
 Writes the data to the channel, and returns when the last byte has been sent by the software. More...
 
void WriteByte (Muint8 b)
 Writes a byte to the channel, and returns when it has been sent. More...
 
void WriteBuffer (const char *buf, unsigned len)
 Writes the data buffer to the channel, and returns when the last character has been sent by the software (but hardware might still need to do some work). More...
 
Muint8 ReadByte ()
 Read a single byte from the channel. More...
 
void ReadBuffer (char *buf, unsigned numberToRead)
 Read an exact number of characters from the channel. More...
 
void Unread (const MVariant &byteOrBytes)
 Return the given byte or bytes to the stream buffer so they get read at the next read operation. More...
 
void UnreadBuffer (const char *buff, unsigned size)
 Return the given bytes to the stream buffer so they get read at the next read operation. More...
 
MByteString ReadBytes (unsigned numberToRead)
 Read bytes directly from the communication channel. More...
 
MByteString ReadBytesUntil (const MByteString &terminatingString)
 Read bytes from the channel until a specified sequence is read. More...
 
MByteString ReadBytesUntilAnyByte (const char *finisher, unsigned finisherSize, unsigned headerSize, unsigned footerSize)
 Read bytes from the channel until a specified sequence is read. More...
 
MByteString ReadAllBytes ()
 Read an arbitrary number of characters from the channel, as much as available. More...
 
void ClearInputBuffer ()
 Immediately discards all the pending characters from the channel. More...
 
void ClearInputUntilSilence (unsigned milliseconds)
 Keep reading and ignoring input until there is silence. More...
 
virtual void CheckIfConnected ()
 Throw an appropriate exception if the channel is not connected. More...
 
void CheckIfConnectedConst () const
 Throw an appropriate exception if the channel is not connected, constant version. More...
 
unsigned GetCountBytesSent () const
 Number of bytes sent through the channel since its creation or since the last ResetCounts(). More...
 
unsigned GetCountBytesReceived () const
 The number of bytes received through the channel since creation or since the last ResetCounts(). More...
 
void ResetCounts ()
 Reset channel statistical data, so the counters become zeros. More...
 
virtual void WriteToMonitor (const MStdString &message)
 Synchronously write a message to the monitor, if it is connected. More...
 
virtual void CancelCommunication (bool callDisconnect=false)
 Request canceling of the communication. More...
 
void EnterUninterruptibleCommunication (bool notify=true)
 Enter a communication sequence that shall not be be interrupted with CancelCommunication call. More...
 
void LeaveUninterruptibleCommunication (bool notify=true)
 Leave a communication sequence that shall not be be interrupted with CancelCommunication call. More...
 
void CheckIfOperationIsCancelled ()
 Check if the user has requested the termination of the communication, and whether the cancel operation lock is zero. More...
 
void Sleep (unsigned milliseconds)
 Channel version of Sleep, a delay function that is aware of cancel communication event. More...
 
unsigned ReadWithTimeout (char *buf, unsigned size, unsigned timeout)
 Read up to size bytes into buffer using the given timeout. More...
 
bool GetAutoAnswer () const
 
void SetAutoAnswer (bool isAutoAnswer)
 
unsigned GetAutoAnswerTimeout () const
 
void SetAutoAnswerTimeout (unsigned timeout)
 
void SetMonitor (MMonitor::Pointer monitor)
 
MMonitor::Pointer GetMonitor () const
 
SHOW_INTERNAL bool GetEcho () const
 
void SetEcho (bool echo)
 
bool GetSendEchoBytesToMonitor () const
 
void SetSendEchoBytesToMonitor (bool doSend)
 
unsigned GetIntercharacterTimeout () const
 
void SetIntercharacterTimeout (unsigned timeout)
 
unsigned GetReadTimeout () const
 
void SetReadTimeout (unsigned timeout)
 
unsigned GetWriteTimeout () const
 
void SetWriteTimeout (unsigned timeout)
 
- Public Member Functions inherited from MCOMObject
virtual ~MCOMObject ()
 Object destructor.
 
virtual MStdStringVector GetAllPropertyNames () const
 Return the list of publicly available properties in MCOM syntax. More...
 
virtual MStdStringVector GetAllPersistentPropertyNames () const
 Return the list of publicly available persistent properties in MCOM syntax. More...
 
MStdString GetPersistentPropertyValues (bool onlyNondefaults=false, bool excludeSecurityRelated=false) const
 Get the string with the list of persistent property names and their values. More...
 
void SetPersistentPropertyValues (const MStdString &values)
 Set the persistent properties for the object using the string with the following format: More...
 
void SetPropertyValues (const MDictionary &values)
 Set the properties for the object using the property list object. More...
 
void WritePropertiesToMonitor ()
 Write all non-default values of protocol properties into monitor. More...
 
MStdString DoGetPersistentPropertyValues0 () const
 Get the string with the whole list of persistent property names and their values. More...
 
MStdString DoGetPersistentPropertyValues1 (bool onlyNondefaults) const
 Get the string with the list of persistent property names and their values. More...
 
- Public Member Functions inherited from MObject
virtual ~MObject ()
 Object destructor.
 
virtual const MClassGetClass () const =0
 Get the final class of the object. More...
 
virtual unsigned GetEmbeddedSizeof () const
 For embedded object types, return the size of the class. More...
 
bool IsEmbeddedObject () const
 Tell if the object is of embedded kind. More...
 
SHOW_INTERNAL MVariant Call (const MStdString &name, const MVariant &params)
 Call the object service with parameters, given as variant. More...
 
MVariant Call0 (const MStdString &name)
 Call the object service with no parameters. More...
 
MVariant Call1 (const MStdString &name, const MVariant &p1)
 Call the object service with one parameter. More...
 
MVariant Call2 (const MStdString &name, const MVariant &p1, const MVariant &p2)
 Call the object service with two parameter. More...
 
MVariant Call3 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3)
 Call the object service with three parameter. More...
 
MVariant Call4 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4)
 Call the object service with four parameter. More...
 
MVariant Call5 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4, const MVariant &p5)
 Call the object service with five parameter. More...
 
MVariant Call6 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4, const MVariant &p5, const MVariant &p6)
 Call the object service with six parameter. More...
 
virtual MVariant CallV (const MStdString &name, const MVariant::VariantVector &params)
 Call the object service with parameters, given as variant vector. More...
 
virtual bool IsPropertyPresent (const MStdString &name) const
 Tell if the property with the given name exists.
 
virtual bool IsServicePresent (const MStdString &name) const
 Tell if the service with the given name exists.
 
virtual MVariant GetProperty (const MStdString &name) const
 Get the property value using name of the property. More...
 
virtual void SetProperty (const MStdString &name, const MVariant &value)
 Set the property using name of the property, and value. More...
 
virtual void SetPersistentPropertiesToDefault ()
 Set the persistent properties of the object to their default values. More...
 
virtual MVariant GetPersistentPropertyDefaultValue (const MStdString &name) const
 Get the default value of persistent property with the name given. More...
 
virtual void SetPersistentPropertyToDefault (const MStdString &name)
 Set the persistent property with the name given to default value. More...
 
virtual const char * GetType () const
 Get the name of the type for the object (could be the same as class name).
 
virtual void SetType (const MStdString &)
 Intentionally, it will set the name of the type for the object, but the service will not allow setting the name to anything other than the current name. More...
 
virtual void Validate ()
 Validate internal structures of the object. More...
 

Additional Inherited Members

- Public Types inherited from MChannel
enum  { CANCEL_COMMUNICATION_CHECK_OPTIMUM_INTERVAL = 1000 }
 
- Static Public Member Functions inherited from MChannelSerialPort
static MStdStringVector GetAvailablePortNames (bool addExtraInfo=false)
 Return a collection of serial port names available at this computer. More...
 
static MStdString GetPortType (const MStdString &portName)
 Get type based on the port name. More...
 
- Static Public Member Functions inherited from MObject
static const MClassGetStaticClass ()
 Get the declared class of this particular object. More...
 
static bool IsClassPresent (const MStdString &name)
 Tells if the given class name is available. More...
 
- Static Public Attributes inherited from MObject
static const MClass s_class
 Class of MObject.
 
- Protected Member Functions inherited from MChannel
 MChannel ()
 Construct the channel object from parent class. More...
 
- Protected Member Functions inherited from MCOMObject
 MCOMObject ()
 Object constructor, protected as the class is abstract.
 
- Protected Member Functions inherited from MObject
 MObject ()
 Object constructor, protected as the class is abstract.
 
void DoSetPersistentPropertiesToDefault (const MClass *staticClass)
 Set the persistent properties to their default values for one object provided the class for that object. More...
 

Detailed Description

Optical probe is a channel based on serial port that is able to control the batteries of the probe (if it exists).

The optical probe channel exports all properties of its parent class, plus the following properties through the property dispatch mechanism:

  • BATTERY_STATE, type bool, the current state of the batteries, if those are present.
  • BATTERY_CONTROL_DTR_HIGH, type bool, whether the DTR has to be high to turn the battery on.
  • BATTERY_CONTROL_RTS_HIGH, type bool, whether the DTR has to be high to turn the battery on.

More information on property handling and error treatment is given within descriptions for property accessors and modifiers.

MChannelOpticalProbe inherits its properties from MChannelSerialPort. Several serial control lines are re-assigned to operate probe features such as battery control and RTS sense. For this channel type, Connect acquires the communication port from the Operating System, sets IsConnected to True, and returns.

Member Function Documentation

virtual void MChannelOpticalProbe::Connect ( )
virtual

Establishes the connection to the meter using the optical probe.

In addition to serial port connection, this particular service turns on probe batteries (if they are present).

Precondition
IsConnected should be false before calling this method. Many OS and program exceptions can be thrown by this method.

Reimplemented from MChannelSerialPort.

virtual void MChannelOpticalProbe::Disconnect ( )
virtual

Disconnect brings down the connection and releases the serial port resource.

In additional to the parent implementation, the optical probe switches the batteries off.

Reimplemented from MChannelSerialPort.

bool MChannelOpticalProbe::GetBatteryControlDtrHigh ( ) const
inline

Whether the DTR signal has to be high in order to switch the battery on.

The Data Terminal Ready (DTR) line is used with the Request To Send (RTS) line to turn the optical probe battery power On / Off. Refer to the technical specifications for the probe being used to determine the correct state for each line. Typically, the DTR and RTS signals are mutually exclusive (one true, one false).

BatteryControlDtrHigh must be set prior to a call to Connect because the optical probe batteries have to be turned on when the connection is established (this is just a convention if there are no batteries). This property overrides the DtrControl property.

Since
MeteringSDK Version 2.1.27.
Default value:
False : As required by the standard ABB/Elster probe.
Possible values:
  • True [1] : DTR has to be high to turn the battery on.
  • False [0] : DTR has to be low to turn the battery on.
bool MChannelOpticalProbe::GetBatteryControlRtsHigh ( ) const
inline

Whether the RTS signal has to be high in order to switch the battery on.

The Request To Send (RTS) line is used with the Data Terminal Ready (DTR) line to turn the optical probe battery power On / Off. Refer to the technical specifications for the probe being used to determine the correct state for each line. Typically, the RTS and DTR signals are mutually exclusive (one true, one false).

BatteryControlRtsHigh must be set prior to a call to Connect because the optical probe batteries have to be turned on when the connection is established (this is just a convention if there are no batteries). This property overrides the RtsControl property.

Since
MeteringSDK Version 2.1.27.
Default value:
True : As required by the standard ABB/Elster probe.
Possible values:
  • True [1] : RTS has to be high to turn the battery on.
  • False [0] : RTS has to be low to turn the battery on.
bool MChannelOpticalProbe::GetBatteryState ( ) const

The state of the probe's batteries.

This dynamic non-persistent property is used to get or set the battery power state explicitly. If the optical probe does not use the batteries, this property is still handled to enable or disable the communication.

This property is controlled by Connect and Disconnect services, when the optical probe communication is established or severed. It may be necessary to set it if the connection stays for a long time, but the communication is inactive.

The logic sense of the battery control lines is set by BatteryControlDtrHigh and BatteryControlRtsHigh

Since
MeteringSDK Version 2.1.27.
Default value:
False : The batteries are off.
Possible values:
  • True [1] : Turn the battery On. If the battery had been previously turned off (which sets DtrControl = D), turning the battery back on will restore the value of DtrControl to what it is was prior to turning off the battery.
  • False [0] : Turn the battery Off (DtrControl will be set to D)
void MChannelOpticalProbe::SetBatteryControlDtrHigh ( bool  yes)
inline

Whether the DTR signal has to be high in order to switch the battery on.

The Data Terminal Ready (DTR) line is used with the Request To Send (RTS) line to turn the optical probe battery power On / Off. Refer to the technical specifications for the probe being used to determine the correct state for each line. Typically, the DTR and RTS signals are mutually exclusive (one true, one false).

BatteryControlDtrHigh must be set prior to a call to Connect because the optical probe batteries have to be turned on when the connection is established (this is just a convention if there are no batteries). This property overrides the DtrControl property.

Since
MeteringSDK Version 2.1.27.
Default value:
False : As required by the standard ABB/Elster probe.
Possible values:
  • True [1] : DTR has to be high to turn the battery on.
  • False [0] : DTR has to be low to turn the battery on.
void MChannelOpticalProbe::SetBatteryControlRtsHigh ( bool  yes)
inline

Whether the RTS signal has to be high in order to switch the battery on.

The Request To Send (RTS) line is used with the Data Terminal Ready (DTR) line to turn the optical probe battery power On / Off. Refer to the technical specifications for the probe being used to determine the correct state for each line. Typically, the RTS and DTR signals are mutually exclusive (one true, one false).

BatteryControlRtsHigh must be set prior to a call to Connect because the optical probe batteries have to be turned on when the connection is established (this is just a convention if there are no batteries). This property overrides the RtsControl property.

Since
MeteringSDK Version 2.1.27.
Default value:
True : As required by the standard ABB/Elster probe.
Possible values:
  • True [1] : RTS has to be high to turn the battery on.
  • False [0] : RTS has to be low to turn the battery on.
void MChannelOpticalProbe::SetBatteryState ( bool  power)

The state of the probe's batteries.

This dynamic non-persistent property is used to get or set the battery power state explicitly. If the optical probe does not use the batteries, this property is still handled to enable or disable the communication.

This property is controlled by Connect and Disconnect services, when the optical probe communication is established or severed. It may be necessary to set it if the connection stays for a long time, but the communication is inactive.

The logic sense of the battery control lines is set by BatteryControlDtrHigh and BatteryControlRtsHigh

Since
MeteringSDK Version 2.1.27.
Default value:
False : The batteries are off.
Possible values:
  • True [1] : Turn the battery On. If the battery had been previously turned off (which sets DtrControl = D), turning the battery back on will restore the value of DtrControl to what it is was prior to turning off the battery.
  • False [0] : Turn the battery Off (DtrControl will be set to D)