MPBus
Introduction
This module implements the Belimo MP bus protocol.
Initialization
from mb_tester.MBTester import MBTester;
from mb_tester.MPSerialPort import MPSerialPort;
from mb_tester.MPBus import MPBus;
# An MBTester object is required
tester = MBTester(...);
# An MPSerialPort object is required
mpserial = MPSerialPort(...);
# create an MPBus instance
mpbus = MPBus( aTester = tester, aDefaultPort = mpserial );
MP Command Parameters
Common parameters used in MP Commands, for example: Peek, Poke, SetData, GetData, etc.
aCommunicationType : Override the MP address (communication type) of the used port for the current command. For possible values see CommunicationTypes.
Timeouts
The time limit to wait for an answer is 800 ms. If a no answer is received within the timeout, retry 3 times by default. The number of retries can be set in the MPSerialPort.
Types
These are the types of configurations related to MPBus.
MPBaudRates
Import : ‘from mb_tester.MPSerialPort import MPBaudRates’
class MPBaudRates(IntEnum):
B1200 = 1200;
B9600 = 9600;
B38400 = 38400;
CommunicationTypes
Import : ‘from mb_tester.MPBus import CommunicationTypes’
class CommunicationTypes(IntEnum):
UNKNOWN = 0;
MP1 = 1;
MP2 = 2;
MP3 = 3;
MP4 = 4;
MP5 = 5;
MP6 = 6;
MP7 = 7;
MP8 = 8;
MP9 = 9;
MP10 = 10;
MP11 = 11;
MP12 = 12;
MP13 = 13;
MP14 = 14;
MP15 = 15;
MP16 = 16;
MASTER = 17;
PP = 18;
PPX = 19;
BROADCAST = 20;
ONEVENT = 21;
TOOLSLAVE = 22;
Class MPBus
This class provides MP communication with MP slaves. It implements a selection of the most common MP commands. In addition it enables to send any MP command using the GenerateCommandBytes() and SendRaw() functions.
Methods
Constructor
def __init__( self
, aTester : MBTester
, aDefaultPort : MPBusPort ):
Arguments
aTester : An MBTester object. It is used for logging results and accessing parameters
aDefaultPort : An MPBusPort object to be used as default. If another port is to be used, it can be set for each command.
Peek()
Sends the MP_Peek (1) command.
Syntax
def Peek( self
, aAddress : int
, aLength : int
, aPort : Union[None, MPBusPort] = None
, aCommunicationType : Union[None, str, CommunicationTypes] = None
, aAcceptErrors : Union[None, List[int]] = None
, aLabel : Union[None, str] = None
) -> Tuple[int, List[int]]:
Arguments
aAddress : Memory address on device.
aLength : The length of read data from the given address.
aPort : See Common Function Parameters.
aCommunicationType : See MP Command Parameters.
aAcceptErrors : See Common Function Parameters..
aLabel : See Common Function Parameters..
Return Value
It returns according to the Function Return Values
Example
(resultCode, buffer) = mpbus.Peek(aAddress = 32769, aLength = 2, aLabel = 'Peek command');
# buffer = [0x12, 0x34]
# Log
# 2021.09.11 15.42.30.321 [E0000,W0000] OUTPUT Peek command [0x01800102]
# 2021.09.11 15.42.31.322 [E0000,W0000] INPUT Peek command [0x1234]
(resultCode, buffer) = mpbus.Peek(aAddress = 0x8003, aLength = 4, aLabel = 'Peek command');
# buffer = [0x00, 0x11, 0x22, 0x33]
# Log
# 2021.09.11 15.42.30.321 [E0000,W0000] OUTPUT Peek command [0x01800303]
# 2021.09.11 15.42.31.322 [E0000,W0000] INPUT Peek command [0x00112233]
Poke()
Sends the MP_Poke (2) command.
def Poke( self
, aAddress : int
, aBlock : List[int]
, aPort : Union[None, MPBusPort] = None
, aCommunicationType : Union[None, str, CommunicationTypes] = None
, aAcceptErrors : Union[None, List[int]] = None
, aLabel : Union[None, str] = None
) -> Tuple[int, List[int]]:
Arguments
aAddress : Memory address on the device.
aBlock : The block for writing to the given address.
aPort : See Common Function Parameters.
aCommunicationType : See MP Command Parameters.
aAcceptErrors : See Common Function Parameters.
aLabel : See Common Function Parameters.
Return Value
It returns according to the Function Return Values. The second value is always an empty list.
Example
(resultCode, buffer) = mpbus.Poke( aAddress = 32769
, aBlock = [0x12, 0x34] );
# Log
# 2021.09.11 15.42.30.700 [E0000,W0000] OUTPUT Poke [0x0280011234]
# 2021.09.11 15.42.31.835 [E0000,W0000] INPUT Poke []
(resultCode, buffer) = mpbus.Poke( aAddress = 32769
, aBlock = [0x11, 0x12, 0x13, 0x14]
, aLabel = 'Poke command' );
# Log
# 2021.09.11 15.42.30.700 [E0000,W0000] OUTPUT Poke command [0x02800111121314]
# 2021.09.11 15.42.31.835 [E0000,W0000] INPUT Poke command []
GetData()
Sends the MP_Get_Data (111) command.
def GetData( self
, aModelId : int
, aAuto : bool = True
, aPort : Union[None, MPBusPort] = None
, aCommunicationType : Union[None, str, CommunicationTypes] = None
, aAcceptErrors : Union[None, List[int]] = None
, aLabel : Union[None, str] = None
) -> Tuple[int, List[int]]:
Arguments
aModelId : Model identifier on the device.
aAuto : If the value is True, then GetNextBlock will be called automatically. (default: True)
aPort : See Common Function Parameters.
aCommunicationType : See MP Command Parameters.
aAcceptErrors : See Common Function Parameters.
aLabel : See Common Function Parameters.
Return Value
It returns according to the Function Return Values.
When the call was a success and the length of payload is more than 4 and aAuto parameter is ‘False’, then additional call(s) of GetNextBlock function is/are required. The last byte of the data list contains the amount of remaining bytes. Use it for calculate the count of GetNextBlock calls.
Example
(resultCode, buffer) = mpbus.GetData(aModelId = 17, aLabel = 'Get Model: 17' );
# Log
# 2021.09.11 15.42.30.700 [E0000,W0000] OUTPUT Get Model: 17 [0x386f00111056]
# 2021.09.11 15.42.31.835 [E0000,W0000] INPUT Get Model: 17 [0x5d0102030402dc87]
(resultCode, buffer) = mpbus.GetData(aModelId = 13, aLabel = 'Get Model: 13' );
# Log
# 2021.09.11 15.42.30.700 [E0000,W0000] OUTPUT Get Model: 13 [0x386f000d90ca]
# 2021.09.11 15.42.31.835 [E0000,W0000] INPUT Get Model: 13 [0x2d138840f6]
GetNextBlock()
Sends the MP_Get_NextBlock(13) command.
def GetNextBlock( self
, aBlockNr : int
, aPort : Union[None, MPBusPort] = None
, aCommunicationType : Union[None, str, CommunicationTypes] = None
, aAcceptErrors : Union[None, List[int]] = None
, aLabel : Union[None, str] = None
) -> Tuple[int, List[int]]:
Arguments
aBlockNr : The identifier of next block. 0 < aBlockNr < 256
aPort : See Common Function Parameters.
aCommunicationType : See MP Command Parameters.
aAcceptErrors : See Common Function Parameters.
aLabel : See Common Function Parameters.
Return Value
It returns according to the Function Return Values. If length of payload is 7, then this function needs to call again with incremented block identifier.
Example
# Get the value of model with id 12 (returns with a length of maximum four bytes)
(resultCode, block) = mpbus.GetData(aModelId = 12, aAuto = False);
if (type(block) is list) and (len(block) > 4) :
blockNr = 1;
countOfRemainingBytes = block[4];
block = block[:4];
while countOfRemainingBytes > 0 :
# The next block, if it has more data
(resultCode, data) = mpbus.GetNextBlock(aBlockNr = blockNr);
if (type(data) is list) :
countOfRemainingBytes -= len(data);
block += data;
else:
break;
blockNr += 1;
SetData()
Sends the MP_Set_Data (110) command.
def SetData( self
, aModelId : int
, aBuffer : List[int]
, aAuto : bool = True
, aPort : Union[None, MPBusPort] = None
, aCommunicationType : Union[None, str, CommunicationTypes] = None
, aAcceptErrors : Union[None, List[int]] = None
, aLabel : Union[None, str] = None
) -> Tuple[int, List[int]:
Arguments
aModelId : Model identifier on the device. (This number is two bytes long unsigned type.)
aBuffer : Value in byte buffer for the model. If the size of the block is more than 4 bytes and the aAuto is set to ‘True’ (default), then SetNextBlock will be called automatically.
aAuto : If the value is ‘True’ and the size of aBuffer is more than 4 bytes, then SetNextBlock will be called automatically. (default: True)
aPort : See Common Function Parameters.
aCommunicationType : See MP Command Parameters.
aAcceptErrors : See Common Function Parameters.
aLabel : See Common Function Parameters.
Return Value
It returns according to the Function Return Values. The second value is always an empty list.
Example
(resultCode, buffer) = mpbus.SetData(aModelId = 12, aBuffer = data, aLabel = "Set Model: 12" );
# Log
# 2021.09.11 15.42.30.700 [E0000,W0000] OUTPUT Set Model: 12 [0x586e000c012cccdb]
# 2021.09.11 15.42.31.835 [E0000,W0000] INPUT Set Model: 12 [0x0d808d]
(resultCode, buffer) = mpbus.SetData(aModelId = 18, aBuffer = data, aLabel = "Set Model: 18" );
# Log
# 2021.09.11 15.42.30.700 [E0000,W0000] OUTPUT Set Model: 18 [0x586e0012012cccc5]
# 2021.09.11 15.42.31.835 [E0000,W0000] INPUT Set Model: 18 [0x0d808d]
SetNextBlock()
Sends the MP_Set_NextBlock (112) command.
def SetNextBlock( self
, aBuffer : List[int]
, aBlockNr : int
, aPort : Union[None, MPBusPort] = None
, aCommunicationType : Union[None, str, CommunicationTypes] = None
, aAcceptErrors : Union[None, List[int]] = None
, aLabel : Union[None, str] = None
) -> Tuple[int, List[int]]:
Arguments
aBuffer : Value in byte buffer for the model. This command sends only the first 7 or less bytes from the buffer.
aBlockNr : Block identifier number in the range [1..256]
aPort : See Common Function Parameters.
aCommunicationType : See MP Command Parameters.
aAcceptErrors : See Common Function Parameters.
aLabel : See Common Function Parameters.
Return Value
It returns according to the Function Return Values. The second value is always an empty list.
Example
data = [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f ];
# Set the model with more then 4 bytes long data
(resultCode, buffer) = mpbus.SetData(aModelId = 12, aBuffer = data, aAuto = False);
if resultCode == 0 :
# The start of set is done properly
(resultCode, buffer) = mpbus.SetNextBlock(aBuffer = tester.ToSubBblock( aBuffer = data
, aOutLength = 4
, aStartIndex = 4 )
, aBlockNr = 1);
(resultCode, buffer) = mpbus.SetNextBlock( aBuffer = tester.ToSubBblock( aBuffer = data
, aOutLength = 4
, aStartIndex = 11 )
, aBlockNr = 2);
SendRaw()
This function allows for the user to send a raw MP command via MPBus.
def SendRaw( self
, aBuffer : List[int]
, aAnswerExpected : bool = True
, aPort : Union[None, MPBusPort] = None
, aCommunicationType : Union[None, str, CommunicationTypes] = None
, aAcceptErrors : Union[None, List[int]] = None
, aLabel : Union[None, str] = None
) -> Tuple[int, List[int]]:
Arguments
aBuffer : It contains the whole MP command to be sent out.
aAnswerExpected : Answer is expected for the command or not. If it is ‘True’ (default), then the command waits for the answer, otherwise it will not.
aPort : See Common Function Parameters.
aCommunicationType : See MP Command Parameters. This parameter has no effect, the communication type is determined by the contents of aBuffer.
aAcceptErrors : See Common Function Parameters.
aLabel : See Common Function Parameters.
Return Value
It returns according to the Function Return Values. If the aAnswerExpected attribute is ‘False’, then the second value is always an empty list.
Example
(resultCode, buffer) = mpbus.SendRaw(
aBuffer = [0x78, 0x3D, 0x00, 0x00, 0x01, 0xF4, 0x03, 0xE8, 0x32, 0x69]
, aAnswerExpected = False
, aLabel = "Custom: MP_Set_Min_Mid_Max" );
# Log
# 2021.05.04 11:51:37.141 [E0009,W0000] OUTPUT Custom: MP_Set_Min_Mid_Max [0x783d000001f403e83269]
# 2021.05.04 11:51:37.238 [E0009,W0000] INPUT Custom: MP_Set_Min_Mid_Max [0x0d808d]
(resultCode, buffer) = mpbus.SendRaw( aBuffer = [0x18, 0x3B, 0x80, 0xA3]
, aAnswerExpected = True
, aLabel = "Custom: MP_Get_Min_Mid_Max" );
# Log
# 2021.05.04 11:51:37.392 [E0009,W0000] OUTPUT Custom: MP_Get_Min_Mid_Max [0x183b80a3]
# 2021.05.04 11:51:37.505 [E0009,W0000] INPUT Custom: MP_Get_Min_Mid_Max [0x6d000001f403e83241]
ColdStart()
Sends the MP_ColdStart (67) command.
def ColdStart( self
, aPort : Union[None, MPBusPort] = None
, aCommunicationType : Union[None, str, CommunicationTypes] = None
, aAcceptErrors : Union[None, List[int]] = None
, aLabel : Union[None, str] = None
) -> Tuple[int, List[int]]:
Arguments
aPort : See Common Function Parameters.
aCommunicationType : See MP Command Parameters.
aAcceptErrors : See Common Function Parameters.
aLabel : See Common Function Parameters.
Return Value
It returns according to the Function Return Values. The second value is always an empty list.
Example
(resultCode, buffer) = mpbus.ColdStart( aAcceptErrors = [ 1111 ] );
# MP Command not known by slave 11
# Log
# 2021.05.06 14:06:43.022 [E0000,W0000] OUTPUT ColdStart [0x184380db]
# 2021.05.06 14:06:43.116 [E0000,W0000] INPUT ColdStart [0x9d0bc056]
# 2021.05.06 14:06:43.117 [E0000,W0000] ERROR ColdStart (1111) Command not known by the slave
GetFirmware()
Sends the MP_Get_Fimrware (82) command.
def GetFirmware( self
, aPort : Union[None, MPBusPort] = None
, aCommunicationType : Union[None, str, CommunicationTypes] = None
, aAcceptErrors : Union[None, List[int]] = None
, aLabel : Union[None, str] = None
) -> Tuple[int, List[int]]:
Arguments
aPort : See Common Function Parameters.
aCommunicationType : See MP Command Parameters.
aAcceptErrors : See Common Function Parameters.
aLabel : See Common Function Parameters.
Return Value
It returns according to the Function Return Values. The second value is the bytes of firmware version.
Example
(resultCode, buffer) = mpbus.GetFirmware( aLabel = 'Get Firmware Info' );
# Log
# 2021.05.06 14:06:43.887 [E0000,W0000] OUTPUT Get Firmware Info [0x285202c0b8]
# 2021.05.06 14:06:43.978 [E0000,W0000] INPUT Get Firmware Info [0x5d10010100123c63]
SetInfoField()
Sends the MP_Set_Infofield (52) command.
Syntax
def SetInfoField( self
, aBlockNr : int
, aBuffer : List[int]
, aPort : Union[None, MPBusPort] = None
, aCommunicationType : Union[None, str, CommunicationTypes] = None
, aAcceptErrors : Union[None, List[int]] = None
, aLabel : Union[None, str] = None
) -> Tuple[int, List[int]]:
Arguments
aBlockNr : Block identifier [0-7].
aBuffer : Data to be sent out. (Limited to a maximum of 5 bytes, the other bytes will be truncated)
aPort : See Common Function Parameters.
aCommunicationType : See MP Command Parameters.
aAcceptErrors : See Common Function Parameters.
aLabel : See Common Function Parameters.
Return Value
It returns according to the Function Return Values. The second value is always an empty list.
Example
(resultCode, buffer) = mpbus.SetInfoField( aBlockNr = 0
, aBuffer = [ 0x00, 0x22, 0x00, 0x01, 0x11] );
# Log
# 2021.05.06 14:06:45.304 [E0000,W0000] OUTPUT SetInfoField [0x7834000022000111423c]
# 2021.05.06 14:06:45.400 [E0000,W0000] INPUT SetInfoField [0x0d808d]
GetInfoField()
Sends the MP_Get_Infofield (53) command.
Syntax
def GetInfoField( self
, aBlockNr : int
, aPort : Union[None, MPBusPort] = None
, aCommunicationType : Union[None, str, CommunicationTypes] = None
, aAcceptErrors : Union[None, List[int]] = None
, aLabel : Union[None, str] = None
) -> Tuple[int, List[int]]:
Arguments
aBlockNr : The block identifier number.
aPort : See Common Function Parameters.
aCommunicationType : See MP Command Parameters.
aAcceptErrors : See Common Function Parameters.
aLabel : See Common Function Parameters.
Return Value
It returns according to the Function Return Values.
Example
(resultCode, buffer) = mpbus.GetInfoField( aBlockNr = 0, aLabel = 'GetInfofield command' );
# Log
# 2021.05.06 14:06:47.480 [E0000,W0000] OUTPUT GetInfofield command [0x283500001d]
# 2021.05.06 14:06:47.540 [E0000,W0000] INPUT GetInfofield command [0x5d0022753011240f]
GenerateCommandBytes()
Creates a new custom command that can be sent later with the SendRaw function.
Syntax
def GenerateCommandBytes( self
, aCommandCode : int
, aParameters : Union[None, TypeByteBlock] = None
, aPort : Union[None, MPBusPort] = None
, aCommunicationType : Union[None, str, CommunicationTypes] = None
, aAcceptErrors : Union[None, List[int]] = None
, aLabel : Union[None, str] = None
) -> List[int]:
Arguments
aCommandCode : The code of the command to be created.
aParameters : MP parameters.
aPort : See Common Function Parameters. This parameter does not have an effect, use the default value.
aCommunicationType : See MP Command Parameters.
aAcceptErrors : See Common Function Parameters. This parameter has no effect.
aLabel : See Common Function Parameters.
Return Value
Returns the raw command bytes including the start and parity bytes. If any error occurs during command generation, then it returns an empty list.
Example
(result, newCommand) = mpbus.GenerateCommandBytes(aCommandCode = 111, aParameters = [0x00, 0x11]);
# Log:
# 2021.05.04 13:57:23.789 [E0000,W0000] INFO Command bytes generated [0x386F00111056]
(result, newCommand) = mpbus.GenerateCommandBytes( aCommandCode = 111
, aParameters = [0x00, 0x11]
, aCommunicationType = CommunicationTypes.MP1 );
# Log:
# 2021.05.04 13:57:23.789 [E0000,W0000] INFO Command bytes generated [0x386F00111056]
GetMPAddress()
Sends the MP_Get_MP_Address (13) command.
def GetMPAddress( self
, aPort : Union[None, MPBusPort] = None
, aCommunicationType : Union[None, str, CommunicationTypes] = None
, aAcceptErrors : Union[None, List[int]] = None
, aLabel : Union[None, str] = None
) -> Tuple[int, List[int]]:
Arguments
aPort : See Common Function Parameters.
aCommunicationType : See MP Command Parameters.
aAcceptErrors : See Common Function Parameters.
aLabel : See Common Function Parameters.
Return Value
It returns according to the Function Return Values.
Example
(resultCode, address) = mpbus.GetMPAddress();
# Log
# 2021.05.15 15:10:05.570 [E0000,W0000] OUTPUT GetMPAddress [0x180d8095]
# 2021.05.15 15:10:05.633 [E0000,W0000] INPUT GetMPAddress [0x1d088095]
if len(address) > 0 :
tester.Log(LogLevels.INFO, "MP address : " + str(address[0]));
# Log
# 2021.05.15 15:10:05.633 [E0000,W0000] INFO MP address : 0x08
SetMPAddress()
Sends the MP_Set_MP_Address (38) command.
def SetMPAddress( self
, aNewAddress : int
, aYear : int
, aWeek : int
, aWeekDay : int
, aRunNumber : int
, aTestStation : int
, aPort : Union[None, MPBusPort] = None
, aCommunicationType : Union[None, str, CommunicationTypes] = None
, aAcceptErrors : Union[None, List[int]] = None
, aLabel : Union[None, str] = None
) -> Tuple[int, List[int]]:
Arguments
aNewAddress : New MP Address in the range [1..16]
aYear : Last two digits of year. (e.g: 2016 -> 16)
aWeek : Week of the year.
aWeekDay : Number of day of week.
aTestStation : Identifier of test station.
aRunNumber : The run number for serial.
aPort : See Common Function Parameters.
aCommunicationType : See MP Command Parameters.
aAcceptErrors : See Common Function Parameters.
aLabel : See Common Function Parameters.
Return Value
It returns according to the Function Return Values. The second value is always an empty list.
Example
(error, buffer) = mpbus.SetMPAddress( aNewAddress = CommunicationTypes.MP8
, aYear = 11
, aWeek = 23
, aWeekDay = 3
, aRunNumber = 2
, aTestStation = 27);
# Log
# 2021.05.15 15:31:36.228 [E0000,W0000] OUTPUT SetMPAddress [0x78260b1703021b00267e]
# 2021.05.15 15:31:36.320 [E0000,W0000] INPUT SetMPAddress [0x0d808d]
GetState()
Sends the MP_Get_State (10) command.
def GetState( self
, aPort : Union[None, MPBusPort] = None
, aCommunicationType : Union[None, str, CommunicationTypes] = None
, aAcceptErrors : Union[None, List[int]] = None
, aLabel : Union[None, str] = None
) -> Tuple[int, List[int]]:
Arguments
aPort : See Common Function Parameters.
aCommunicationType : See Common Function Parameters.
aAcceptErrors : See Common Function Parameters.
aLabel : See Common Function Parameters.
Return Value
It returns according to the Function Return Values.
Example
(resultCode, state) = mpbus.GetState();
# Log
# 2021.05.18 12:07:41.163 [E0000,W0000] OUTPUT GetState [0x180a0012]
# 2021.05.18 12:07:41.259 [E0000,W0000] INPUT GetState [0x7d33449856001520c839]
SetForcedControl()
Sends the MP_Set_Forced_Control (14) command.
def SetForcedControl( self
, aForceOperation : int
, aPort : Union[None, MPBusPort] = None
, aCommunicationType : Union[None, str, CommunicationTypes] = None
, aAcceptErrors : Union[None, List[int]] = None
, aLabel : Union[None, str] = None
) -> Tuple[int, List[int]]:
Arguments
aForceOperation : Identifier of forced operation.
aPort : See Common Function Parameters.
aCommunicationType : See Common Function Parameters.
aAcceptErrors : See Common Function Parameters.
aLabel : See Common Function Parameters.
Return Value
It returns according to the Function Return Values. The second value is always an empty list.
Example
(error, buffer) = mpbus.SetForcedControl(aTestStation = 2);
# Log
# 2021.05.18 12:07:41.038 [E0000,W0000] OUTPUT SetForcedControl [0x280e02c0e4]
# 2021.05.18 12:07:41.131 [E0000,W0000] INPUT SetForcedControl [0x0d808d]
GetRelative()
Sends the MP_Get_Relative (41) command.
def GetRelative( self
, aPort : Union[None, MPBusPort] = None
, aCommunicationType : Union[None, str, CommunicationTypes] = None
, aAcceptErrors : Union[None, List[int]] = None
, aLabel : Union[None, str] = None
) -> Tuple[int, List[int]]:
Arguments
aPort : See Common Function Parameters.
aCommunicationType : See MP Command Parameters.
aAcceptErrors : See Common Function Parameters.
aLabel : See Common Function Parameters.
Return Value
It returns according to the Function Return Values. The length of the second value is 4 bytes long. The first two bytes contain the actual position and the second two bytes contain the setpoint.
Example
(resultCode, data) = mpbus.GetRelative();
# Log
# 2021.05.18 16:02:09.371 [E0000,W0000] OUTPUT GetRelative [0x182980b1]
# 2021.05.18 16:02:09.437 [E0000,W0000] INPUT GetRelative [0x4d131417181055]
if len(data) == 4 :
tester.Log( LogLevels.INFO
, "Actual : " + str(tester.ToNumber( aType = ConvertTypes.UINT16
, aBuffer = data)));
tester.Log( LogLevels.INFO
, "Set Point : " + str(tester.ToNumber( aType = ConvertTypes.UINT16
, aBuffer = data
, aStartIndex = 2)));
# Log
# 2021.05.18 16:02:09.444 [E0000,W0000] INFO Actual : 4884
# 2021.05.18 16:02:09.446 [E0000,W0000] INFO Set Point : 5912
SetRelative()
Sends the MP_Set_Relative (37) command.
def SetRelative( self
, aValue : int
, aPort : Union[None, MPBusPort] = None
, aCommunicationType : Union[None, str, CommunicationTypes] = None
, aAcceptErrors : Union[None, List[int]] = None
, aLabel : Union[None, str] = None
) -> Tuple[int, List[int]:
Arguments
aValue : The value to set.
aPort : See Common Function Parameters.
aCommunicationType : See MP Command Parameters.
aAcceptErrors : See Common Function Parameters.
aLabel : See Common Function Parameters.
Return Value
It returns according to the Function Return Values. The second value is always an empty list.
Example
(error, data) = mpbus.SetRelative(aValue = 4500);
# Log
# 2021.05.18 16:02:09.243 [E0000,W0000] OUTPUT SetRelative [0x38251194b028]
# 2021.05.18 16:02:09.340 [E0000,W0000] INPUT SetRelative [0x0d808d]
Login()
Sends the MP_Login (78) command.
def Login( self
, aPassword : List[int]
, aPort : Union[None, MPBusPort] = None
, aCommunicationType : Union[None, str, CommunicationTypes] = None
, aAcceptErrors : Union[None, List[int]] = None
, aLabel : Union[None, str] = None
) -> Tuple[int, List[int]]:
Arguments
aPassword : 4 bytes long byte list as a password.
aPort : See Common Function Parameters.
aCommunicationType : See MP Command Parameters.
aAcceptErrors : See Common Function Parameters.
aLabel : See Common Function Parameters.
Return Value
It returns according to the Function Return Values. The second value is always an empty list. If the format of password is invalid it returns ERROR_PYT_ARGUMENT_ERROR.
Example
(result, data) = mpbus.Login(aPassword = [0xFB, 0x78, 0xFB, 0x79]);
# Log
# 2021.05.18 16:57:20.308 [E0000,W0000] OUTPUT Login [0x584efb78fb79d4c3]
# 2021.05.18 16:57:20.401 [E0000,W0000] INPUT Login [0x0d808d]
Logout()
Sends the MP_Logout (60) command.
def Logout( self
, aPort : Union[None, MPBusPort] = None
, aCommunicationType : Union[None, str, CommunicationTypes] = None
, aAcceptErrors : Union[None, List[int]] = None
, aLabel : Union[None, str] = None
) -> Tuple[int, List[int]]:
Arguments
aPort : See Common Function Parameters.
aCommunicationType : See MP Command Parameters.
aAcceptErrors : See Common Function Parameters.
aLabel : See Common Function Parameters.
Return Value
It returns according to the Function Return Values. The second value is always an empty list.
Example
(result, data) = mpbus.Logout();
# Log
# 2021.05.18 16:57:20.432 [E0000,W0000] OUTPUT Logout [0x183c0024]
# 2021.05.18 16:57:20.527 [E0000,W0000] INPUT Logout [0x0d808d]
SpecialFunction()
Sends the MP_SpecialFunction (102) command.
def SpecialFunction( self
, aFunction : int
, aPort : Union[None, MPBusPort] = None
, aCommunicationType : Union[None, str, CommunicationTypes] = None
, aAcceptErrors : Union[None, List[int]] = None
, aLabel : Union[None, str] = None
) -> Tuple[int, List[int]]:
Arguments
aFunction : Identifier number of the function.
aPort : See Common Function Parameters.
aCommunicationType : See MP Command Parameters.
aAcceptErrors : See Common Function Parameters.
aLabel : See Common Function Parameters.
Return Value
It returns according to the Function Return Values. The second value is always an empty list.
Example
(result, data) = mpbus.SpecialFunction(aFunction = 1);
# Log
# 2021.05.20 09:36:26.242 [E0000,W0000] OUTPUT SpecialFunction [0x28660180cf]
# 2021.05.20 09:36:26.336 [E0000,W0000] INPUT SpecialFunction [0x0d808d]
GetSummary()
Sends the MP_Get_Summary (118) command.
def GetSummary( self
, aPort : Union[None, MPBusPort] = None
, aCommunicationType : Union[None, str, CommunicationTypes] = None
, aAcceptErrors : Union[None, List[int]] = None
, aLabel : Union[None, str] = None
) -> Tuple[int, List[int]]:
Arguments
aPort : See Common Function Parameters.
aCommunicationType : See MP Command Parameters.
aAcceptErrors : See Common Function Parameters.
aLabel : See Common Function Parameters.
Return Value
It returns according to the Function Return Values.
Example
(resultCode, state) = mpbus.GetSummary();
if type(state) is list:
bits = tester.BytesToBits(state[0]);
if type(bits) is list:
if bits[1]:
tester.Log(LogLevels.INFO, "Data changed");
else:
tester.Log(LogLevels.INFO, "No data changed");
GetSeriesNo()
Sends the MP_Get_SeriesNo (50) command.
def GetSeriesNo( self
, aPort : Union[None, MPBusPort] = None
, aCommunicationType : Union[None, str, CommunicationTypes] = None
, aAcceptErrors : Union[None, List[int]] = None
, aLabel : Union[None, str] = None
) -> Tuple[int, List[int]]:
Arguments
aPort : See Common Function Parameters.
aCommunicationType : See MP Command Parameters.
aAcceptErrors : See Common Function Parameters.
aLabel : See Common Function Parameters.
Return Value
It returns according to the Function Return Values.
Example
(resultCode, seriesNo) = mpbus.GetSeriesNo();
# Log
# 2021.05.20 10:06:54.668 [E0000,W0000] OUTPUT GetSeriesNo [0x183280aa]
# 2021.05.20 10:06:54.760 [E0000,W0000] INPUT GetSeriesNo [0x7d565758595a5b5c4c6c]
if type(seriesNo) is list:
tester.LogBytes(aLogLevel = LogLevels.INFO, aTextPrefix = "Series Number:", aBytes = seriesNo);
# 2021.05.20 10:06:54.780 [E0000,W0000] INFO Series Number: [0x565758595a5b5c]a5b5c]
Class MPSerialPort
Class representation of an MP-Bus serial port, implements MBPort.
Properties
communication_type
The communication type used on this port.
Example
port.communication_type = CommunicationTypes.MP2;
# Log
# 2021.12.07 13:32:42.056 [E0000,W0000] DEBUG 'port0' - 'MP1' -> 'MP2'
port.communication_type = 33;
# Log
# 2021.12.07 15:32:42.058 [E0001,W0000] ERROR 'port0' - Invalid communication type '33'
retry_count
Number of retries used in MP communication. The property is read-only and is set by the constructor argument.
Methods
Constructor
Syntax
Arguments
aTester : An MBTester object.
aName : Identifier name for the port.
aDeviceId : Serial port identifier string. (example: “COM1”, “COM2”, etc.)
aCommunicationType : See MP Command Parameters
aRtsLevel : Set the RTS (Request To Send) level to high (True) or low (False). Simulation of bad serial communication in case of dev board.
aDtrLevel : Set the DTR (Data Terminal Ready) level to high (True) or low (False). Simulation of bad serial communication in case of dev board.
aBaudRate : The baud rate of the serial port. This value will be registered for the “aDeviceId”. Changing this value for the device is not possible by creating an another port. It can cause an error. The following baud rates are allowed: 1200, 9600, 38400. The default value is 1200. (See the constants of usable baudrates)
aRetryCount : The retry count during the communication. (default: 3)
Example
tester = MBTester();
bus1 = MPSerialPort( aTester = tester
, aName = "Port1"
, aDeviceId = "COM1"
, aCommunicationType = CommunicationTypes.MP1
, aBaudRate = MPBaudRates.B38400 );
# Log:
# 2021.02.11 13:57:23.789 INFO MP Port created ['Port1',0]
bus2 = MPSerialPort( aTester = tester
, aName = "Port2"
, aDeviceId = "COM1"
, aCommunicationType = CommunicationTypes.MP2);
# Log:
# 2021.02.11 13:57:23.790 FATAL_ERR Could not create port 'Port1' due to already defined.
bus3 = MPSerialPort( aTester = tester
, aName = "Port1"
, aDeviceId = "COM1"
, aCommunicationType = CommunicationTypes.MP3 );
# Log:
# 2021.02.11 13:57:23.790 FATAL_ERR Could not create port 'Port1' due to already defined.
bus4 = MPSerialPort( aTester = tester
, aName = "Port3"
, aDeviceId = "COM1"
, aCommunicationType = CommunicationTypes.MP4
, aBaudRate = MPBaudRates.BAUD_RATE_1200 );
# Log:
# 2021.02.11 13:57:23.795 ERROR Could not initialize serial port because it is already initialized ...
# ...with different baud rate ['COM1',1200/38400]