當前位置: 首頁>>代碼示例>>Python>>正文


Python makerbot_driver.Encoder類代碼示例

本文整理匯總了Python中makerbot_driver.Encoder的典型用法代碼示例。如果您正苦於以下問題:Python Encoder類的具體用法?Python Encoder怎麽用?Python Encoder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Encoder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_error_reporting

 def test_error_reporting(self):
   """Tests that StreamWriter records errors received correctly
   and stores those values in the TransmissionError Thrown.
   """
   expected_errors = [
       'CRCMismatchError',
       'CRCMismatchError',
       'CRCMismatchError',
       'GenericError',
       'GenericError',
       ]
   response_payload = bytearray()
   response_payload.append(constants.response_code_dict['CRC_MISMATCH'])
   for i in range(3):
     self.outputstream.write(Encoder.encode_payload(response_payload))
   response_payload = bytearray()
   response_payload.append(constants.response_code_dict['GENERIC_PACKET_ERROR'])
   for i in range(2):
     self.outputstream.write(Encoder.encode_payload(response_payload))
   self.outputstream.seek(0)
   payload = 'asdf'
   try:
     self.w.send_command(payload) 
   except errors.TransmissionError as e:
     self.assertEqual(expected_errors, e.value)
開發者ID:ricberw,項目名稱:s3g,代碼行數:25,代碼來源:pi_test_StreamWriter.py

示例2: test_build_and_send_action_payload

  def test_build_and_send_action_payload(self):
    command = constants.host_action_command_dict['QUEUE_EXTENDED_POINT_NEW']
    point = [1, 2, 3, 4, 5]
    duration = 42
    relativeAxes = 0
    expected_payload = struct.pack(
      '<BiiiiiIB',
      command,
      point[0], point[1], point[2], point[3], point[4],
      duration,
      relativeAxes
    )

    response_payload = bytearray()
    response_payload.append(constants.response_code_dict['SUCCESS'])
    self.outputstream.write(Encoder.encode_payload(response_payload))
    self.outputstream.seek(0)

    payload = struct.pack(
      '<BiiiiiIB',
      command,
      point[0], point[1], point[2], point[3], point[4],
      duration,
      relativeAxes,
    )
    self.w.send_action_payload(payload)
    self.assertEquals(Encoder.encode_payload(expected_payload), self.inputstream.getvalue())
開發者ID:ricberw,項目名稱:s3g,代碼行數:27,代碼來源:pi_test_StreamWriter.py

示例3: test_unpack_response

 def test_unpack_response(self):
   expected_data = [1,'a','b','c']
   b = bytearray()
   b.extend(Encoder.encode_uint32(1))
   for data in expected_data[1:]:
     b.append(data)
   data = Encoder.unpack_response('<Iccc',b)
   for i in range(0, len(expected_data)):
     assert(data[i] == expected_data[i])
開發者ID:dgs3,項目名稱:s3g,代碼行數:9,代碼來源:pi_test_Coding.py

示例4: test_unpack_response_with_string

 def test_unpack_response_with_string(self):
   expected_data = [1, 'a', 'b', 'c', 'ABCDE\x00']
   b = bytearray()
   b.extend(Encoder.encode_uint32(1))
   for data in expected_data[1:-1]:
     b.append(data)
   b.extend(expected_data[-1])
   data = Encoder.unpack_response_with_string('<Iccc',b)
   for expected, d in zip(expected_data, data):
     self.assertEqual(expected, d)
開發者ID:dgs3,項目名稱:s3g,代碼行數:10,代碼來源:pi_test_Coding.py

示例5: test_send_command

  def test_send_command(self):
    """
    Passing case: Preload the buffer with a correctly formatted expected response, and verigy that it works correctly
    """
    payload = 'abcde'

    response_payload = bytearray()
    response_payload.append(constants.response_code_dict['SUCCESS'])
    response_payload.extend('12345')
    self.outputstream.write(Encoder.encode_payload(response_payload))
    self.outputstream.seek(0)

    self.assertEqual(response_payload, self.w.send_command(payload))
    self.assertEqual(Encoder.encode_payload(payload), self.inputstream.getvalue())
開發者ID:ricberw,項目名稱:s3g,代碼行數:14,代碼來源:pi_test_StreamWriter.py

示例6: test_send_packet_timeout

  def test_send_packet_timeout(self):
    """
    Time out when no data is received. The input stream should have max_rety_count copies of the
    payload packet in it.
    """
    payload = 'abcde'
    packet = Encoder.encode_payload(payload)
    expected_packet = Encoder.encode_payload(payload)

    self.assertRaises(errors.TransmissionError,self.w.send_packet, packet)

    self.inputstream.seek(0)
    for i in range (0, constants.max_retry_count):
      for byte in expected_packet:
        self.assertEquals(byte, ord(self.inputstream.read(1)))
開發者ID:dgs3,項目名稱:s3g,代碼行數:15,代碼來源:test_StreamWriter.py

示例7: test_send_packet

    def test_send_packet(self):
        """
    Passing case: Preload the buffer with a correctly formatted expected response, and
    verify that it works correctly.
    """
        payload = "abcde"
        packet = Encoder.encode_payload(payload)
        response_payload = bytearray()
        response_payload.append(constants.response_code_dict["SUCCESS"])
        response_payload.extend("12345")
        self.outputstream.write(Encoder.encode_payload(response_payload))
        self.outputstream.seek(0)

        self.assertEquals(response_payload, self.w.send_packet(packet))
        self.assertEquals(Encoder.encode_payload(payload), self.inputstream.getvalue())
開發者ID:dgs3,項目名稱:s3g,代碼行數:15,代碼來源:pi_test_StreamWriter.py

示例8: test_build_and_send_query_payload

    def test_build_and_send_query_payload(self):
        cmd = constants.host_query_command_dict["GET_VERSION"]
        s3gVersion = 123
        botVersion = 456
        expected_payload = struct.pack("<bH", cmd, s3gVersion)

        response_payload = bytearray()
        response_payload.append(constants.response_code_dict["SUCCESS"])
        response_payload.extend(Encoder.encode_uint16(botVersion))
        self.outputstream.write(Encoder.encode_payload(response_payload))
        self.outputstream.seek(0)

        payload = struct.pack("<bH", cmd, s3gVersion)

        self.assertEquals(response_payload, self.w.send_query_payload(payload))
        self.assertEquals(Encoder.encode_payload(expected_payload), self.inputstream.getvalue())
開發者ID:dgs3,項目名稱:s3g,代碼行數:16,代碼來源:pi_test_StreamWriter.py

示例9: test_external_stop_works_precondition

 def test_external_stop_works_precondition(self):
   response_payload = bytearray()
   response_payload.append(constants.response_code_dict['SUCCESS'])
   self.outputstream.write(Encoder.encode_payload(response_payload))
   self.outputstream.seek(0)
   self.w.set_external_stop()
   self.assertRaises(errors.ExternalStopError, self.w.send_command, 'asdf')
開發者ID:ricberw,項目名稱:s3g,代碼行數:7,代碼來源:pi_test_StreamWriter.py

示例10: test_unpack_response_with_string_no_format

 def test_unpack_response_with_string_no_format(self):
   expected_string = 'abcde\x00'
   b = bytearray()
   b.extend(expected_string)
   data = Encoder.unpack_response_with_string('',b)
   assert(len(data) == 1)
   assert data[0] == expected_string
開發者ID:dgs3,項目名稱:s3g,代碼行數:7,代碼來源:pi_test_Coding.py

示例11: test_build_and_send_query_payload_with_null_terminated_string

    def test_build_and_send_query_payload_with_null_terminated_string(self):
        cmd = constants.host_query_command_dict["GET_NEXT_FILENAME"]
        flag = 0x01
        payload = struct.pack("<BB", cmd, flag)
        filename = "asdf\x00"

        response_payload = bytearray()
        response_payload.append(constants.response_code_dict["SUCCESS"])
        response_payload.append(constants.sd_error_dict["SUCCESS"])
        response_payload.extend(filename)
        self.outputstream.write(Encoder.encode_payload(response_payload))
        self.outputstream.seek(0)

        payload = struct.pack("<bb", cmd, flag)
        self.assertEqual(response_payload, self.w.send_query_payload(payload))
        self.assertEqual(Encoder.encode_payload(payload), self.inputstream.getvalue())
開發者ID:dgs3,項目名稱:s3g,代碼行數:16,代碼來源:pi_test_StreamWriter.py

示例12: test_decode_uint16_bytearray

 def test_decode_uint16_bytearray(self):
   byteArrayCases = [
     [0,       bytearray('\x00\x00')],
     [32767,   bytearray('\xff\x7f')],
     [65535,   bytearray('\xff\xff')],
   ]
   for case in byteArrayCases:
     self.assertEqual(Encoder.decode_uint16(case[1]), case[0])
開發者ID:dgs3,項目名稱:s3g,代碼行數:8,代碼來源:pi_test_Coding.py

示例13: test_decode_uint16

 def test_decode_uint16(self):
   cases = [
     [0,       '\x00\x00'],
     [32767,   '\xFF\x7F'],
     [65535,   '\xFF\xFF'],
   ]
   for case in cases:
     self.assertEqual(Encoder.decode_uint16(case[1]), case[0])
開發者ID:dgs3,項目名稱:s3g,代碼行數:8,代碼來源:pi_test_Coding.py

示例14: test_decode_bitfield

 def test_decode_bitfield(self):
   cases = [
     [[True for i in range(8)], 255],
     [[False for i in range(8)], 0],
     [[True, False, True, False, True, False, True, False], 85],
     ]
   for case in cases:
     self.assertEqual(case[0], Encoder.decode_bitfield(case[1]))
開發者ID:dgs3,項目名稱:s3g,代碼行數:8,代碼來源:pi_test_Coding.py

示例15: test_encode_uint16

 def test_encode_uint16(self):
   cases = [
     [0,       '\x00\x00'],
     [32767,   '\xFF\x7F'],
     [65535,   '\xFF\xFF'],
   ]
   for case in cases:
     assert Encoder.encode_uint16(case[0]) == case[1]
開發者ID:dgs3,項目名稱:s3g,代碼行數:8,代碼來源:pi_test_Coding.py


注:本文中的makerbot_driver.Encoder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。