python - How to write integers to port using PySerial -


I am trying to use data first serial port, COM1, PySerial.

  serial ser = serial.Serial (0) print (ser.name) ser.baudrate = 56700 ser.write ("abcdefg") ser.close ()   

should work to import. However, I have to send 28 bytes of integer continuously; <255 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 At P>, using a byte of data with each integer.

is trying:

  import serial ser = serial.Serial (0) print (ser.name) ser .broadrate = 56700 while true: ser.write ( 255 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 ser.close ()   

increases a syntax error .

How do you write an integer on a serial port if you send stars? How can I ensure that each number is sent as 8-bit?

, so any help would be appreciated.

Firstly, writing <123> 123 12 123 123 123 is not valid Python Syntax .

Create a list or a tupe with your integer: value = (1,2,3,4,5)

Now, Need to convert to a binary string that represents our values.

How do we do this here imported imported values ​​= (1,2,3,4,5) string = '' for value in I: String + = Straight Pock ('! B', I) Send Now String on Serial Port

Depending on how many bytes you want to use per number, Must have to pack. See document here:

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -