C12Adapter Opensource C++ Interface
MProtocol Class Referenceabstract

Abstraction of a communication protocol. More...

Inheritance diagram for MProtocol:

Classes

struct  TableRawData
 Table raw data associated with the table number. More...
 

Public Types

enum  {
  MAXIMUM_NUMBER_STRING_SIZE = 64,
  MAXIMUM_SERVICE_NAME_STRING_SIZE = MAXIMUM_NUMBER_STRING_SIZE + 64,
  DEFAULT_ESTIMATED_RESPONSE_SIZE = 0x1000,
  MAXIMUM_POSSIBLE_TABLE_OFFSET = 0xFFFFFF,
  MAXIMUM_POSSIBLE_TABLE_LENGTH = 0xFFFFFF
}
 
typedef std::vector< TableRawDataTableRawDataVector
 Vector of table raw data.
 

Public Member Functions

virtual MProtocolCreateClone () const
 Virtual copy constructor, creates the protocol which is a clone of current. More...
 
virtual ~MProtocol ()=0
 Destroy the protocol object. More...
 
void Finalize ()
 Execute this method as first action in the destructor of any child protocol. More...
 
unsigned GetCountApplicationLayerServicesSuccessful () const
 The number of Application Layer services that have been successfully processed. More...
 
void IncrementCountApplicationLayerServicesSuccessful ()
 Increment the number of application layer services successfully processed. More...
 
unsigned GetCountApplicationLayerServicesRetried () const
 The number of Application Layer services that have been retried. More...
 
void IncrementCountApplicationLayerServicesRetried ()
 Increment the number of application layer services retried. More...
 
unsigned GetCountApplicationLayerServicesFailed () const
 The number of Application Layer services that have failed. More...
 
void IncrementCountApplicationLayerServicesFailed ()
 Increment the number of application layer services failed. More...
 
unsigned GetCountLinkLayerPacketsSuccessful () const
 The number of Link Layer packets that have been successfully processed. More...
 
void IncrementCountLinkLayerPacketsSuccessful ()
 Increment the number of data link layer packets successfully processed. More...
 
unsigned GetCountLinkLayerPacketsRetried () const
 The number of Link Layer packets that have been retried. More...
 
void IncrementCountLinkLayerPacketsRetried ()
 Increment the number of data link layer packets retried. More...
 
unsigned GetCountLinkLayerPacketsFailed () const
 Get number of data link layer packets failed. More...
 
void IncrementCountLinkLayerPacketsFailed ()
 Increment the number of data link layer packets failed. More...
 
unsigned GetMaximumRoundTripTime () const
 Gets the maximum measured approximate packet round trip time over the link layer. More...
 
unsigned GetMinimumRoundTripTime () const
 Gets the minimum measured approximate packet round trip time over the link layer. More...
 
unsigned GetAverageRoundTripTime () const
 Gets the average measured approximate packet round trip time over the link layer. More...
 
void ClearPasswordList ()
 Set the password list for the protocol to none, so the SetPassword property is used. More...
 
void AddToPasswordList (const MByteString &password)
 Add a password to the password list. More...
 
int GetPasswordListSuccessfulEntry () const
 Return the entry, which was successfully tried with the meter. More...
 
void ResetCounts ()
 Clear the statistical data for the channel. More...
 
virtual void ApplyChannelParameters ()
 Setup the configuration of the channel in a way compatible with the protocol handshake sequence. More...
 
void Connect ()
 Initializes the channel and establishes the connection with the peer. More...
 
void Disconnect ()
 Severs the connection between the computer and the end device. More...
 
bool IsConnected () const
 Tells whether the protocol is currently connected. More...
 
bool IsInSession () const
 Whether the protocol is in session. More...
 
MProgressActionCreateRootProgressAction ()
 Create root of the progress actions hierarchy. More...
 
MProgressActionGetLocalProgressAction ()
 Read-only access to the currently preset local action in progress monitor. More...
 
bool QNeedToCommit () const
 Whether or not it is time to call QCommit(true) in order to sync with the background thread. More...
 
bool QIsBackgroundCommunicationProgressing () const
 True if the background communication is still progressing. More...
 
bool QIsDone ()
 Combines QNeedToCommit with the following QCommit in case all commands in the queue have been sent. More...
 
void QAbort ()
 Clears the commands in the queue, or cancel the ongoing background communication. More...
 
void QWriteToMonitor (const MStdString &message)
 Add the message to write to the Monitor log file to MProtocol's command queue. More...
 
void QConnect ()
 Places a Connect command in the queue. More...
 
void QDisconnect ()
 Places a Disconnect command in the queue. More...
 
void QIdentifyMeter ()
 Places an IdentifyMeter task in the queue. More...
 
void QStartSession ()
 Adds a start session command to MProtocol's command queue. More...
 
void QEndSession ()
 Adds an end session command to MProtocol's command queue. More...
 
void QEndSessionNoThrow ()
 EndSessionNoThrow request is queued. More...
 
void QTableRead (MCOMNumberConstRef number, unsigned expectedSize, int id)
 Adds a ReadTable command to MProtocol's command queue. More...
 
void QTableWrite (MCOMNumberConstRef number, const MByteString &data)
 Adds a table write command to MProtocol's command queue. More...
 
void QTableReadPartial (MCOMNumberConstRef number, int offset, int size, int id)
 Adds a partial table read command to MProtocol's command queue. More...
 
void QTableWritePartial (MCOMNumberConstRef number, const MByteString &data, int offset)
 Adds a partial table write command to MProtocol's command queue. More...
 
void QFunctionExecute (MCOMNumberConstRef number)
 Place a function without data request in MProtocol command queue. More...
 
void QFunctionExecuteRequest (MCOMNumberConstRef number, const MByteString &request)
 Place a function with request data in MProtocol's command queue. More...
 
void QFunctionExecuteResponse (MCOMNumberConstRef number, int id, unsigned estimatedResponseSize=DEFAULT_ESTIMATED_RESPONSE_SIZE)
 Place a function with response data in MProtocol's command queue. More...
 
void QFunctionExecuteRequestResponse (MCOMNumberConstRef number, const MByteString &request, int id, unsigned estimatedResponseSize=DEFAULT_ESTIMATED_RESPONSE_SIZE)
 Place a function with request and response data in MProtocol's command queue. More...
 
virtual void QCommit (bool asynchronously=false)
 Executes all operations in MProtocol's command queue. More...
 
MByteString QGetTableData (MCOMNumberConstRef number, int id=-1)
 Fetch the table data after the table read has been successfully performed by QCommit. More...
 
MByteString QGetFunctionData (MCOMNumberConstRef number, int id=-1)
 Fetch the function response data after the function has been successfully executed in QCommit. More...
 
MStdString QGetIdentifyMeterData ()
 Fetch the identify meter string after the QIdentifyMeter has been successfully performed in QCommit. More...
 
virtual void WriteToMonitor (const MStdString &message)
 Synchronously write a message to the monitor, if it is connected. More...
 
void WriteCountsToMonitor ()
 Write running values of communication quality counters to monitor. More...
 
void StartSession ()
 Synchronously start the session. More...
 
void EndSession ()
 Synchronously end the session. More...
 
void EndSessionNoThrow ()
 End the session, but do not throw errors. More...
 
Muint8 ReadStartByte (const MByteString &setOfValidStartBytes, unsigned trafficTimeout)
 Read the start byte of the packet in a proper way, taking into consideration timeouts and ignoring garbage. More...
 
MByteString TableRead (MCOMNumberConstRef number, unsigned expectedSize=0)
 Synchronously read the whole table with number given as parameter. More...
 
void TableReadBuffer (MCOMNumberConstRef number, void *buff, unsigned size)
 Same as ReadTable, but instead of returning a byte string, read table into a given buffer. More...
 
template<class T >
void TableReadBuffer (MCOMNumberConstRef number, T &table)
 Same as ReadTable, but instead of returning a byte string, read table into a given template variable. More...
 
MByteString TableReadNoThrow (MCOMNumberConstRef number, MException **exception, unsigned expectedSize=0)
 Synchronously read the whole table with number given as parameter, do not throw an exception, but rather return it. More...
 
void TableWrite (MCOMNumberConstRef number, const MByteString &data)
 Synchronously write the whole table with number given as parameter. More...
 
void TableWriteBuffer (MCOMNumberConstRef number, const void *data, unsigned size)
 Same as TableWrite, but uses buffer, given as data and size parameters. More...
 
template<class T >
void TableWriteBuffer (MCOMNumberConstRef number, const T &table)
 Same as WriteTable, but uses variable of some specific template class or structure. More...
 
MByteString TableReadPartial (MCOMNumberConstRef number, int offset, int size)
 Synchronously read part of the table with number given as parameter. More...
 
void TableReadPartialBuffer (MCOMNumberConstRef number, int offset, void *buff, unsigned size)
 Same as TableReadPartial, but instead of returning a byte string, read table into a given buffer. More...
 
template<class T >
void TableReadPartialBuffer (MCOMNumberConstRef number, T &table, int offset)
 Same as TableReadPartial, but instead of returning a byte string, partially read table into a given template variable. More...
 
void TableWritePartial (MCOMNumberConstRef number, const MByteString &data, int offset)
 Synchronously write part of the table with number given as parameter. More...
 
void TableWritePartialBuffer (MCOMNumberConstRef number, int offset, const void *buff, unsigned size)
 Same as TableWritePartial, but instead of using a byte string, write table using a given buffer. More...
 
template<class T >
void TableWritePartialBuffer (MCOMNumberConstRef number, const T &table, int offset)
 Same as TableWritePartial, but instead of using a byte string, write table using a given template class contents. More...
 
void FunctionExecute (MCOMNumberConstRef number)
 Synchronously execute the function with no parameters, the number of the function is given as parameter. More...
 
void FunctionExecuteRequest (MCOMNumberConstRef number, const MByteString &request)
 Synchronously execute the function with request data, the number of the function is given as parameter. More...
 
MByteString FunctionExecuteResponse (MCOMNumberConstRef number)
 Synchronously execute the function with response data, the number of the function is given as parameter. More...
 
MByteString FunctionExecuteRequestResponse (MCOMNumberConstRef number, const MByteString &request)
 Synchronously execute the function with request and response data, the number of the function is given as parameter. More...
 
virtual unsigned GetNumberOfDataLinkPackets (MCommunicationCommand::CommandType typeOfRequest, unsigned applicationLayerDataSize=0)
 Return the number of data link packets that are required for a given request, provided an optional size of the application data. More...
 
MStdString IdentifyMeterWithContext (bool sessionIsStarted=false, TableRawDataVector *tablesRead=NULL)
 Identify the meter if the protocol is known (note this is not an ANSI Identify protocol command). More...
 
virtual unsigned CalculateChecksumFromBuffer (const char *buff, unsigned size) const
 Protocol dependent one-byte checksum calculation procedure that uses buffer and its size. More...
 
unsigned CalculateChecksum (const MByteString &buffer) const
 Protocol dependent one-byte checksum calculation procedure that uses byte string. More...
 
virtual Muint16 CalculateCRC16FromBuffer (const char *buff, unsigned size) const
 Abstract protocol dependent two-byte CRC calculation procedure, takes buffer chunk with the size. More...
 
unsigned CalculateCRC16 (const MByteString &buffer) const
 Protocol dependent two-byte CRC calculation procedure that accepts the byte string. More...
 
void Sleep (unsigned milliseconds)
 Calls channel's Sleep method if the channel is present. More...
 
bool GetMeterIsLittleEndian () const
 
void SetMeterIsLittleEndian (bool isLittleEndian)
 
MChannelGetChannel () const
 
void SetChannel (MChannel *channel)
 
bool IsChannelOwned () const
 
void SetIsChannelOwned (bool yes)
 
bool GetKeepSessionAlive () const
 
void SetKeepSessionAlive (bool alive)
 
MByteString GetPassword () const
 
void SetPassword (const MByteString &password)
 
const MByteStringVectorGetPasswordList () const
 
void SetPasswordList (const MByteStringVector &passwordList)
 
MProgressMonitorGetProgressMonitor () const
 
void SetProgressMonitor (MProgressMonitor *p)
 
MCommunicationQueue & GetCommandQueue ()
 M_NO_PROGRESS_MONITOR. More...
 
const MCommunicationQueue & GetCommandQueue () const
 M_NO_PROGRESS_MONITOR. More...
 
MStdString IdentifyMeter (bool sessionIsStarted=false)
 
MStdString DoIdentifyMeter0 ()
 
- 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...
 

Static Public Member Functions

static unsigned StaticCalculateChecksumFromBuffer (const char *buff, unsigned size)
 Most popular one-byte checksum calculation procedure, a sum of all bytes. More...
 
static unsigned StaticCalculateChecksum (const MByteString &buffer)
 Compute checksum of the byte string given as parameters. 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...
 

Protected Member Functions

 MProtocol (MChannel *channel, bool channelIsOwned=true)
 Create a new abstract protocol with the channel given. More...
 
virtual void DoStartSession ()
 Synchronously start the session, don't do service count. More...
 
virtual void DoEndSession ()
 Synchronously end the session, don't do service count. More...
 
virtual void DoTableRead (MCOMNumberConstRef number, MByteString &data, unsigned expectedSize=0)
 Synchronously read the whole table with number given as parameter, don't do service count. More...
 
virtual void DoTableWrite (MCOMNumberConstRef number, const MByteString &data)
 Synchronously write the whole table with number given as parameter, don't do service count. More...
 
virtual void DoTableReadPartial (MCOMNumberConstRef number, MByteString &data, int offset, int size)
 Synchronously read part of the table with number given as parameter, don't do service count. More...
 
virtual void DoTableWritePartial (MCOMNumberConstRef number, const MByteString &data, int offset)
 Synchronously write part of the table with number given as parameter, don't do service count. More...
 
virtual void DoFunctionExecute (MCOMNumberConstRef number)
 Synchronously execute the function with no parameters, the number of the function is given as parameter, don't do service count. More...
 
virtual void DoFunctionExecuteRequest (MCOMNumberConstRef number, const MByteString &request)
 Synchronously execute the function with request data, the number of the function is given as parameter, don't do service count. More...
 
virtual void DoFunctionExecuteResponse (MCOMNumberConstRef number, MByteString &response)
 Synchronously execute the function with response data, the number of the function is given as parameter, don't do service count. More...
 
virtual void DoFunctionExecuteRequestResponse (MCOMNumberConstRef number, const MByteString &request, MByteString &response)
 Synchronously execute the function with request and response data, the number of the function is given as parameter, don't do service count. More...
 
virtual MStdString DoIdentifyMeter (bool sessionIsStarted, TableRawDataVector *tablesRead)
 Identify the meter if the protocol is known (note this is not an ANSI Identify protocol command). More...
 
void DoTryPasswordOrPasswordList ()
 Try password or passwords for the protocol according to the PASSWORD and PasswordList settings. More...
 
virtual void DoTryPasswordEntry (const MByteString &entry)
 Try one password, throw if error. More...
 
virtual void DoBuildComplexServiceName (MChars fullServiceName, MConstChars serviceName, MCOMNumberConstRef number, int par1=-1, int par2=-1)
 Build service name with a number and given parameters. More...
 
void DoBuildPossiblyNumericComplexServiceName (MChars fullServiceName, MConstChars serviceName, MCOMNumberConstRef number, bool isHex, int par1=-1, int par2=-1)
 Helper service name builder that can interpret numeric values either as hex or as decimal. 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...
 

Additional Inherited Members

- Static Public Attributes inherited from MObject
static const MClass s_class
 Class of MObject.
 

Detailed Description

Abstraction of a communication protocol.

The protocol is able to execute application level commands directly, or through the command queue interface. The concrete instances of protocol will implement the abstractions defined by this class, plus some extra services and attributes specific to those protocols.

Preferred way of creating a protocol is through MCOMFactory, and typically, the protocol will be created together with MChannel object using MCOMFactory::CreateProtocol()

Member Enumeration Documentation

anonymous enum
Enumerator
MAXIMUM_NUMBER_STRING_SIZE 

Maximum string size allowed for a Number, used in representing a number by the monitoring and error reporting facilities.

MAXIMUM_SERVICE_NAME_STRING_SIZE 

Maximum string size for the service name.

DEFAULT_ESTIMATED_RESPONSE_SIZE 

Size that a response to a function can allocate when its actual size is not known.

MAXIMUM_POSSIBLE_TABLE_OFFSET 

Maximum value for abstract table offset.

This value is protocol dependent, however this value implies a high level check that is not smaller than any protocol.

MAXIMUM_POSSIBLE_TABLE_LENGTH 

Maximum value for abstract table length.

This value is protocol dependent, however this value implies a high level check that is not smaller than any protocol. Also, when the length is bigger than the physical length supported by the protocol, many consecutive application layer requests are done.

Constructor & Destructor Documentation

MProtocol::MProtocol ( MChannel channel,
bool  channelIsOwned = true 
)
protected

Create a new abstract protocol with the channel given.

The service is protected because the class is abstract.

Parameters
channelChannel object of the protocol. It will be a rare case when a protocol can be created without a channel, in which case this parameter can be NULL.
channelIsOwnedWhether the channel has to be owned by the protocol, deleted in protocol destructor or at channel reassignment. By default the protocol owns its channel.
virtual MProtocol::~MProtocol ( )
pure virtual

Destroy the protocol object.

If the channel is owned, IsChannelOwned is true, the channel is also destroyed.

Member Function Documentation

void MProtocol::AddToPasswordList ( const MByteString password)

Add a password to the password list.

Parameters
passwordShall be valid for this protocol, or an error is thrown.
See also
GetPasswordList
virtual void MProtocol::ApplyChannelParameters ( )
virtual

Setup the configuration of the channel in a way compatible with the protocol handshake sequence.

The action depends on the channel and protocol. Implementations ensure that the service behaves gracefully no matter whether the channel is connected or not.

Reimplemented in MProtocolC1222, MProtocolC12, MProtocolC1218, and MProtocolC1221.

unsigned MProtocol::CalculateChecksum ( const MByteString buffer) const

Protocol dependent one-byte checksum calculation procedure that uses byte string.

This implementation uses a protocol-dependent virtual call.

Parameters
bufferBuffer for which to calculate one-byte checksum.
Returns
Value of the checksum, one byte returned within the low part of four bytes.
virtual unsigned MProtocol::CalculateChecksumFromBuffer ( const char *  buff,
unsigned  size 
) const
virtual

Protocol dependent one-byte checksum calculation procedure that uses buffer and its size.

This particular implementation of the checksum calculation fits the majority of the protocols, override if needed.

Parameters
buffThe pointer to the buffer for which to calculate the checksum.
sizeSize of the buffer.
Returns
Value of the checksum, one byte as lower part of four bytes.
See also
StaticCalculateChecksumFromBuffer Static variant of this method that implements the most common sum of bytes algorithm.
CalculateChecksum Works on byte string and returns a checksum value as unsigned integer.

Reimplemented in MProtocolC12.

unsigned MProtocol::CalculateCRC16 ( const MByteString buffer) const
inline

Protocol dependent two-byte CRC calculation procedure that accepts the byte string.

This implementation uses a protocol-dependent virtual call.

Parameters
bufferThe buffer for which to calculate CRC16.
Returns
Value of CRC16, two bytes returned within the low part of four bytes.
virtual Muint16 MProtocol::CalculateCRC16FromBuffer ( const char *  buff,
unsigned  size 
) const
virtual

Abstract protocol dependent two-byte CRC calculation procedure, takes buffer chunk with the size.

Parameters
buffThe pointer to the buffer for which to calculate CRC16.
sizeSize of the buffer.
Returns
Value of CRC16, two bytes.

Reimplemented in MProtocolC12.

void MProtocol::ClearPasswordList ( )

Set the password list for the protocol to none, so the SetPassword property is used.

When the password list is not clear, property SetPassword will not apply.

See also
GetPasswordList
void MProtocol::Connect ( )

Initializes the channel and establishes the connection with the peer.

Prior to calling MChannel::Connect(), this protocol method does extra checks, and calls ApplyChannelParameters(). Unless MChannel is used without MProtocol, it is recommended to use protocol's Connect() method.

See also
MChannel.Connect() - this is where per-channel specifics of Connect are exhaustively described.
Disconnect() - operation that undoes the connection.
virtual MProtocol* MProtocol::CreateClone ( ) const
virtual

Virtual copy constructor, creates the protocol which is a clone of current.

All persistent properties get copied, all other properties have initial values. If channel is owned, channel is duplicated. If channel is not owned, it is made shared.

Reimplemented from MCOMObject.

MProgressAction* MProtocol::CreateRootProgressAction ( )

Create root of the progress actions hierarchy.

Any existing hierarchy is destroyed. If progress monitor is not set, dummy action is returned. A dummy action implements all action's properties and services as no-ops

void MProtocol::Disconnect ( )

Severs the connection between the computer and the end device.

Unless MChannel is used without MProtocol, it is recommended to use protocol's Disconnect method.

Include Disconnect in error handling routines, otherwise, other applications may not be able to connect to the end device.

See also
MChannel.Disconnect() - this is where per-channel specifics of Disconnect are exhaustively described.
Connect() - operation that sets up the connection.
virtual void MProtocol::DoBuildComplexServiceName ( MChars  fullServiceName,
MConstChars  serviceName,
MCOMNumberConstRef  number,
int  par1 = -1,
int  par2 = -1 
)
protectedvirtual

Build service name with a number and given parameters.

If parameters are not present they are not in the name. The particular protocols can fill in their own implementations for full service name.

Precondition
The given chars pointer shall point to a buffer at least MAXIMUM_SERVICE_NAME_STRING_SIZE long. Otherwise the behavior is undefined. Under no circumstance shall this method shall throw an error.
void MProtocol::DoBuildPossiblyNumericComplexServiceName ( MChars  fullServiceName,
MConstChars  serviceName,
MCOMNumberConstRef  number,
bool  isHex,
int  par1 = -1,
int  par2 = -1 
)
protected

Helper service name builder that can interpret numeric values either as hex or as decimal.

If parameters are not present they are not in the name. The particular protocols can fill in their own implementations for full service name.

Precondition
The given chars pointer shall point to a buffer at least MAXIMUM_SERVICE_NAME_STRING_SIZE long. Otherwise the behavior is undefined. Under no circumstance shall this method shall throw an error.
virtual void MProtocol::DoEndSession ( )
protectedvirtual

Synchronously end the session, don't do service count.

This protected service is indeed the one, which needs overwriting by a particular protocol. Depending on the particular protocol this leads to sequence of logoff and terminate commands.

See EndSession, which is public. That one does necessary statistics, monitor handling and error message formatting.

Precondition
The channel is open, the protocol state allows ending the session. Otherwise exceptions can be thrown.

Reimplemented in MProtocolC1218.

virtual void MProtocol::DoFunctionExecute ( MCOMNumberConstRef  number)
protectedvirtual

Synchronously execute the function with no parameters, the number of the function is given as parameter, don't do service count.

This protected service is indeed the one, which needs overwriting by a particular protocol.

See FunctionExecute, which is public. That one does necessary statistics, monitor handling and error message formatting.

Precondition
The channel is open, the session is started. Otherwise exceptions can be thrown.
virtual void MProtocol::DoFunctionExecuteRequest ( MCOMNumberConstRef  number,
const MByteString request 
)
protectedvirtual

Synchronously execute the function with request data, the number of the function is given as parameter, don't do service count.

This protected service is indeed the one, which needs overwriting by a particular protocol.

See FunctionExecuteRequest, which is public. That one does necessary statistics, monitor handling and error message formatting.

Precondition
The channel is open, the session is started. Otherwise exceptions can be thrown.
virtual void MProtocol::DoFunctionExecuteRequestResponse ( MCOMNumberConstRef  number,
const MByteString request,
MByteString response 
)
protectedvirtual

Synchronously execute the function with request and response data, the number of the function is given as parameter, don't do service count.

This protected service is indeed the one, which needs overwriting by a particular protocol.

See FunctionExecuteRequestResponse, which is public. That one does necessary statistics, monitor handling and error message formatting.

Precondition
The channel is open, the session is started. Otherwise exceptions can be thrown.
virtual void MProtocol::DoFunctionExecuteResponse ( MCOMNumberConstRef  number,
MByteString response 
)
protectedvirtual

Synchronously execute the function with response data, the number of the function is given as parameter, don't do service count.

This protected service is indeed the one, which needs overwriting by a particular protocol.

See FunctionExecuteResponse, which is public. That one does necessary statistics, monitor handling and error message formatting.

Precondition
The channel is open, the session is started. Otherwise exceptions can be thrown.
virtual MStdString MProtocol::DoIdentifyMeter ( bool  sessionIsStarted,
TableRawDataVector tablesRead 
)
protectedvirtual

Identify the meter if the protocol is known (note this is not an ANSI Identify protocol command).

This protected service is indeed the one, which needs overwriting by a particular protocol.

If the first parameter is true, the service assumes the session is open, and it will not start the session, or close it. The second parameter, if it is not NULL, is filled with the data from tables, which DoIdentifyMeter had to read from the meter during its attempts to fetch the necessary information from the meter. This table vector can be used in order to minimize the communication with the meter, if this task has its place.

See IdentifyMeter, which is public. That one does necessary statistics, monitor handling and error message formatting.

Precondition
The channel is connected. Otherwise a channel-related exception is thrown that tells about the failure. The meter is indeed the one which is able to talk the specific protocol. Otherwise the protocol-specific exception is thrown that signals the failure of communicating through the channel. If the session is started already, the first parameter has to be true, or the behavior is undefined.
MStdString MProtocol::DoIdentifyMeter0 ( )

Identify the meter version and other information if the protocol is known.

Note that this is not an ANSI Identify protocol command. Typically, IdentifyMeter would be used when creating a meter of a known type, but an unknown version.

The IdentifyMeter service wraps the start and end session around the identification task. To call IdentifyMeter, one has to connect to the meter, but the session should not be started. This differs from QIdentifyMeter which does NOT wrap start and end session around the identification task.

Typically, IdentifyMeter returns only one identify string that identifies the meter. However, identify strings can be created for the option boards installed on a meter. In this case, the returned string can contain multiple identify strings, where the the meter's identify string is listed first and identify strings are separated by a semi- colon. Use GetIdentifyStrings to separate multiple identify strings.

The identify string is formatted as a J command and may not be suitable for showing to the user as it can contain non-printable characters. Instead, it is formatted for easy processing by a script or a program. A typical identify string returned for an A3 meter with LANOB option board follows (wrapped for clarity):

Example of A3 Identify string followed by LANOB's identify string, spaces and new lines used for clarity:

J00[MANUFACTURER:EE ]
[ED_MODEL:A3R ]
[HW_VERSION_REVISION:1.2]
[SW_VERSION_REVISION:2.3]
[MFG_SERIAL_NUMBER: ]
[NUMBER_OF_OPTION_BOARDS:2]
[OB1_Type:0M]
[OB1_SSPEC:000237]
[OB1_REVISION:1.0]
[OB1_POSITION:1]
[OB2_Type:0K]
[OB2_SSPEC:000239]
[OB2_REVISION:1.3]
[OB2_POSITION:2];
J00[MANUFACTURER:EE ]
[ED_MODEL:REXILC ]
[HW_VERSION_REVISION:1.0]
[SW_VERSION_REVISION:1.3]
[MFG_SERIAL_NUMBER:LANOB ]
virtual void MProtocol::DoStartSession ( )
protectedvirtual

Synchronously start the session, don't do service count.

This protected service is indeed the one, which needs overwriting by a particular protocol. Depending on the particular protocol this leads to sequence of handshake and logon commands.

See StartSession, which is public. That one does necessary statistics, monitor handling and error message formatting.

Precondition
The channel is open, the protocol state allows starting the session. Otherwise exceptions can be thrown.

Reimplemented in MProtocolC1218, and MProtocolC1221.

virtual void MProtocol::DoTableRead ( MCOMNumberConstRef  number,
MByteString data,
unsigned  expectedSize = 0 
)
protectedvirtual

Synchronously read the whole table with number given as parameter, don't do service count.

This protected service is indeed the one, which needs overwriting by a particular protocol.

See TableRead, which is public. That one does necessary statistics, monitor handling and error message formatting.

The third argument is introduced to handle a special case where the table size is bigger than what the protocol allows, such as configuring an ANSI meter to have more load profile data than the 64K that can be transmitted with ANSI C12.18. In this case the table is read with multiple partial reads, where each partial read is sized to fit within the protocol constraints.

Precondition
The channel is open, the session is started. Otherwise exceptions can be thrown.
virtual void MProtocol::DoTableReadPartial ( MCOMNumberConstRef  number,
MByteString data,
int  offset,
int  size 
)
protectedvirtual

Synchronously read part of the table with number given as parameter, don't do service count.

This protected service is indeed the one, which needs overwriting by a particular protocol.

See TableReadPartial, which is public. That one does necessary statistics, monitor handling and error message formatting.

Precondition
The channel is open, the session is started. Otherwise exceptions can be thrown.
virtual void MProtocol::DoTableWrite ( MCOMNumberConstRef  number,
const MByteString data 
)
protectedvirtual

Synchronously write the whole table with number given as parameter, don't do service count.

This protected service is indeed the one, which needs overwriting by a particular protocol.

See TableWrite, which is public. That one does necessary statistics, monitor handling and error message formatting.

Precondition
The channel is open, the session is started. Otherwise exceptions can be thrown.
virtual void MProtocol::DoTableWritePartial ( MCOMNumberConstRef  number,
const MByteString data,
int  offset 
)
protectedvirtual

Synchronously write part of the table with number given as parameter, don't do service count.

This protected service is indeed the one, which needs overwriting by a particular protocol.

See TableWritePartial, which is public. That one does necessary statistics, monitor handling and error message formatting.

Precondition
The channel is open, the session is started. Otherwise exceptions can be thrown.
virtual void MProtocol::DoTryPasswordEntry ( const MByteString entry)
protectedvirtual

Try one password, throw if error.

This service has to be overloaded by every final protocol to attempt applying a given password.

Precondition
The security should be cleared with the meter using the password entry given, otherwise an exception should be thrown by the concrete implementation.
void MProtocol::DoTryPasswordOrPasswordList ( )
protected

Try password or passwords for the protocol according to the PASSWORD and PasswordList settings.

In case the password list is specified, only the password list is tried, if there is no password list, PASSWORD property is used.

Precondition
The security should be cleared with the meter using one of the passwords in the password list, or the password property. Otherwise a security error is thrown.
void MProtocol::EndSession ( )

Synchronously end the session.

Depending on the particular protocol this leads to sequence of logoff and terminate commands.

See QEndSession for the queue version of this service. Q services would work faster for the queue based protocols, but slower for synchronous protocols like C12. Also, they are obviously less convenient for synchronous operations.

Precondition
The channel is open, the protocol state allows ending the session. Otherwise exceptions can be thrown.
See also
EndSessionNoThrow for the variant that does not throw errors.
void MProtocol::EndSessionNoThrow ( )

End the session, but do not throw errors.

See also
EndSession for the variant that throws errors.
void MProtocol::Finalize ( )

Execute this method as first action in the destructor of any child protocol.

It is okay to call this method many times from a hierarchy of destructors, however nothing else shall be called after.

void MProtocol::FunctionExecute ( MCOMNumberConstRef  number)

Synchronously execute the function with no parameters, the number of the function is given as parameter.

See QFunctionExecute for the queue version of this service. Q services would work faster for the queue based protocols, but slower for synchronous protocols like C12. Also, they are obviously less convenient for synchronous operations.

Precondition
The channel is open, the session is started. Otherwise exceptions can be thrown.
Parameters
numberFunction number
void MProtocol::FunctionExecuteRequest ( MCOMNumberConstRef  number,
const MByteString request 
)

Synchronously execute the function with request data, the number of the function is given as parameter.

See QFunctionExecuteRequest for the queue version of this service. Q services would work faster for the queue based protocols, but slower for synchronous protocols like C12. Also, they are obviously less convenient for synchronous operations.

Precondition
The channel is open, the session is started. Otherwise exceptions can be thrown.
Parameters
numberFunction number.
requestRequest data.
MByteString MProtocol::FunctionExecuteRequestResponse ( MCOMNumberConstRef  number,
const MByteString request 
)

Synchronously execute the function with request and response data, the number of the function is given as parameter.

See QFunctionExecuteRequestResponse for the queue version of this service. Q services would work faster for the queue based protocols, but slower for synchronous protocols like C12. Also, they are obviously less convenient for synchronous operations.

Precondition
The channel is open, the session is started. Otherwise exceptions can be thrown.
Parameters
numberFunction number.
requestRequest data.
Returns
Response data.
MByteString MProtocol::FunctionExecuteResponse ( MCOMNumberConstRef  number)

Synchronously execute the function with response data, the number of the function is given as parameter.

See QFunctionExecuteResponse for the queue version of this service. Q services would work faster for the queue based protocols, but slower for synchronous protocols like C12. Also, they are obviously less convenient for synchronous operations.

Precondition
The channel is open, the session is started. Otherwise exceptions can be thrown.
Parameters
numberFunction number.
Returns
Response data.
unsigned MProtocol::GetAverageRoundTripTime ( ) const
inline

Gets the average measured approximate packet round trip time over the link layer.

A 'round trip' is defined as the amount of time elapsed from the last byte sent to the first byte received back. Each trip is monitored, and the following properties updated accordingly: GetMinimumRoundTripTime, GetMaximumRoundTripTime, and GetAverageRoundTripTime.

The round trip times are not updated when there is a timeout, even if there were garbage characters on the line. The round trip times are nullified when the connection is created or when ResetCounts is issued.

Since
MeteringSDK Version 4.0.43.
Possible values:
  • 0 .. UINT32
MChannel* MProtocol::GetChannel ( ) const
inline

Channel associated with this protocol.

When the channel is owned, and a new one is reassigned to the protocol, the previous channel will be deleted.

MCommunicationQueue& MProtocol::GetCommandQueue ( )
inline

M_NO_PROGRESS_MONITOR.

Get the command queue of the protocol.

If the items were added to the queue by Q services, and no QCommit is performed yet, the queue is not empty.

const MCommunicationQueue& MProtocol::GetCommandQueue ( ) const
inline

M_NO_PROGRESS_MONITOR.

Get the command queue of the protocol.

If the items were added to the queue by Q services, and no QCommit is performed yet, the queue is not empty.

unsigned MProtocol::GetCountApplicationLayerServicesFailed ( ) const
inline

The number of Application Layer services that have failed.

The count is nullified when the connection is created, or when ResetCounts is issued.

Since
MeteringSDK Version 2.2.17.
Possible values:
  • 0 .. UINT32
unsigned MProtocol::GetCountApplicationLayerServicesRetried ( ) const
inline

The number of Application Layer services that have been retried.

The count is nullified when the connection is created, or when ResetCounts is issued. For some protocols the application layer retries never take place, in which case this property will remain at zero.

Since
MeteringSDK Version 2.2.17.
Possible values:
  • 0 .. UINT32
unsigned MProtocol::GetCountApplicationLayerServicesSuccessful ( ) const
inline

The number of Application Layer services that have been successfully processed.

The count is nullified when the protocol is created, and when ResetCounts is called.

Since
MeteringSDK Version 2.2.17.
Possible values:
  • 0 .. UINT32
unsigned MProtocol::GetCountLinkLayerPacketsFailed ( ) const
inline

Get number of data link layer packets failed.

The count is nullified when the connection is created, or when ResetCounts is issued. Some protocols, such as MProtocolC1222, do not have a link layer, therefore, they will not increment this counter.

Since
MeteringSDK Version 2.2.17.
Possible values:
  • 0 .. UINT32
unsigned MProtocol::GetCountLinkLayerPacketsRetried ( ) const
inline

The number of Link Layer packets that have been retried.

The count is nullified when the connection is created, or when ResetCounts is issued. Some protocols, such as MProtocolC1222, do not have a link layer, therefore, they will not increment this counter.

Since
MeteringSDK Version 2.2.17.
Possible values:
  • 0 .. UINT32
unsigned MProtocol::GetCountLinkLayerPacketsSuccessful ( ) const
inline

The number of Link Layer packets that have been successfully processed.

The count is nullified when the connection is created, or when ResetCounts is issued. Some protocols, such as MProtocolC1222, do not have a link layer, therefore, they will not increment this counter.

Since
MeteringSDK Version 2.2.17.
Possible values:
  • 0 .. UINT32
bool MProtocol::GetKeepSessionAlive ( ) const

Whether the protocol should keep session alive in case of long inactivity.

When KeepSessionAlive is true, the session is kept from timing out. The feature can also be used to prevent an idling connection from being closed. What is done to keep the session alive is protocol dependent, but usually involves repeatedly sending some type of communication request to the meter. For some sessionless protocols this property has no effect.

The session is being kept alive by a background thread that is watching for the current value of property IsInSession. When IsInSession is true, the background communication is performed. Errors raised on the background can be silenced if IsConnected value was false. Otherwise, the session keeping errors will be thrown to the foreground thread at the next communication event, such as QCommit. Another place that checks and throws an error collected by the background thread is the assignment to KeepSessionAlive property itself. Therefore, the following will check for an error, and throw it if it was present:

protocol.SetKeepSessionAlive(protocol.GetKeepSessionAlive()); // C++

When KeepSessionAlive is false, the session will time out or the connection will be closed according to the protocol rules.

Since
MeteringSDK Version 3.2.6.
Default value:
False
Possible values:
  • True [1] : The session will not time out.
  • False [0] : The session will time out according to the protocol rules.
See also
IsInSession - whether the session keeping is active.
MProgressAction* MProtocol::GetLocalProgressAction ( )

Read-only access to the currently preset local action in progress monitor.

If progress monitor is not set, or if it does not have local action, dummy action is returned.

unsigned MProtocol::GetMaximumRoundTripTime ( ) const
inline

Gets the maximum measured approximate packet round trip time over the link layer.

A 'round trip' is defined as the amount of time elapsed from the last byte sent to the first byte received back. Each trip is monitored, and the following properties updated accordingly: GetMinimumRoundTripTime, GetMaximumRoundTripTime, and GetAverageRoundTripTime.

The round trip times are not updated when there is a timeout, even if there were garbage characters on the line. The round trip times are nullified when the connection is created or when ResetCounts is issued.

Since
MeteringSDK Version 4.0.43.
Possible values:
  • 0 .. UINT32
bool MProtocol::GetMeterIsLittleEndian ( ) const
inline

Primary data order of the device, whether it is little endian.

This information is used by some protocol implementations, for example, for ANSI procedures/functions implementation. Such protocols have application-level fields that depend on the protocol byte order.

It is only necessary to set this property when communicating to a device of different endianity as the protocol default. When communicating through the upper library levels this property can be set automatically.

Default value:
Depends on the protocol type. Most of the protocols are little endian, while some legacy ones are big endian.
Since
MeteringSDK Version 2.1.27.
Possible values:
  • True [1] : Little Endian
  • False [0] : Big Endian
unsigned MProtocol::GetMinimumRoundTripTime ( ) const
inline

Gets the minimum measured approximate packet round trip time over the link layer.

A 'round trip' is defined as the amount of time elapsed from the last byte sent to the first byte received back. Each trip is monitored, and the following properties updated accordingly: GetMinimumRoundTripTime, GetMaximumRoundTripTime, and GetAverageRoundTripTime.

The round trip times are not updated when there is a timeout, even if there were garbage characters on the line. The round trip times are nullified when the connection is created or when ResetCounts is issued.

Since
MeteringSDK Version 4.0.43.
Possible values:
  • 0 .. UINT32
virtual unsigned MProtocol::GetNumberOfDataLinkPackets ( MCommunicationCommand::CommandType  typeOfRequest,
unsigned  applicationLayerDataSize = 0 
)
virtual

Return the number of data link packets that are required for a given request, provided an optional size of the application data.

Like for table read, this will be the expected size of the table to read, and for the table write this is the size of the table to be written. For function execution this is the sum of request and response sizes.

Parameters
typeOfRequestThe type of the request, the value within the enumeration range. There is a debug check for the value.
applicationLayerDataSizeTable size or the sum of function request and response size, whatever comprises the application layer of the given command.
Returns
Estimated number of link layer packets to process the request.
MByteString MProtocol::GetPassword ( ) const

Application level password of the protocol.

The Password property is the binary value that is used to gain access to the device. No interpretation of C escape character sequences is performed on this string.

Many protocols will typically use password in the StartSession sequence, while some, such as sessionless mode of MProtocolC1222, will send password at every request.

The password can have less characters than the maximum number of characters allowed. In this case, during the communication, the password will be padded with a fill character (different for each protocol). For example, if an 8 character password is set to "1111", then the password "1111 " is transmitted during communications, while Password property will continue to report "1111". The padded characters are significant, and the password stored in the meter must exactly match the password used during communications (including the fill characters) or an error is generated.

Default value:
Possible values:
  • "12345678901234567890" : Passwords for the MProtocolC1218, MProtocolC1221, and MProtocolC1222 protocols (A3, A1800 meters) can have a maximum of 20 characters. If the specified password is less than 20 characters, then the remaining characters are filled with blank spaces during communication.
const MByteStringVector& MProtocol::GetPasswordList ( ) const
inline

Password list for the protocol.

The password lists, when not empty, overwrite the SetPassword property. In such case, passwords from the password list are applied in the ascending order until a successful entry is found. If none exists, the last error received during list processing is thrown.

See also
GetPassword
ClearPasswordList - clear the password list
AddToPasswordList - add entry to password list
GetPasswordListSuccessfulEntry - shall be called after successful start session to know which password list worked.
int MProtocol::GetPasswordListSuccessfulEntry ( ) const

Return the entry, which was successfully tried with the meter.

If there was no attempt to try the password list, or when none of the entries were successful, this property will be equal to -1.

See also
GetPasswordList
MProgressMonitor* MProtocol::GetProgressMonitor ( ) const
inline

Access to the progress monitor, if exists

MStdString MProtocol::IdentifyMeter ( bool  sessionIsStarted = false)

Identify the meter version and other information if the protocol is known.

Note that this is not an ANSI Identify protocol command. Typically, IdentifyMeter would be used when creating a meter of a known type, but an unknown version.

The IdentifyMeter service wraps the start and end session around the identification task. To call IdentifyMeter, one has to connect to the meter, but the session should not be started. This differs from QIdentifyMeter which does NOT wrap start and end session around the identification task.

Typically, IdentifyMeter returns only one identify string that identifies the meter. However, identify strings can be created for the option boards installed on a meter. In this case, the returned string can contain multiple identify strings, where the the meter's identify string is listed first and identify strings are separated by a semi- colon. Use GetIdentifyStrings to separate multiple identify strings.

The identify string is formatted as a J command and may not be suitable for showing to the user as it can contain non-printable characters. Instead, it is formatted for easy processing by a script or a program. A typical identify string returned for an A3 meter with LANOB option board follows (wrapped for clarity):

Example of A3 Identify string followed by LANOB's identify string, spaces and new lines used for clarity:

J00[MANUFACTURER:EE ]
[ED_MODEL:A3R ]
[HW_VERSION_REVISION:1.2]
[SW_VERSION_REVISION:2.3]
[MFG_SERIAL_NUMBER: ]
[NUMBER_OF_OPTION_BOARDS:2]
[OB1_Type:0M]
[OB1_SSPEC:000237]
[OB1_REVISION:1.0]
[OB1_POSITION:1]
[OB2_Type:0K]
[OB2_SSPEC:000239]
[OB2_REVISION:1.3]
[OB2_POSITION:2];
J00[MANUFACTURER:EE ]
[ED_MODEL:REXILC ]
[HW_VERSION_REVISION:1.0]
[SW_VERSION_REVISION:1.3]
[MFG_SERIAL_NUMBER:LANOB ]
MStdString MProtocol::IdentifyMeterWithContext ( bool  sessionIsStarted = false,
TableRawDataVector tablesRead = NULL 
)

Identify the meter if the protocol is known (note this is not an ANSI Identify protocol command).

If the first parameter is true, the service assumes the session is open, and it will not start the session, or close it. The second parameter, if it is not NULL, is filled with the data from tables, which IdentifyMeter had to read from the meter during its attempts to fetch the necessary information from the meter. This table vector can be used in order to minimize the communication with the meter, if this task has its place.

Precondition
The channel is connected. Otherwise a channel-related exception is thrown that tells about failure. The meter is indeed the one, which is able to talk the specific protocol. Otherwise the protocol-specific exception is thrown that signals the failure of communicating through the channel. If the session is started already, the first parameter has to be true, or the behavior is undefined.
Parameters
sessionIsStartedTrue if the method should not start and end the session as part of identification.
tablesReadPointer of data vector for tables that were read as part of the call.
Returns
Identify string
void MProtocol::IncrementCountApplicationLayerServicesFailed ( )
inline

Increment the number of application layer services failed.

This can be used by the outside application, which is willing to treat its actions as an application layer failure.

void MProtocol::IncrementCountApplicationLayerServicesRetried ( )
inline

Increment the number of application layer services retried.

This can be used by the outside application, which is willing to treat its actions as an application layer retry.

void MProtocol::IncrementCountApplicationLayerServicesSuccessful ( )
inline

Increment the number of application layer services successfully processed.

This can be used by the outside application, which is willing to treat its actions as an application layer service.

void MProtocol::IncrementCountLinkLayerPacketsFailed ( )
inline

Increment the number of data link layer packets failed.

This can be used by the outside application, which is willing to treat its actions as a link layer failure.

void MProtocol::IncrementCountLinkLayerPacketsRetried ( )
inline

Increment the number of data link layer packets retried.

This can be used by the outside application, which is willing to treat its actions as a link layer retry.

void MProtocol::IncrementCountLinkLayerPacketsSuccessful ( )
inline

Increment the number of data link layer packets successfully processed.

This can be used by the outside application, which is willing to treat its actions as a link layer success.

bool MProtocol::IsChannelOwned ( ) const
inline

Whether the channel is owned by this protocol.

When the channel is owned, it will be deleted by protocol destructor, or at the event of channel reassignment to the protocol.

bool MProtocol::IsConnected ( ) const

Tells whether the protocol is currently connected.

This method is a straightforward facade to MChannel::IsConnected. It reflects the assumption the communication component has about the channel state, it does not guarantee that the next action with the channel will be successful. Issue the Connect() service to establish the connection and the Disconnect() service to terminate the connection.

Default value:
False
Possible values:
  • True : The connection has been established.
  • False : The connection has not been established.
See also
IsInSession
MChannel.IsConnected
Connect
Disconnect
bool MProtocol::IsInSession ( ) const

Whether the protocol is in session.

This is a generic method, and the meaning of 'session' depends on protocol type and mode. The notion of a session exists in most protocols, and for these protocols the property indicates whether MeteringSDK considers the device to be in session mode. The current implementation, however, does not respect session timeout, therefore, when the client protocol is in session, the device might have timed out already.

Some protocols such as MProtocolC1222 do not have session state, however for them this property will behave as if the notion of a session is present, such as:

  • Initially, IsInSession is false
  • StartSession, if successful, sets IsInSession to true even though it might not result in any communication
  • Any successful table or function operation sets IsInSession to true
  • EndSession, even a dummy one, sets IsInSession to false
  • Disconnect sets IsInSession to false

When both this property and GetKeepSessionAlive are true, and session keeping is implemented for this protocol type or mode, the value of IsInSession will indicate whether the session keeping is being done. Session keeping sequence, however, can be interrupted by an error.

Possible values:
  • True : The protocol is in session state.
  • False : The protocol is not in session.
See also
IsConnected
void MProtocol::QAbort ( )

Clears the commands in the queue, or cancel the ongoing background communication.

If the queue is empty when the QAbort is issued, the queue remains empty and no error is generated. If the queue has commands, but they are not being processed (QCommit has not been issued), then the queue is cleared and no error is generated.

If the queue is being executed asynchronously (QCommit(true) then QAbort will tell MCOM to stop executing the commands in the queue and clear all remaining commands from the queue. If the abort is requested while a table is being written, the write request is completed before the abort request will be processed. No attempt is made to end (or clean up) the session. Note that QAbort returns immediately, it does not wait for the communications to stop. How long it takes for MCOM to respond to the QAbort request depends on the protocol and the tasks running on the PC. Typically, one could expect the time to be less than 500 mSec. To determine when communications have been terminated, QIsDone must be checked. For communications that have been stopped by a QAbort, QIsDone will raise an error. If QIsDone is not checked and allowed to raise the error, then the next Q Command (such as QStartSession), will raise an error. Most likely the error will indicate "Invalid operation during active background communication". This is because the asynchronous communication background thread can not terminate while there is an error to hand back to the foreground thread that started the asynchronous communications. Asynchronous communications should always check QIsDone until it is True or raises an error.

Note that QAbort and QIsDone are issued immediately, they do NOT require a QCommit.

virtual void MProtocol::QCommit ( bool  asynchronously = false)
virtual

Executes all operations in MProtocol's command queue.

If no operations were queued then QCommit does nothing.

Protocol supports synchronous and asynchronous communications. When synchronous communications are initiated, QCommit will not return until all commands in the queue have been executed or an error occurs. This prevents the calling application from performing any other work on that thread. When asynchronous communications are initiated, the QCommit will return immediately while the commands in the queue are executed in the background. The calling application is free to perform other work while waiting for the communications to complete. The application will have to check QIsDone to determine when asynchronous communications have completed. The application can also call QAbort to stop and clear the commands from the queue.

Should an error occur during synchronous communications, it will be reported immediately on the QCommit. Should an error occur during asynchronous communications, the error is raised on QIsDone. In either case, no attempt is made to execute the remaining commands in the queue.

The command queue will always be cleared after a QCommit, regardless of success or failure of the operations that were queued.

Parameters
asynchronouslyWhether to perform the communication on the background, asynchronously.

The following sequences are completely equivalent:

protocol.Connect() // synchronously connect
protocol.StartSession() // synchronously start the session
table = protocol.TableRead(0) // read table zero
protocol.EndSession() // here end the session
protocol.Disconnect() // synchronously disconnect

or:

protocol.QConnect(); // declare we will be connecting
protocol.QStartSession(); // declare we will be starting session
protocol.QTableRead(0, 0, 0) // queue table read, have no expectation about its size
protocol.QEndSession() // after that we will be ending the session
protocol.QDisconnect(); // declare we will be disconnecting
protocol.QCommit() // commit the will, the sequence is executed
table = protocol.QGetTableData(0, 0); // get the result data or table 0, id 0

Case of background communication in a separate thread:

protocol.QConnect(); // declare we will be connecting
protocol.QStartSession(); // declare we will be starting session
protocol.QTableRead(0, 0, 0) // queue table read, have no expectation about its size
protocol.QEndSession() // after that we will be ending the session
protocol.QDisconnect(); // declare we will be disconnecting
protocol.QCommit(true); // commit on the background
while ( !protocol->QIsDone() )
{
.... do anything
}
table = protocol.QGetTableData(0, 0); // get the result data or table 0, id 0
void MProtocol::QConnect ( )

Places a Connect command in the queue.

The QConnect can be paired with QDisconnect or Disconnect. Protocol supports synchronous and asynchronous communications.

When synchronous communications are initiated, QCommit will not return until all commands in the queue have been executed or an error occurs. This prevents the calling application from performing any other work on that thread. When asynchronous communications are initiated, the QCommit returns immediately while the commands in the queue are executed in the background. The calling application is free to perform other work while waiting for the communications to complete. The application will have to check QIsDone to determine when asynchronous communications have completed. The application can also call QAbort to stop and clear the commands from the queue. QAbort can be useful for Connect sequences that take a long time (such as the 30-60 seconds it takes to connect to a modem).

void MProtocol::QDisconnect ( )

Places a Disconnect command in the queue.

The QDisconnect can be paired with QConnect or Connect. Note that an commands are cleared from the queue when an error occurs. If the QDisconnect is placed in the queue and an error occurs before it can be issued, it will be cleared from the queue along with the remaining unexecuted commands. Error handling routines must issue a Disconnect (or QDisconnect/QCommit), in order to disconnect from the channel. For this reason, it is recommended that users use Disconnect instead of QDisconnect for most cases.

Protocol supports synchronous and asynchronous communications. When synchronous communications are initiated, QCommit will not return until all commands in the queue have been executed or an error occurs. This prevents the calling application from performing any other work on that thread. When asynchronous communications are initiated, the QCommit returns immediately while the commands in the queue are executed in the background. The calling application is free to perform other work while waiting for the communications to complete. The application will have to check QIsDone to determine when asynchronous communications have completed. The application can also call QAbort to stop and clear the commands from the queue.

void MProtocol::QEndSession ( )

Adds an end session command to MProtocol's command queue.

When QEndSession is executed by a QCommit, the active session with the meter will be terminated. Typically, this is done using the protocol's logoff service. If the protocol does not support a start/end session, such as sessionless MProtocolC1222, then QEndSession does nothing and does not generate an error. This is so programs that support multiple meters and protocols can be written with the QStartSession and QEndSession.

For protocols that support start/end session, once an QEndSession command is executed, no other commands can be sent to the meter until after the next QStartSession. The communications link to the meter will not be severed by QEndSession. For instance, a modem channel will remain on-line after this operation. To sever the communications link to the meter requires using the Disconnect() method. The Disconnect method should only be used when no more communications to the meter are required.

protocol.QStartSession()
protocol.QTableWrite(tableNum, data)
protocol.QEndSession()
protocol.QCommit()
See also
QEndSessionNoThrow - silences any errors if they appear
void MProtocol::QEndSessionNoThrow ( )

EndSessionNoThrow request is queued.

This service is part of queue communication interface. In all ways it is similar to QEndSession except that it silently swallows any error, should it appear. Therefore, this variant is very convenient in error handlers that need to ensure that the session has ended.

See also
QEndSession - throws errors
void MProtocol::QFunctionExecute ( MCOMNumberConstRef  number)

Place a function without data request in MProtocol command queue.

This service is part of queue communication interface.

Parameters
numberIdentifies the function to be placed into the queue. Typically, this is an integer, but some protocols do allow it to be a string.
void MProtocol::QFunctionExecuteRequest ( MCOMNumberConstRef  number,
const MByteString request 
)

Place a function with request data in MProtocol's command queue.

This service is part of queue communication interface.

Parameters
numberIdentifies the function to be placed into the queue. Typically, this is an integer, but some protocols do allow it to be a string.
requestThe function data to send to the meter. It must be in the form of a byte array and must have the number of bytes that corresponds to the specified function.
void MProtocol::QFunctionExecuteRequestResponse ( MCOMNumberConstRef  number,
const MByteString request,
int  id,
unsigned  estimatedResponseSize = DEFAULT_ESTIMATED_RESPONSE_SIZE 
)

Place a function with request and response data in MProtocol's command queue.

This service is part of queue communication interface. The response data will be available after the QCommit method is issued. Use the QGetFunctionData method to retrieve the bytes.

Parameters
numberIdentifies the function to be placed into the queue. Typically, this is an integer, but some protocols do allow it to be a string.
requestThe function data to send to the meter. It must be in the form of a byte array and must have the number of bytes that corresponds to the specified function.
idOperation identifier to associate with the data returned from the device. When processing tables or functions with different numbers, this can be any value, as tables and functions can be identified by their numbers, however when using the same table or function number in the same queue, this ID should be unique, so the identification is possible.
estimatedResponseSizeoptional parameter. If provided, this is the size of the response. If not provided, this is estimated to be large enough to fit any possible value.
void MProtocol::QFunctionExecuteResponse ( MCOMNumberConstRef  number,
int  id,
unsigned  estimatedResponseSize = DEFAULT_ESTIMATED_RESPONSE_SIZE 
)

Place a function with response data in MProtocol's command queue.

This service is part of queue communication interface. The response data will be available after the QCommit method is issued. Use the QGetFunctionData to retrieve the bytes.

Parameters
numberIdentifies the function to be placed into the queue. Typically, this is an integer, but some protocols do allow it to be a string.
estimatedResponseSizeoptional parameter. If provided, this is the size of the response. If not provided, this is estimated to be large enough to fit any possible value.
idOperation identifier to associate with the data returned from the device. When processing tables or functions with different numbers, this can be any value, as tables and functions can be identified by their numbers, however when using the same table or function number in the same queue, this ID should be unique, so the identification is possible.
MByteString MProtocol::QGetFunctionData ( MCOMNumberConstRef  number,
int  id = -1 
)

Fetch the function response data after the function has been successfully executed in QCommit.

The data remains available after commit has performed, but until the next queue starts to be built.

Parameters
numberNumber of the function that was executed, whatever is given to QFunctionExecuteResponse or QFunctionExecuteRequestResponse
idIf the same table was read several times in the same session, use this id to distinguish between individual calls of QTableRead or QTableReadPartial.
Returns
Function data bytes.
MStdString MProtocol::QGetIdentifyMeterData ( )

Fetch the identify meter string after the QIdentifyMeter has been successfully performed in QCommit.

Typically, QGetIdentifyMeterData returns only one identify string that identifies the meter. However, identify strings can be created for the option boards installed on a meter. In this case, the returned string can contain multiple identify strings, where the the meter's identify string is listed first and identify strings are separated by a semi- colon. Use GetIdentifyStrings to separate multiple identify strings.

The identify string is formatted as a J command and may not be suitable for showing to the user as it can contain non-printable characters. Instead, it is formatted for easy processing by a script or a program. A typical identify string returned for an A3 meter with LANOB option board follows (wrapped for clarity):

J00[MANUFACTURER:EE ] // A3's identify string //
[ED_MODEL:A3R ]
[HW_VERSION_REVISION:1.2]
[SW_VERSION_REVISION:2.3]
[MFG_SERIAL_NUMBER: ]
[NUMBER_OF_OPTION_BOARDS:2]
[OB1_Type:0M]
[OB1_SSPEC:000237]
[OB1_REVISION:1.0]
[OB1_POSITION:1]
[OB2_Type:0K]
[OB2_SSPEC:000239]
[OB2_REVISION:1.3]
[OB2_POSITION:2];
J00[MANUFACTURER:EE ] // LANOB's identify string //
[ED_MODEL:REXILC ]
[HW_VERSION_REVISION:1.0]
[SW_VERSION_REVISION:1.3]
[MFG_SERIAL_NUMBER:LANOB ]
Returns
Result identify string
MByteString MProtocol::QGetTableData ( MCOMNumberConstRef  number,
int  id = -1 
)

Fetch the table data after the table read has been successfully performed by QCommit.

The data remains available after commit has performed, but until the next queue starts to be built.

Parameters
numberNumber of the table that was read, whatever is given to QTableRead or QTableReadPartial
idIf the same table was read several times in the same session, use this id to distinguish between individual calls of QTableRead or QTableReadPartial.
Returns
Table data bytes
void MProtocol::QIdentifyMeter ( )

Places an IdentifyMeter task in the queue.

The commands stored in the command queue will be sent to the meter when QCommit is issued. The identify meter task identifies the meter version and other information if the protocol is known (note that this is not an ANSI Identify protocol command). Typically, QIdentifyMeter is used when creating a meter of a known type, but an unknown version.

The QIdentifyMeter service does NOT wrap the start and end session around the identification task. To use QIdentifyMeter, one has to connect to the meter and start the session. This differs from IdentifyMeter which wraps start and end session around the identification task.

The identification information is retrieved with QGetIdentifyMeterData after QIdentifyMeter has been successfully QCommit-ted (all requests in queue sent to the meter).

bool MProtocol::QIsBackgroundCommunicationProgressing ( ) const
inline

True if the background communication is still progressing.

This is different from QIsDone in the sense that it will be true only if there is a background activity.

// ... QNeedToCommit() == false, QIsBackgroundCommunicationProgressing() == false
protocol.QConnect
protocol.QStartSession
protocol.QEndSession
protocol.QDisconnect
// ... QNeedToCommit() == false, QIsBackgroundCommunicationProgressing() == false
protocol.QCommit(true);
// ... QNeedToCommit() == false, QIsBackgroundCommunicationProgressing() == true
// ...
while ( !protocol.QNeedToCommit() )
// ... QNeedToCommit() == true, QIsBackgroundCommunicationProgressing() == true
protocol.QCommit(false);
// ... QNeedToCommit() == false, QIsBackgroundCommunicationProgressing() == false
bool MProtocol::QIsDone ( )

Combines QNeedToCommit with the following QCommit in case all commands in the queue have been sent.

The relationship of this property with QNeedToCommit is shown below:

// ... QIsDone() == true, QNeedToCommit() == false
protocol.QConnect
protocol.QStartSession
protocol.QEndSession
protocol.QDisconnect
// ... QIsDone() == true, QNeedToCommit() == false
protocol.QCommit(true);
// ... QIsDone() == false, QNeedToCommit() == true
// ...
while ( !protocol.QIsDone() )
// ... QIsDone() == true, QNeedToCommit() == true
// ... No need to call meter.QCommit(false)

This property is used when QCommit was issued asynchronously. During asynchronous communications, the application is free to perform other work while waiting for the communications to complete. The application can periodically check QIsDone to determine if MCOM has completed processing the commands in the queue. For asynchronous communications, QIsDone will raise any communication errors. (For synchronous communications, any errors will be raised on QCommit.)

Asynchronous communications should check QIsDone until it reports True or raises an error. The asynchronous communication background thread can not terminate until QIsDone has been checked and it reports True or raises an error. If QIsDone is not checked until one of these states occur, then the next Q Command (such as QStartSession), will raise an error, even if the communications have completed. Most likely the error will indicate "Invalid operation during active background communication".

Note that QIsDone and QAbort are issued immediately, they do NOT require a QCommit.

bool MProtocol::QNeedToCommit ( ) const

Whether or not it is time to call QCommit(true) in order to sync with the background thread.

In case M_NO_MCOM_PROTOCOL_THREAD is nonzero during compilation, this service is not present. Asynchronous communication will not be supported in this case.

See also
QIsDone that combines QNeedToCommit with QCommit when the communication finishes.
void MProtocol::QStartSession ( )

Adds a start session command to MProtocol's command queue.

QStartSession performs the protocol services required to gain access to the meter, so that tables can be read and written and functions can be executed. Before committing the start session request, a connection with the meter must have been established using Connect() or QConnect.

When QStartSession is executed by QCommit, an active session with the meter is initiated. The start session action is not a single protocol command but rather a sequence of commands that establish an active communication session with the meter. Generally this sequence of commands handles handshaking with the meter, presenting a password, receiving permission to proceed, and negotiating various protocol settings. The exact sequence of steps performed by this method depends on the MProtocol Type. If the protocol does not support a start session, then QStartSession does nothing and does not generate an error. This is so programs that support multiple meters and protocols can be written with the QStartSession and QEndSession.

protocol.QStartSession()
protocol.QTableWrite(tableNum, data)
protocol.QEndSession()
protocol.QCommit()
void MProtocol::QTableRead ( MCOMNumberConstRef  number,
unsigned  expectedSize,
int  id 
)

Adds a ReadTable command to MProtocol's command queue.

This service is part of queue communication interface. The result table data can be retrieved by using the QGetTableData method.

Parameters
numberIdentifies the table to be placed into the queue. The format is protocol dependent. In can be a numeric value, as for the case of MProtocolC1218 or MProtocolC1222, or even a string if the protocol supports strings.
expectedSizeExpected table size in bytes. If this is zero, then the entire table will be read. If the protocol does not support full table reads then specifying a size of zero will result in an error being generated.
idOperation identifier to associate with the data returned from the device. When processing tables or functions with different numbers, this can be any value, as tables and functions can be identified by their numbers, however when using the same table or function number in the same queue, this ID should be unique, so the identification is possible.
void MProtocol::QTableReadPartial ( MCOMNumberConstRef  number,
int  offset,
int  size,
int  id 
)

Adds a partial table read command to MProtocol's command queue.

This service is part of queue communication interface.

Parameters
numberIdentifies the table to be placed into the queue. The format is protocol dependent. In can be a numeric value, as for the case of MProtocolC1218 or MProtocolC1222, or even a string if the protocol supports it.
offsetThe number of bytes from the beginning of the table where the operation will begin.
sizeThe number of bytes to be read starting from offset.
idOperation identifier to associate with the data returned from the device. When processing tables or functions with different numbers, this can be any value, as tables and functions can be identified by their numbers, however when using the same table or function number in the same queue, this ID should be unique, so the identification is possible.
void MProtocol::QTableWrite ( MCOMNumberConstRef  number,
const MByteString data 
)

Adds a table write command to MProtocol's command queue.

This service is part of queue communication interface.

Parameters
numberIdentifies the table to be placed into the queue. The format is protocol dependent. In can be a numeric value, as for the case of MProtocolC1218 or MProtocolC1222, or even a string if the protocol supports it.
dataThis buffer contains the data that will be written to the meter. The size of data determines the size of the buffer to be written.
void MProtocol::QTableWritePartial ( MCOMNumberConstRef  number,
const MByteString data,
int  offset 
)

Adds a partial table write command to MProtocol's command queue.

This service is part of queue communication interface.

Parameters
numberIdentifies the table to be placed into the queue. The format is protocol dependent. In can be a numeric value, as for the case of MProtocolC1218 or MProtocolC1222, or even a string if the protocol supports it.
dataThis buffer contains the data that will be written to the meter. The size of data determines the size of the buffer to be written.
offsetThe number of bytes from the beginning of the table where the write operation will begin.
void MProtocol::QWriteToMonitor ( const MStdString message)

Add the message to write to the Monitor log file to MProtocol's command queue.

The QWriteToMonitor method can be used to make communication transactions more readable by marking key data transactions, such as the start/end of a test.

QWriteToMonitor must be issued after the connection is established with the end device (Connect or QConnect). QWriteToMonitor is different than MMonitor::Write in that Write sends the message to the monitor immediately, whereas QWriteToMonitor is executed as part of the command queue on QCommit.

No error is thrown if the Monitor is not listening or the log file is not accumulating.

Parameters
messageThe message to write to the Monitor log file.
See also
WriteToMonitor - no-queue version of the method
Muint8 MProtocol::ReadStartByte ( const MByteString setOfValidStartBytes,
unsigned  trafficTimeout 
)

Read the start byte of the packet in a proper way, taking into consideration timeouts and ignoring garbage.

Parameters
setOfValidStartBytes- sequence of bytes that are valid start characters.
trafficTimeout- how long to wait for arrival of start byte.
Returns
the character that was successfully received, one among setOfValidStartBytes.
Precondition
The start character among those in the set given should be present in the input stream within trafficTimeout period. Otherwise an exception is thrown.
void MProtocol::ResetCounts ( )

Clear the statistical data for the channel.

Zeroes Out the COUNT_* and *_ROUND_TRIP_TIME properties. The list of properties that are reset follows:

If the channel is present, its own MChannel::ResetCounts() is called and channel's counts are reset.

See also
MChannel::ResetCounts()
void MProtocol::SetChannel ( MChannel channel)

Channel associated with this protocol.

When the channel is owned, and a new one is reassigned to the protocol, the previous channel will be deleted.

void MProtocol::SetIsChannelOwned ( bool  yes)
inline

Whether the channel is owned by this protocol.

When the channel is owned, it will be deleted by protocol destructor, or at the event of channel reassignment to the protocol.

void MProtocol::SetKeepSessionAlive ( bool  alive)

Whether the protocol should keep session alive in case of long inactivity.

When KeepSessionAlive is true, the session is kept from timing out. The feature can also be used to prevent an idling connection from being closed. What is done to keep the session alive is protocol dependent, but usually involves repeatedly sending some type of communication request to the meter. For some sessionless protocols this property has no effect.

The session is being kept alive by a background thread that is watching for the current value of property IsInSession. When IsInSession is true, the background communication is performed. Errors raised on the background can be silenced if IsConnected value was false. Otherwise, the session keeping errors will be thrown to the foreground thread at the next communication event, such as QCommit. Another place that checks and throws an error collected by the background thread is the assignment to KeepSessionAlive property itself. Therefore, the following will check for an error, and throw it if it was present:

protocol.SetKeepSessionAlive(protocol.GetKeepSessionAlive()); // C++

When KeepSessionAlive is false, the session will time out or the connection will be closed according to the protocol rules.

Since
MeteringSDK Version 3.2.6.
Default value:
False
Possible values:
  • True [1] : The session will not time out.
  • False [0] : The session will time out according to the protocol rules.
See also
IsInSession - whether the session keeping is active.
void MProtocol::SetMeterIsLittleEndian ( bool  isLittleEndian)
inline

Primary data order of the device, whether it is little endian.

This information is used by some protocol implementations, for example, for ANSI procedures/functions implementation. Such protocols have application-level fields that depend on the protocol byte order.

It is only necessary to set this property when communicating to a device of different endianity as the protocol default. When communicating through the upper library levels this property can be set automatically.

Default value:
Depends on the protocol type. Most of the protocols are little endian, while some legacy ones are big endian.
Since
MeteringSDK Version 2.1.27.
Possible values:
  • True [1] : Little Endian
  • False [0] : Big Endian
void MProtocol::SetPassword ( const MByteString password)

Application level password of the protocol.

The Password property is the binary value that is used to gain access to the device. No interpretation of C escape character sequences is performed on this string.

Many protocols will typically use password in the StartSession sequence, while some, such as sessionless mode of MProtocolC1222, will send password at every request.

The password can have less characters than the maximum number of characters allowed. In this case, during the communication, the password will be padded with a fill character (different for each protocol). For example, if an 8 character password is set to "1111", then the password "1111 " is transmitted during communications, while Password property will continue to report "1111". The padded characters are significant, and the password stored in the meter must exactly match the password used during communications (including the fill characters) or an error is generated.

Default value:
Possible values:
  • "12345678901234567890" : Passwords for the MProtocolC1218, MProtocolC1221, and MProtocolC1222 protocols (A3, A1800 meters) can have a maximum of 20 characters. If the specified password is less than 20 characters, then the remaining characters are filled with blank spaces during communication.
void MProtocol::SetPasswordList ( const MByteStringVector passwordList)

Password list for the protocol.

The password lists, when not empty, overwrite the SetPassword property. In such case, passwords from the password list are applied in the ascending order until a successful entry is found. If none exists, the last error received during list processing is thrown.

See also
GetPassword
ClearPasswordList - clear the password list
AddToPasswordList - add entry to password list
GetPasswordListSuccessfulEntry - shall be called after successful start session to know which password list worked.
void MProtocol::SetProgressMonitor ( MProgressMonitor p)
inline

Access to the progress monitor, if exists

void MProtocol::Sleep ( unsigned  milliseconds)

Calls channel's Sleep method if the channel is present.

Channel's sleep is interruptible, and this is the difference of this method from plain MUtilities::Sleep.

Parameters
millisecondsHow many milliseconds to sleep.
void MProtocol::StartSession ( )

Synchronously start the session.

Depending on the particular protocol this leads to a sequence of handshake and logon commands.

See QStartSession for the queue version of this service. Q services would work faster for the queue based protocols, but slower for synchronous protocols like C12. Also, they are obviously less convenient for synchronous operations.

Precondition
The channel is open, the protocol state allows starting the session. Otherwise exceptions can be thrown.
static unsigned MProtocol::StaticCalculateChecksum ( const MByteString buffer)
static

Compute checksum of the byte string given as parameters.

The checksum is calculated based on the C12 rules. Different protocols can have their own variants of this method.

Parameters
bufferThe buffer for which to calculate the checksum.
Returns
Value of the checksum, two bytes returned within the low part of four bytes.
static unsigned MProtocol::StaticCalculateChecksumFromBuffer ( const char *  buff,
unsigned  size 
)
static

Most popular one-byte checksum calculation procedure, a sum of all bytes.

The checksum is calculated based on the C12 rules. Different protocols can have their own variants of this method.

Parameters
buffThe pointer to the buffer for which to calculate the checksum.
sizeSize of the buffer.
Returns
Value of the checksum, one byte as lower part of four bytes.
See also
CalculateChecksumFromBuffer Virtual protocol dependent variant of this method.
MByteString MProtocol::TableRead ( MCOMNumberConstRef  number,
unsigned  expectedSize = 0 
)

Synchronously read the whole table with number given as parameter.

See QTableRead for the queue version of this service. Q services would work faster for the queue based protocols, but slower for synchronous protocols like C12. Also, they are obviously less convenient for synchronous operations.

The third argument is introduced to handle a special case where the table size is bigger than what the protocol allows, such as configuring an ANSI meter to have more load profile data than the 64K that can be transmitted with ANSI C12.18. In this case the table is read with multiple partial reads, where each partial read is sized to fit within the protocol constraints.

Precondition
The channel is open, the session is started. Otherwise exceptions can be thrown.
Parameters
numberTable number.
expectedSizeIf given, should match exactly the size of the table.
Returns
Table data bytes
void MProtocol::TableReadBuffer ( MCOMNumberConstRef  number,
void *  buff,
unsigned  size 
)

Same as ReadTable, but instead of returning a byte string, read table into a given buffer.

Precondition
In addition to all preconditions of ReadTable, the given buffer shall match the table size exactly, or a size mismatch exception is thrown.
Parameters
numberTable number.
buffWhere to return the table bytes.
sizeSize of the given buffer and size of the table.
template<class T >
void MProtocol::TableReadBuffer ( MCOMNumberConstRef  number,
T &  table 
)
inline

Same as ReadTable, but instead of returning a byte string, read table into a given template variable.

Precondition
In addition to all preconditions of ReadTable, the given buffer shall match the table size exactly, or a size mismatch exception is thrown.
MByteString MProtocol::TableReadNoThrow ( MCOMNumberConstRef  number,
MException **  exception,
unsigned  expectedSize = 0 
)

Synchronously read the whole table with number given as parameter, do not throw an exception, but rather return it.

See QTableRead for the queue version of this service. Q services would work faster for the queue based protocols, but slower for synchronous protocols like C12. Also, they are obviously less convenient for synchronous operations.

The second argument is introduced to handle exceptions internally and return the data that was successfully read before the exception was raised.

The third argument is introduced to handle a special case where the table size is bigger than what the protocol allows, such as configuring an ANSI meter to have more load profile data than the 64K that can be transmitted with ANSI C12.18. In this case the table is read with multiple partial reads, where each partial read is sized to fit within the protocol constraints.

Precondition
The channel is open, the session is started. Otherwise exceptions can be thrown. The exception is not NULL, there is a debug check.
Parameters
numberTable number.
exceptionReturned new object, exception, if it was thrown during the operation. If not NULL, it has to be deleted by the caller.
expectedSizeIf given, should match exactly the size of the table.
Returns
Table data bytes.
MByteString MProtocol::TableReadPartial ( MCOMNumberConstRef  number,
int  offset,
int  size 
)

Synchronously read part of the table with number given as parameter.

See QTableReadPartial for the queue version of this service. Q services would work faster for the queue based protocols, but slower for synchronous protocols like C12. Also, they are obviously less convenient for synchronous operations.

Precondition
The channel is open, the session is started. Otherwise exceptions can be thrown.
Parameters
numberTable number.
offsetOffset within the table.
sizeSize within the table starting from the offset.
Returns
Table data bytes.
void MProtocol::TableReadPartialBuffer ( MCOMNumberConstRef  number,
int  offset,
void *  buff,
unsigned  size 
)

Same as TableReadPartial, but instead of returning a byte string, read table into a given buffer.

Parameters
numberTable number.
offsetOffset within the table.
buffWhere to return the table bytes.
sizeSize of the partial chunk and size of buff.
Returns
Table data bytes.
template<class T >
void MProtocol::TableReadPartialBuffer ( MCOMNumberConstRef  number,
T &  table,
int  offset 
)
inline

Same as TableReadPartial, but instead of returning a byte string, partially read table into a given template variable.

Parameters
numberTable number.
tableTable raw structure or class.
offsetOffset within the table.
void MProtocol::TableWrite ( MCOMNumberConstRef  number,
const MByteString data 
)

Synchronously write the whole table with number given as parameter.

See QTableWrite for the queue version of this service. Q services would work faster for the queue based protocols, but slower for synchronous protocols like C12. Also, they are obviously less convenient for synchronous operations.

Precondition
The channel is open, the session is started. Otherwise exceptions can be thrown.
Parameters
numberTable number.
dataTable data to be written.
void MProtocol::TableWriteBuffer ( MCOMNumberConstRef  number,
const void *  data,
unsigned  size 
)

Same as TableWrite, but uses buffer, given as data and size parameters.

Parameters
numberTable number.
dataPointer to table data to be written.
sizeSize of the table data.
See also
TableWrite
template<class T >
void MProtocol::TableWriteBuffer ( MCOMNumberConstRef  number,
const T &  table 
)
inline

Same as WriteTable, but uses variable of some specific template class or structure.

Parameters
numberTable number.
tableTable raw structure or class.
See also
TableWrite
void MProtocol::TableWritePartial ( MCOMNumberConstRef  number,
const MByteString data,
int  offset 
)

Synchronously write part of the table with number given as parameter.

See QTableWritePartial for the queue version of this service. Q services would work faster for the queue based protocols, but slower for synchronous protocols like C12. Also, they are obviously less convenient for synchronous operations.

Precondition
The channel is open, the session is started. Otherwise exceptions can be thrown.
Parameters
numberTable number.
dataTable data to be written at a given offset.
offsetOffset within the table.
void MProtocol::TableWritePartialBuffer ( MCOMNumberConstRef  number,
int  offset,
const void *  buff,
unsigned  size 
)

Same as TableWritePartial, but instead of using a byte string, write table using a given buffer.

Parameters
numberTable number.
offsetOffset within the table.
buffPointer to table data to be written at a given offset.
sizeSize of the data.
template<class T >
void MProtocol::TableWritePartialBuffer ( MCOMNumberConstRef  number,
const T &  table,
int  offset 
)
inline

Same as TableWritePartial, but instead of using a byte string, write table using a given template class contents.

Parameters
numberTable number.
tableTable raw structure or class.
offsetOffset within the table.
void MProtocol::WriteCountsToMonitor ( )

Write running values of communication quality counters to monitor.

This is a convenience method for all types of troubleshooting. No errors are thrown. If there is no monitor connected, nothing is done.

virtual void MProtocol::WriteToMonitor ( const MStdString message)
virtual

Synchronously write a message to the monitor, if it is connected.

No error is thrown if the Monitor is not listening or the log file is not accumulating.

Parameters
messageThe message to write to the Monitor log file.
See also
QWriteToMonitor - queue based version of this service.

Reimplemented from MCOMObject.