How to use set_function_code method in localstack

Best Python code snippet using localstack_python

modbus_coder.py

Source:modbus_coder.py Github

copy

Full Screen

...37 def _set_request_mbap(self, slave, pdu_length, function_code):38 self._reset_request_mbap()39 self._request_mbap.next_transaction_id()40 self._request_mbap.set_unit_id(slave)41 self._request_mbap.set_function_code(function_code)42 self._request_mbap.set_pdu_length(pdu_length)43 def _reset_request_mbap(self):44 """Needs to keep tracking the transaction_id"""45 self._request_mbap.__init__()46 def _reset_response_mbap(self):47 """No need to track transaction_id here"""48 self._response_mbap = Mbap()49 def _reset_request_pdu(self):50 self._request_pdu = Pdu()51 def _reset_response_pdu(self):52 self._response_pdu = Pdu()53#-----------------------------------------------------------------------------------------------------------------------54class Pdu:55 _PDU_REQUEST_ENCODING = '>HH'56 _PDU_RESPONSE_ENCODING = '>B'57 def __init__(self):58 self.start_address = 059 self.num_registers = 060 self.data = ()61 def set_start_address(self, start_address):62 self.start_address = start_address63 def set_num_registers(self, num_registers):64 self.num_registers = num_registers65 def pack_bytes(self):66 return struct.pack(self._PDU_REQUEST_ENCODING, self.start_address, self.num_registers)67 def unpack_bytes(self, bytes, return_code):68 second_byte = struct.unpack(Pdu._PDU_RESPONSE_ENCODING, bytes[0:1])69 if return_code > 0x80:70 # the slave has returned an error71 exception_code = second_byte[0]72 raise ModbusError(exception_code)73 else:74 data_length = second_byte[0]75 data_encoding = '>' + (int(data_length / 2) * 'H')76 data = bytes[1:]77 if len(data) != data_length:78 # the byte count in the pdu is invalid79 raise ModbusInvalidResponseError("Byte count is %d while actual number of bytes is %d. " \80 % (data_length, len(data)))81 result = struct.unpack(data_encoding, data)82 return result83#-----------------------------------------------------------------------------------------------------------------------84class Mbap:85 _MBAP_ENCODING = '>HHHBB'86 transaction_id = 087 def __init__(self):88 self.protocol_id = 089 self.unit_id = 090 self.function_code = 091 self.pdu_length = 092 def next_transaction_id(self):93 Mbap.transaction_id = (Mbap.transaction_id + 1) % 25594 return Mbap.transaction_id95 def set_pdu_length(self, pdu_length):96 self.pdu_length = pdu_length97 def set_unit_id(self, unit_id):98 self.unit_id = unit_id99 def set_function_code(self, function_code):100 self.function_code = function_code101 def pack_bytes(self):102 return struct.pack(Mbap._MBAP_ENCODING, self.transaction_id, self.protocol_id, self.pdu_length + 2,103 self.unit_id, self.function_code)104 def unpack_bytes(self, bytes):105 (_, _, d_len, u_id, f_cd) = struct.unpack(Mbap._MBAP_ENCODING, bytes)106 self.set_pdu_length(d_len - 1)107 self.set_unit_id(u_id)...

Full Screen

Full Screen

test_ccsds_secondary_header.py

Source:test_ccsds_secondary_header.py Github

copy

Full Screen

...28 """29 Test CcsdsSecondaryCmdHeader class method: set_function_code & get_function_code30 Sets the function code field31 """32 assert secondary_header.set_function_code(2) is None33 assert secondary_header.get_function_code() == 234 with pytest.raises(TypeError):35 secondary_header.set_function_code(1.1)36 with pytest.raises(TypeError):37 secondary_header.set_function_code(-12.3)38 with pytest.raises(TypeError):39 secondary_header.set_function_code("15")40 with pytest.raises(TypeError):41 secondary_header.set_function_code([10])42 assert secondary_header.get_function_code() == 243 # test ("function_code", ctypes.c_uint8), overflow44 secondary_header.set_function_code(257)45 assert secondary_header.get_function_code != 25746def test_ccsdssecondarycmdheader_checksum(secondary_header):47 """48 Test CcsdsSecondaryCmdHeader class method: set_checksum & get_checksum49 Sets/Gets the checksum field50 """51 assert secondary_header.set_checksum(2) is None52 assert secondary_header.get_checksum() == 253 with pytest.raises(TypeError):54 secondary_header.set_checksum(5.2)55 with pytest.raises(TypeError):56 secondary_header.set_checksum(-111.3)57 with pytest.raises(TypeError):58 secondary_header.set_checksum("24")...

Full Screen

Full Screen

decoder.py

Source:decoder.py Github

copy

Full Screen

...27def set_opcode(opcode):28 global OPCODE29 OPCODE = opcode30 print('Set OPCODE to: {0}'.format(hex(opcode)))31def set_function_code():32 global OPFUNCTION33 OPFUNCTION = (OPCODE & 0xF0000000) >> 2834def set_coordinate_one():35 global OPCOORDINATE_ONE36 OPCOORDINATE_ONE = (OPCODE & 0x0FF00000) >> 2037def set_coordinate_two():38 global OPCOORDINATE_TWO39 OPCOORDINATE_TWO = (OPCODE & 0x000FF000) >> 1240def set_value():41 global OPVALUE42 OPVALUE = (OPCODE & 0x00000FF0) >> 443def instruction_AXY00000():44 pass45def instruction_BXYXY000():46 pass47def decode_opcode():48 # print(hex(op_func), hex(op_coordinate_1), hex(value))49 set_function_code()50 set_coordinate_one()51 set_coordinate_two()52 set_value()53 # if op_func == 0xA0000000:54 # pass55def display_op_status():56 print()57 print('OPCODE: ', hex(OPCODE))58 print('OPFUNCTION: ', hex(OPFUNCTION))59 print('OPCOORDINATE_ONE:', hex(OPCOORDINATE_ONE))60 print('OPCOORDINATE_TWO:', hex(OPCOORDINATE_TWO))61 print('OPVALUE: ', hex(OPVALUE))62 print()63set_opcode(0xa1234567)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful