本文整理汇总了Python中serial.to_bytes函数的典型用法代码示例。如果您正苦于以下问题:Python to_bytes函数的具体用法?Python to_bytes怎么用?Python to_bytes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了to_bytes函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: FunSerial
def FunSerial(USBPort,USBRate):
try:
#ser = serial.Serial("/dev/ttyAMA0", 115200, timeout=5)
#ser = serial.Serial("/dev/cu.usbserial-A700eGFx", 115200, timeout=1)
#ser = serial.Serial("/dev/cu.usbserial", 115200, timeout=1)
print '----------------------------------'
ser = serial.Serial(USBPort, USBRate, timeout=0.5)
ser.write(serial.to_bytes([0x80,0x00,0x00]))
data = ser.read(6)
#print(data)
print data.encode('hex')
ser.write(serial.to_bytes([0xc1,0x01,0x00]))
data = ser.read(5)
print data.encode('hex')
ser.write(serial.to_bytes([0xc1,0x02,0x00]))
data = ser.read(12)
print data.encode('hex')
ser.write(serial.to_bytes([0xc1,0x03,0x05,0x03,0xe4,0xc0,0x00,0x03]))
data = ser.read(5)
print data.encode('hex')
ser.write(serial.to_bytes([0xc1,0x06,0x00]))
data = ser.read(7)
print ("reciver:")
print data.encode('hex')
ser.close()
except serial.serialutil.SerialException:
print 'cannot open Serial Port'
开发者ID:iFrogLab,项目名称:IL-LORA1272,代码行数:30,代码来源:ap10-parameter.py
示例2: test_to_bytes
def test_to_bytes(self):
self.assertEqual(serial.to_bytes([1, 2, 3]), b'\x01\x02\x03')
self.assertEqual(serial.to_bytes(b'\x01\x02\x03'), b'\x01\x02\x03')
self.assertEqual(serial.to_bytes(bytearray([1,2,3])), b'\x01\x02\x03')
# unicode is not supported test. use decode() instead of u'' syntax to be
# compatible to Python 3.x < 3.4
self.assertRaises(TypeError, serial.to_bytes, b'hello'.decode('utf-8'))
开发者ID:pyserial,项目名称:pyserial,代码行数:7,代码来源:test_util.py
示例3: FunRX
def FunRX(ser):
global global_RXArray
global global_RXCmd
ser.write(serial.to_bytes([0xc1,0x03,0x05,0x03,0xe4,0xc0,0x00,0x03]))
data = ser.read(5)
print data.encode('hex')
time.sleep(0.1)
print ("reciver:")
while True:
ser.write(serial.to_bytes([0xc1,0x06,0x00]))
data = ser.read(3)
if len(data)>=2 :
len1=int(data[2].encode('hex'),16)
cmd = ser.read(1)
data2 = ser.read(len1-1)
CRC = ser.read(1)
isSame=numpy.array_equal(data2,global_RXArray)
#print (cmd,16)
if isSame == False or global_RXCmd!=cmd :
global_RXArray=data2
global_RXCmd=cmd
print data2.encode('hex')
if data2[0] == 0x71:
GPIO.output(7,True) ## Turn on GPIO pin 7
elif data2[0] == 0x70:
GPIO.output(7,False) ## Turn off GPIO pin 7
elif data2[0] == 0xb1:
GPIO.output(11,True) ## Turn on GPIO pin 7
elif data2[0] == 0xb0:
GPIO.output(11,False) ## Turn off GPIO pin 7
#tarray=['0']
#FunTX(ser,tarray)
else:
exit(2)
开发者ID:iFrogLab,项目名称:IL-LORA1272,代码行数:34,代码来源:ap15-LEDOnOff.py
示例4: FunBridge
def FunBridge(ser,serBridge):
global global_RXArray
global global_RXCmd
ser.write(serial.to_bytes([0xc1,0x03,0x05,0x03,0xe4,0xc0,0x00,0x03]))
data = ser.read(5)
print data.encode('hex')
time.sleep(0.1)
print ("reciver:")
while True:
ser.write(serial.to_bytes([0xc1,0x06,0x00]))
data = ser.read(3)
if len(data)>=2 :
len1=int(data[2].encode('hex'),16)
cmd = ser.read(1)
data2 = ser.read(len1-1)
CRC = ser.read(1)
isSame=numpy.array_equal(data2,global_RXArray)
#print (cmd,16)
if isSame == False or global_RXCmd!=cmd :
global_RXArray=data2
global_RXCmd=cmd
print ('Bridge data')
print data2.encode('HEX')
else:
exit(2)
开发者ID:iFrogLab,项目名称:IL-LORA1272,代码行数:25,代码来源:ap16-Bridge.py
示例5: FunSerial
def FunSerial(USBPort,USBRate,SendReceive,data_array):
try:
#ser = serial.Serial("/dev/ttyAMA0", 115200, timeout=5)
#ser = serial.Serial("/dev/cu.usbserial-A700eGFx", 115200, timeout=1)
#ser = serial.Serial("/dev/cu.usbserial", 115200, timeout=1)
print '----------------------------------'
ser = serial.Serial(USBPort, USBRate, timeout=0.5)
ser.write(serial.to_bytes([0x80,0x00,0x00]))
data = ser.read(6)
print data.encode('hex')
ser.write(serial.to_bytes([0xc1,0x01,0x00]))
data = ser.read(5)
print data.encode('hex')
#time.sleep(0.1)
ser.write(serial.to_bytes([0xc1,0x02,0x00]))
data = ser.read(12)
print data.encode('hex')
#time.sleep(0.1)
if SendReceive == 'R':
FunRX(ser)
else:
FunTX(ser,data_array)
ser.close()
except serial.serialutil.SerialException:
print 'cannot open Serial Port'
开发者ID:iFrogLab,项目名称:IL-LORA1272,代码行数:27,代码来源:ap15-LEDOnOff.py
示例6: FunTX
def FunTX(ser):
ser.write(serial.to_bytes([0xc1,0x03,0x05,0x02,0xe4,0xc0,0x00,0x03]))
data = ser.read(5)
print data.encode('hex')
ser.write(serial.to_bytes([0xc1,0x05,0x03,0x01,0x02,0x03]))
data = ser.read(5)
print data.encode('hex')
开发者ID:iFrogLab,项目名称:IL-LORA1272,代码行数:7,代码来源:ap11-SendReceive.py
示例7: test_alternate_eol
def test_alternate_eol(self):
"""Test readline with alternative eol settings (skipped for io based systems)"""
if hasattr(self.s, 'xreadlines'): # test if it is our FileLike base class
self.s.write(serial.to_bytes("no\rno\nyes\r\n"))
self.failUnlessEqual(
self.s.readline(eol=serial.to_bytes("\r\n")),
serial.to_bytes("no\rno\nyes\r\n"))
开发者ID:gustavovelascoh,项目名称:pyserial3,代码行数:7,代码来源:test_readline.py
示例8: test_readlines
def test_readlines(self):
"""Test readlines method"""
self.s.write(serial.to_bytes([0x31, 0x0a, 0x32, 0x0a, 0x33, 0x0a]))
self.failUnlessEqual(
self.s.readlines(),
[serial.to_bytes([0x31, 0x0a]), serial.to_bytes([0x32, 0x0a]), serial.to_bytes([0x33, 0x0a])]
)
开发者ID:gustavovelascoh,项目名称:pyserial3,代码行数:7,代码来源:test_readline.py
示例9: velCallback
def velCallback(self, Twist):
x_vel = Twist.linear.x
y_vel = Twist.linear.y
w_vel = Twist.angular.z
m_unit = []
m_unit.append(y_vel - x_vel + pi * w_vel * (self.a_ + self.b_))
m_unit.append(y_vel + x_vel - pi * w_vel * (-self.a_ + self.b_))
m_unit.append(y_vel - x_vel - pi * w_vel * (self.a_ + self.b_))
m_unit.append(y_vel + x_vel + pi * w_vel * (self.a_ + self.b_))
# m_unit.append( x_vel - y_vel + (4 / (3*pi)) * w_vel * (self.a_ + self.b_) ** 1/2)
# m_unit.append( x_vel + y_vel + (4 / pi) * w_vel * (self.a_ + self.b_) ** 1/2)
# m_unit.append( x_vel - y_vel - (4 / pi) * w_vel * (self.a_ + self.b_) ** 1/2)
# m_unit.append( x_vel + y_vel - (4 / (3*pi)) * w_vel * (self.a_ + self.b_) ** 1/2)
self.m1_target = int(127 + 60 * (m_unit[0]))
self.m2_target = int(127 + 60 * (m_unit[1]))
self.m3_target = int(127 + 60 * (m_unit[2]))
self.m4_target = int(127 + 60 * (m_unit[3]))
self.serial.write(serial.to_bytes([mini_target, m1_, self.m1_target]))
self.serial.write(serial.to_bytes([mini_target, m2_, self.m2_target]))
self.serial.write(serial.to_bytes([mini_target, m3_, self.m3_target]))
self.serial.write(serial.to_bytes([mini_target, m4_, self.m4_target]))
开发者ID:aubravo,项目名称:navigation,代码行数:26,代码来源:move_base_node.py
示例10: test_readlines
def test_readlines(self):
"""Test readlines method"""
self.s.write(serial.to_bytes([0x31, 0x0A, 0x32, 0x0A, 0x33, 0x0A]))
self.assertEqual(
self.s.readlines(),
[serial.to_bytes([0x31, 0x0A]), serial.to_bytes([0x32, 0x0A]), serial.to_bytes([0x33, 0x0A])],
)
开发者ID:aarauf,项目名称:pyserial,代码行数:7,代码来源:test_readline.py
示例11: test_readlines
def test_readlines(self):
"""Test readlines method"""
self.s.write(serial.to_bytes(b"1\n2\n3\n"))
self.assertEqual(
self.s.readlines(),
[serial.to_bytes(b"1\n"), serial.to_bytes(b"2\n"), serial.to_bytes(b"3\n")]
)
开发者ID:AeroEng43,项目名称:pyserial,代码行数:7,代码来源:test_readline.py
示例12: test_readlines
def test_readlines(self):
"""Test readlines method"""
self.s.write(serial.to_bytes("1\n2\n3\n"))
self.failUnlessEqual(
self.s.readlines(),
[serial.to_bytes("1\n"), serial.to_bytes("2\n"), serial.to_bytes("3\n")]
)
开发者ID:Abdelkrim,项目名称:makerbot_agent,代码行数:7,代码来源:test_readline.py
示例13: test_xreadlines
def test_xreadlines(self):
"""Test xreadlines method (skipped for io based systems)"""
if hasattr(self.s, "xreadlines"):
self.s.write(serial.to_bytes([0x31, 0x0A, 0x32, 0x0A, 0x33, 0x0A]))
self.assertEqual(
list(self.s.xreadlines()),
[serial.to_bytes([0x31, 0x0A]), serial.to_bytes([0x32, 0x0A]), serial.to_bytes([0x33, 0x0A])],
)
开发者ID:aarauf,项目名称:pyserial,代码行数:8,代码来源:test_readline.py
示例14: test_readline
def test_readline(self):
"""Test readline method"""
self.s.write(serial.to_bytes(b"1\n2\n3\n"))
self.assertEqual(self.s.readline(), serial.to_bytes(b"1\n"))
self.assertEqual(self.s.readline(), serial.to_bytes(b"2\n"))
self.assertEqual(self.s.readline(), serial.to_bytes(b"3\n"))
# this time we will get a timeout
self.assertEqual(self.s.readline(), serial.to_bytes(""))
开发者ID:AeroEng43,项目名称:pyserial,代码行数:8,代码来源:test_readline.py
示例15: test_xreadlines
def test_xreadlines(self):
"""Test xreadlines method (skipped for io based systems)"""
if hasattr(self.s, 'xreadlines'):
self.s.write(serial.to_bytes(b"1\n2\n3\n"))
self.assertEqual(
list(self.s),
[serial.to_bytes(b"1\n"), serial.to_bytes(b"2\n"), serial.to_bytes(b"3\n")]
)
开发者ID:AeroEng43,项目名称:pyserial,代码行数:8,代码来源:test_readline.py
示例16: test_xreadlines
def test_xreadlines(self):
"""Test xreadlines method (skipped for io based systems)"""
if hasattr(self.s, 'xreadlines'):
self.s.write(serial.to_bytes([0x31, 0x0a, 0x32, 0x0a, 0x33, 0x0a]))
self.failUnlessEqual(
list(self.s),
[serial.to_bytes([0x31, 0x0a]), serial.to_bytes([0x32, 0x0a]), serial.to_bytes([0x33, 0x0a])]
)
开发者ID:gustavovelascoh,项目名称:pyserial3,代码行数:8,代码来源:test_readline.py
示例17: test_readline
def test_readline(self):
"""Test readline method"""
self.s.write(serial.to_bytes([0x31, 0x0a, 0x32, 0x0a, 0x33, 0x0a]))
self.failUnlessEqual(self.s.readline(), serial.to_bytes([0x31, 0x0a]))
self.failUnlessEqual(self.s.readline(), serial.to_bytes([0x32, 0x0a]))
self.failUnlessEqual(self.s.readline(), serial.to_bytes([0x33, 0x0a]))
# this time we will get a timeout
self.failUnlessEqual(self.s.readline(), serial.to_bytes([]))
开发者ID:gustavovelascoh,项目名称:pyserial3,代码行数:8,代码来源:test_readline.py
示例18: test_for_in
def test_for_in(self):
"""Test for line in s"""
self.s.write(serial.to_bytes([0x31, 0x0A, 0x32, 0x0A, 0x33, 0x0A]))
lines = []
for line in self.s:
lines.append(line)
self.assertEqual(
lines, [serial.to_bytes([0x31, 0x0A]), serial.to_bytes([0x32, 0x0A]), serial.to_bytes([0x33, 0x0A])]
)
开发者ID:aarauf,项目名称:pyserial,代码行数:9,代码来源:test_readline.py
示例19: FunRX
def FunRX(ser):
ser.write(serial.to_bytes([0xc1,0x03,0x05,0x03,0xe4,0xc0,0x00,0x03]))
data = ser.read(5)
print data.encode('hex')
ser.write(serial.to_bytes([0xc1,0x06,0x00]))
data = ser.read(7)
print ("reciver:")
print data.encode('hex')
开发者ID:iFrogLab,项目名称:IL-LORA1272,代码行数:9,代码来源:ap11-SendReceive.py
示例20: test_for_in
def test_for_in(self):
"""Test for line in s"""
self.s.write(serial.to_bytes(b"1\n2\n3\n"))
lines = []
for line in self.s:
lines.append(line)
self.assertEqual(
lines,
[serial.to_bytes(b"1\n"), serial.to_bytes(b"2\n"), serial.to_bytes(b"3\n")]
)
开发者ID:AeroEng43,项目名称:pyserial,代码行数:10,代码来源:test_readline.py
注:本文中的serial.to_bytes函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论