C12Adapter Opensource C++ Interface
MChannelSerialPort Class Reference

Serial port based channel, a null cable direct serial link or a link through a current loop adapter. More...

Inheritance diagram for MChannelSerialPort:

Public Member Functions

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

Static Public Member Functions

static MStdStringVector GetAvailablePortNames (bool addExtraInfo=false)
 Return a collection of serial port names available at this computer. More...
 
static MStdString GetPortType (const MStdString &portName)
 Get type based on the port name. More...
 
- Static Public Member Functions inherited from MObject
static const MClassGetStaticClass ()
 Get the declared class of this particular object. More...
 
static bool IsClassPresent (const MStdString &name)
 Tells if the given class name is available. More...
 

Additional Inherited Members

- Public Types inherited from MChannel
enum  { CANCEL_COMMUNICATION_CHECK_OPTIMUM_INTERVAL = 1000 }
 
- Static Public Attributes inherited from MObject
static const MClass s_class
 Class of MObject.
 
- Protected Member Functions inherited from MChannel
 MChannel ()
 Construct the channel object from parent class. More...
 
- Protected Member Functions inherited from MCOMObject
 MCOMObject ()
 Object constructor, protected as the class is abstract.
 
- Protected Member Functions inherited from MObject
 MObject ()
 Object constructor, protected as the class is abstract.
 
void DoSetPersistentPropertiesToDefault (const MClass *staticClass)
 Set the persistent properties to their default values for one object provided the class for that object. More...
 

Detailed Description

Serial port based channel, a null cable direct serial link or a link through a current loop adapter.

It forms the basic interface to the rest of the COM port based channels and MChannel Type's MChannelOpticalProbe and MChannelModem inherit their properties from MChannelSerialPort. Many properties of MChannelSerialPort are controlled by the communication protocols or by the child channels; however, an advanced user can override the values set by the protocols and children channels at any time to achieve advanced behavior for test purposes.

Member Function Documentation

virtual void MChannelSerialPort::Connect ( )
virtual

Establishes the connection to the meter using the serial port.

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

Reimplemented from MChannel.

Reimplemented in MChannelOpticalProbe, and MChannelModem.

virtual void MChannelSerialPort::FlushOutputBuffer ( unsigned  numberOfCharsInBuffer = UINT_MAX)
virtual

Ensure that the characters from the output buffer are sent.

Parameters
numberOfCharsInBufferIf specified, should match the number of characters written into the serial port right before FlushOutputBuffer is called. If the parameter is missing, the biggest possible number of characters will be flushed.
Precondition
The channel is open, otherwise the operation fails with the exception.

Implements MChannel.

static MStdStringVector MChannelSerialPort::GetAvailablePortNames ( bool  addExtraInfo = false)
inlinestatic

Return a collection of serial port names available at this computer.

Names returned can be given to GetPortName. The returned names are operating system dependent.

  • On Windows the names are "COMxxxx", where xxxx is an integer digit. When extra information is added , they are like "COM11 {USB Optical Probe}".
  • UNIX-like operating systems such as Linux, QNX (but not on Android) return device names such as "/dev/ttyS0". Extra information will be "/dev/ttyS0 {pnp/drivers/serial}".
  • On Android the port name rules are more diverse as the standard Android does not expose serial port device files. Bluetooth serial ports use the name of the paired device, and FTDI USB probes accepts the device description. Extra information will include MAC address for Bluetooth or device index for FTDI USB device.
Parameters
addExtraInfowhether to add any extra information about the port, useful for users to select the port.
Returns
array of present port names
unsigned MChannelSerialPort::GetBaud ( ) const
inline

Get the baud rate of the channel, BAUD public attribute.

Serial data rate as defined by the RS-232 standard. The channels, MChannelSerialPort, MChannelCurrentLoop, MChannelModem, and MChannelModemCallback have full control of the value of the Baud property and their client protocols will not make any attempt to change it. When using MChannelSerialPort, make sure that the meter configuration matches the channel settings.

In contrast, MChannelOpticalProbe, child of MChannelSerialPort, this property is controlled by the protocols.

Since
MeteringSDK Version 2.1.27.
Default value:
28800
Possible values:
  • 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 115200, 128000, 256000
bool MChannelSerialPort::GetCtsFlow ( ) const
inline

Flag to enable Clear To Send (CTS) flow control on the serial port.

Use caution when setting this property, as the protocols might override this value while communicating.

Since
MeteringSDK Version 2.1.27.
Default value:
Possible values:
  • True [1] : CTS flow control enabled
  • False [0] : CTS flow control disabled
int MChannelSerialPort::GetDataBits ( ) const
inline

The number of Data bits in a serial data frame.

The protocols impose their own restrictions on the data bits, and they handle this property during communication. For MChannelModem and MChannelModemCallback, this property has to be set in a way that is compatible with both the modem and the protocol.

Only an advanced user would change this property for MChannelCurrentLoop, MChannelSerialPort, and MChannelOpticalProbe. For example, to ensure the proper display of the communication error code by the meter.

Since
MeteringSDK Version 2.1.27.
Default value:
8
Possible values:
  • 5 .. 8
bool MChannelSerialPort::GetDCD ( ) const
inline

The current state of the DCD signal of the port.

Precondition
The port has to be open, otherwise a system error takes place.
bool MChannelSerialPort::GetDsrFlow ( ) const
inline

Flag to enable Data Set Ready (DSR) flow control on the serial port.

Use caution when setting this property, as the protocols might override this value while communicating.

Since
MeteringSDK Version 2.1.27.
Default value:
False
Possible values:
  • True [1] : DSR flow control enabled
  • False [0] : DSR flow control disabled
bool MChannelSerialPort::GetDsrSensitivity ( ) const
inline

Flag to set the level sense of the Data Set Ready (DSR) signal for the serial port.

Use caution when setting this property, as the protocols might override this value while communicating.

Since
MeteringSDK Version 2.1.27.
Default value:
False
Possible values:
  • True [1] : Communication is sensitive to DSR level.
  • False [0] : Communication is not sensitive to DSR level.
char MChannelSerialPort::GetDtrControl ( ) const
inline

Sets the Data Terminal Ready (DTR) control mode for the serial port.

Use caution when overwriting this property, as the protocols impose their own restrictions on the DTR control, and they handle this property during communication. For example, setting the value of MChannelOpticalProbe::GetBatteryState will affect the value of DtrControl.

Since
MeteringSDK Version 2.1.27.
Default value:
Possible values:
  • "E" : enable
  • "D" : disable
  • "H" : handshake
virtual MStdString MChannelSerialPort::GetMediaIdentification ( ) const
virtual

Return a string that will identify the media through which this channel is talking to.

For serial port based channels, it will return a host name, SERIAL string, and port name.

Implements MChannel.

char MChannelSerialPort::GetParity ( ) const
inline

Sets the parity bit mode for the serial data frame.

The protocols impose their own restrictions on the data bits, and they handle this property during communication. For MChannelModem and MChannelModemCallback, this property has to be set in a way that is compatible with both the modem and the protocol.

Only an advanced user would change this property for MChannelCurrentLoop, MChannelSerialPort, and MChannelOpticalProbe. For example, to ensure the proper display of the communication error code by the meter.

Since
MeteringSDK Version 2.1.27.
Default value:
"N" : No Parity
Possible values:
  • "N" : no parity
  • "O" : odd parity
  • "E" : even parity
  • "M" : mark
  • "S" : space
MSerialPort& MChannelSerialPort::GetPort ( )
inline

Access serial port system object.

const MSerialPort& MChannelSerialPort::GetPort ( ) const
inline

Access serial port system object.

const MStdString& MChannelSerialPort::GetPortName ( ) const
inline

Port name is the file name which is used by the operating system to open the port, OS dependent.

Name of the communication port. The port name is determined by the operating system.

Since
MeteringSDK Version 2.1.27.
Default value:
"COM1" on Windows, "/dev/ttyS0" on all other operating systems
Possible values:
There is no syntactical restriction on what can be the name of the port, and here are few examples given for different operating systems:
  • "/dev/ttyS0" : Typical device name for a serial port on UNIX-like systems such as Linux or QNX.
  • "/dev/ttyS0 {pnp/drivers/serial}" : Linux serial port with extra information as returned by GetAvailablePortNames(true).
  • "COM1" .. "COM99" .. "COMxxxx" .. : Standard Windows port names (where xxxx is an integer digit).
  • "COM1 {USB Serial Probe}" : Windows port name as returned by GetAvailablePortNames(true).
  • "\\\\.\\COMxxxx" : Windows serial port device names in the global namespace (where xxxx is an integer digit). Specifying such name should open the port a bit faster for names above "COM9". Internally on Windows the port name as provided will be tried, if it fails, then the port name with the standard network naming convention applied is tried.
  • "USB Serial Probe" : Android USB probe as returned by GetAvailablePortNames(false).
  • "USB Serial Probe {usb#12425}" : Android USB probe as returned by GetAvailablePortNames(true) - allows distinguishing between devices if there is more than one of the same type connected.
  • "Bluetooth Probe" : Android paired Bluetooth probe as returned by GetAvailablePortNames(false).
  • "Bluetooth Probe {mac#00:01:02:03:04:05}" : Android paired Bluetooth probe as returned by GetAvailablePortNames(true) - allows distinguishing between devices if there is more than one of the same type paired.
See also
GetAvailablePortNames
static MStdString MChannelSerialPort::GetPortType ( const MStdString portName)
inlinestatic

Get type based on the port name.

Provides information about underlying port technology. When such information is not available, for example the given port name is not present, an empty string is returned. Otherwise the string returned can be one of the following types:

  • "serial" wide range of different UART based serial drivers
  • "bluetooth" for bluetooth devices
  • "usb" USB serial devices
  • "remote" remote ports such as MOXA NPort
  • "" empty string can be returned only on Android when MeteringSDK could not determine the type of the port
  • Any other name will mean the type of the port is determined, but not recognized and classified. Such name is still useful as it identifies the port type.

All known port types will always appear in lowercase. Unknown port types will preserve the letter case defined by the operating system. The port will not be opened by the call.

This is a static method as it allows getting information without opening the port. A string is returned rather than an enumeration as it allows returning useful information even when the port type is not recognized and classified.

Parameters
portNameName of the port such as "COM11" on Windows or "/dev/ttyS0" on Linux
Returns
Port type string with contents described above.
char MChannelSerialPort::GetRtsControl ( ) const
inline

Request To Send (RTS) control mode for the serial port.

The protocols impose their own restrictions on the data bits, and they handle this property during communication. For MChannelModem and MChannelModemCallback, this property has to be set in a way that is compatible with the modem.

Since
MeteringSDK Version 2.1.27.
Default value:
Possible values:
  • "E" : enable
  • "D" : disable
  • "H" : handshake
  • "T" : toggle
int MChannelSerialPort::GetStopBits ( ) const
inline

The number of stop-bits in a serial data frame.

The protocols impose their own restrictions on the data bits, and they handle this property during communication. For MChannelModem and MChannelModemCallback, this property has to be set in a way that is compatible with both the modem and the protocol.

Only an advanced user would change this property for MChannelCurrentLoop, MChannelSerialPort and MChannelOpticalProbe. For example, to ensure the proper display of the communication error code by the meter.

Since
MeteringSDK Version 2.1.27.
Default value:
1
Possible values:
  • 1 or 2, there is no support for 1.5 stop bits.
void MChannelSerialPort::SetBaud ( unsigned  baud)
inline

Get the baud rate of the channel, BAUD public attribute.

Serial data rate as defined by the RS-232 standard. The channels, MChannelSerialPort, MChannelCurrentLoop, MChannelModem, and MChannelModemCallback have full control of the value of the Baud property and their client protocols will not make any attempt to change it. When using MChannelSerialPort, make sure that the meter configuration matches the channel settings.

In contrast, MChannelOpticalProbe, child of MChannelSerialPort, this property is controlled by the protocols.

Since
MeteringSDK Version 2.1.27.
Default value:
28800
Possible values:
  • 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 115200, 128000, 256000
void MChannelSerialPort::SetCtsFlow ( bool  isCtsFlow)
inline

Flag to enable Clear To Send (CTS) flow control on the serial port.

Use caution when setting this property, as the protocols might override this value while communicating.

Since
MeteringSDK Version 2.1.27.
Default value:
Possible values:
  • True [1] : CTS flow control enabled
  • False [0] : CTS flow control disabled
void MChannelSerialPort::SetDataBits ( int  dataBits)
inline

The number of Data bits in a serial data frame.

The protocols impose their own restrictions on the data bits, and they handle this property during communication. For MChannelModem and MChannelModemCallback, this property has to be set in a way that is compatible with both the modem and the protocol.

Only an advanced user would change this property for MChannelCurrentLoop, MChannelSerialPort, and MChannelOpticalProbe. For example, to ensure the proper display of the communication error code by the meter.

Since
MeteringSDK Version 2.1.27.
Default value:
8
Possible values:
  • 5 .. 8
void MChannelSerialPort::SetDsrFlow ( bool  isDsrFlow)
inline

Flag to enable Data Set Ready (DSR) flow control on the serial port.

Use caution when setting this property, as the protocols might override this value while communicating.

Since
MeteringSDK Version 2.1.27.
Default value:
False
Possible values:
  • True [1] : DSR flow control enabled
  • False [0] : DSR flow control disabled
void MChannelSerialPort::SetDsrSensitivity ( bool  isDsrSens)
inline

Flag to set the level sense of the Data Set Ready (DSR) signal for the serial port.

Use caution when setting this property, as the protocols might override this value while communicating.

Since
MeteringSDK Version 2.1.27.
Default value:
False
Possible values:
  • True [1] : Communication is sensitive to DSR level.
  • False [0] : Communication is not sensitive to DSR level.
void MChannelSerialPort::SetDtrControl ( char  dtrControl)
inline

Sets the Data Terminal Ready (DTR) control mode for the serial port.

Use caution when overwriting this property, as the protocols impose their own restrictions on the DTR control, and they handle this property during communication. For example, setting the value of MChannelOpticalProbe::GetBatteryState will affect the value of DtrControl.

Since
MeteringSDK Version 2.1.27.
Default value:
Possible values:
  • "E" : enable
  • "D" : disable
  • "H" : handshake
void MChannelSerialPort::SetParity ( char  p)
inline

Sets the parity bit mode for the serial data frame.

The protocols impose their own restrictions on the data bits, and they handle this property during communication. For MChannelModem and MChannelModemCallback, this property has to be set in a way that is compatible with both the modem and the protocol.

Only an advanced user would change this property for MChannelCurrentLoop, MChannelSerialPort, and MChannelOpticalProbe. For example, to ensure the proper display of the communication error code by the meter.

Since
MeteringSDK Version 2.1.27.
Default value:
"N" : No Parity
Possible values:
  • "N" : no parity
  • "O" : odd parity
  • "E" : even parity
  • "M" : mark
  • "S" : space
void MChannelSerialPort::SetPortName ( const MStdString portName)

Port name is the file name which is used by the operating system to open the port, OS dependent.

Name of the communication port. The port name is determined by the operating system.

Since
MeteringSDK Version 2.1.27.
Default value:
"COM1" on Windows, "/dev/ttyS0" on all other operating systems
Possible values:
There is no syntactical restriction on what can be the name of the port, and here are few examples given for different operating systems:
  • "/dev/ttyS0" : Typical device name for a serial port on UNIX-like systems such as Linux or QNX.
  • "/dev/ttyS0 {pnp/drivers/serial}" : Linux serial port with extra information as returned by GetAvailablePortNames(true).
  • "COM1" .. "COM99" .. "COMxxxx" .. : Standard Windows port names (where xxxx is an integer digit).
  • "COM1 {USB Serial Probe}" : Windows port name as returned by GetAvailablePortNames(true).
  • "\\\\.\\COMxxxx" : Windows serial port device names in the global namespace (where xxxx is an integer digit). Specifying such name should open the port a bit faster for names above "COM9". Internally on Windows the port name as provided will be tried, if it fails, then the port name with the standard network naming convention applied is tried.
  • "USB Serial Probe" : Android USB probe as returned by GetAvailablePortNames(false).
  • "USB Serial Probe {usb#12425}" : Android USB probe as returned by GetAvailablePortNames(true) - allows distinguishing between devices if there is more than one of the same type connected.
  • "Bluetooth Probe" : Android paired Bluetooth probe as returned by GetAvailablePortNames(false).
  • "Bluetooth Probe {mac#00:01:02:03:04:05}" : Android paired Bluetooth probe as returned by GetAvailablePortNames(true) - allows distinguishing between devices if there is more than one of the same type paired.
See also
GetAvailablePortNames
void MChannelSerialPort::SetRtsControl ( char  rtsControl)
inline

Request To Send (RTS) control mode for the serial port.

The protocols impose their own restrictions on the data bits, and they handle this property during communication. For MChannelModem and MChannelModemCallback, this property has to be set in a way that is compatible with the modem.

Since
MeteringSDK Version 2.1.27.
Default value:
Possible values:
  • "E" : enable
  • "D" : disable
  • "H" : handshake
  • "T" : toggle
void MChannelSerialPort::SetStopBits ( int  stopBits)
inline

The number of stop-bits in a serial data frame.

The protocols impose their own restrictions on the data bits, and they handle this property during communication. For MChannelModem and MChannelModemCallback, this property has to be set in a way that is compatible with both the modem and the protocol.

Only an advanced user would change this property for MChannelCurrentLoop, MChannelSerialPort and MChannelOpticalProbe. For example, to ensure the proper display of the communication error code by the meter.

Since
MeteringSDK Version 2.1.27.
Default value:
1
Possible values:
  • 1 or 2, there is no support for 1.5 stop bits.
virtual void MChannelSerialPort::WaitForNextIncomingConnection ( bool  reinitialize = true)
virtual

When GetAutoAnswer true, wait for the incoming connection without disconnecting the channel.

A typical server application sequence that uses this call:

Connect() // wait for the first incoming connection
loop until interrupted:
... communicate ...
WaitForNextIncomingConnection() // wait for the next incoming connection
end loop
Parameters
reinitializeTells if reinitialization of the channel has to be made at each new incoming connection.
Precondition
Prior to this call, the channel needs to be configured with SetAutoAnswer true, and the connection established with Connect(). Not all channels support Auto Answer mode, and might throw an exception. A timeout exception is thrown if no call is received during the GetAutoAnswerTimeout period.

Reimplemented from MChannel.

Reimplemented in MChannelModem.