mbserver 0.5.0
modbus.Address Class Reference
Collaboration diagram for modbus.Address:
Collaboration graph

Public Member Functions

 __init__ (self, value=None, offset=None)
bool isvalid (self)
int type (self)
 settype (self, int tp)
int offset (self)
 setoffset (self, int offset)
int number (self)
 setnumber (self, int number)
 fromint (self, int v)
int toint (self)
 fromstr (self, str s)
str tostr (self, int notation=Notation_Default)
 __int__ (self)
 __lt__ (self, other)
 __le__ (self, other)
 __eq__ (self, other)
 __ne__ (self, other)
 __gt__ (self, other)
 __ge__ (self, other)
 __hash__ (self)
 __add__ (self, int other)
 __sub__ (self, int other)
 __iadd__ (self, int other)
 __isub__ (self, int other)
 __repr__ (self)
 __str__ (self)

Protected Attributes

 _type = Memory_Unknown
int _offset = 0

Detailed Description

Modbus Data Address class. Represents Modbus Data Address.

`Address` class is used to represent Modbus Data Address. It contains memory type and offset.
E.g. `modbus.Address(modbus.Memory_4x, 0)` creates `400001` standard address.
E.g. `modbus.Address(400001)` creates `Address` with type `Modbus::Memory_4x` and offset `0`, and
`modbus.Address(1)` creates `modbus.Address` with type `modbus.Memory_0x` and offset `0`.
Class provides convertions from/to string methods.

Class supports next operators and standard functions:
+, -, <, <=, >, >=, ==, !=, hash(), str(), int()

Constructor & Destructor Documentation

◆ __init__()

modbus.Address.__init__ ( self,
value = None,
offset = None )
Constructor of the class.

Can have next forms:
* `Address()`  - creates invalid address class
* `Address(Memory_4x, 0)`  - creates address for holding registers with `offset=0`
* `Address("%MW0")`  - creates address for holding registers with `offset=0`
* `Address("%Q0000h")`  - creates address for coils with `offset=0`
* `Address("100001")`  - creates address for input discretes with `offset=0`
* `Address(300001)`  - creates address for input registers with `offset=0`

Member Function Documentation

◆ __add__()

modbus.Address.__add__ ( self,
int other )
Return a new Address object with the offset increased by the given integer.

◆ __eq__()

modbus.Address.__eq__ ( self,
other )
Return self.toint() == other.toint()

◆ __ge__()

modbus.Address.__ge__ ( self,
other )
Return self.toint() >= other.toint()

◆ __gt__()

modbus.Address.__gt__ ( self,
other )
Return self.toint() > other.toint()

◆ __hash__()

modbus.Address.__hash__ ( self)
Return the hash of the object.

◆ __iadd__()

modbus.Address.__iadd__ ( self,
int other )
Increase the offset by the given integer.

◆ __int__()

modbus.Address.__int__ ( self)
Return the integer representation of the object by calling the toint() method.

◆ __isub__()

modbus.Address.__isub__ ( self,
int other )
Decrease the offset by the given integer.

◆ __le__()

modbus.Address.__le__ ( self,
other )
Return self.toint() <= other.toint()

◆ __lt__()

modbus.Address.__lt__ ( self,
other )
Return self.toint() < other.toint()

◆ __ne__()

modbus.Address.__ne__ ( self,
other )
Return self.toint() != other.toint()

◆ __repr__()

modbus.Address.__repr__ ( self)
Return the string representation of the object.

◆ __str__()

modbus.Address.__str__ ( self)
Return the string representation of the object.

◆ __sub__()

modbus.Address.__sub__ ( self,
int other )
 Return a new Address object with the offset decreased by the given integer.

◆ fromint()

modbus.Address.fromint ( self,
int v )
Make modbus address from integer representaion

◆ fromstr()

modbus.Address.fromstr ( self,
str s )
Make modbus address from string representaion

◆ isvalid()

bool modbus.Address.isvalid ( self)
Returns `True` if memory type is not `Modbus::Memory_Unknown`, `False` otherwise.

◆ number()

int modbus.Address.number ( self)
 Returns memory number (offset+1) of Modbus Data Address.

◆ offset()

int modbus.Address.offset ( self)
Returns memory offset of Modbus Data Address.

◆ setnumber()

modbus.Address.setnumber ( self,
int number )
Set memory number (offset+1) of Modbus Data Address.

◆ setoffset()

modbus.Address.setoffset ( self,
int offset )
Sets memory offset of Modbus Data Address.

◆ settype()

modbus.Address.settype ( self,
int tp )
Sets memory type of Modbus Data Address.

◆ toint()

int modbus.Address.toint ( self)
Converts current Modbus Data Address to `int`,
e.g. `Address(Memory_4x, 0)` will be converted to `400001`.

◆ tostr()

str modbus.Address.tostr ( self,
int notation = Notation_Default )
Returns string repr of Modbus Data Address with specified notation:
* `Notation_Modbus`      - `Address(Memory_4x, 0)` will be converted to `"400001"`.
* `Notation_IEC61131`    - `Address(Memory_4x, 0)` will be converted to `"%MW0"`.
* `Notation_IEC61131Hex` - `Address(Memory_4x, 0)` will be converted to `"%MW0000h"`.

◆ type()

int modbus.Address.type ( self)
Returns memory type of Modbus Data Address.

The documentation for this class was generated from the following file: