Hello,
I'm using a function ser.read (from PySerial) to read a sequence of 2000 bytes from a microcontroller. Two received bytes in a sequence are actually two bytes of uint16 data which are combined in python script (so in Python these sequence of 2000 bytes are combined into 1000 uint16_t data), but that's not important here.
I have a problem with understanding the received bytes of ser.read form the figure bellow (print(s))? Please click the the gray rectangle bellow to see the figure.
After printing out data received with ser.read with print(s) I can see strange printout. I would expect that each byte is in a form like \x04, but at the beginning I can see the form like \x04J, the listing also start with G\04F\...? So at the beginning of the figure I can see that there are three numbers or a strange (not hex) characters instead of two hex numbers (equals one byte)?
The code is here:
Ernest
I'm using a function ser.read (from PySerial) to read a sequence of 2000 bytes from a microcontroller. Two received bytes in a sequence are actually two bytes of uint16 data which are combined in python script (so in Python these sequence of 2000 bytes are combined into 1000 uint16_t data), but that's not important here.
I have a problem with understanding the received bytes of ser.read form the figure bellow (print(s))? Please click the the gray rectangle bellow to see the figure.
After printing out data received with ser.read with print(s) I can see strange printout. I would expect that each byte is in a form like \x04, but at the beginning I can see the form like \x04J, the listing also start with G\04F\...? So at the beginning of the figure I can see that there are three numbers or a strange (not hex) characters instead of two hex numbers (equals one byte)?
The code is here:
import serial import numpy as np import matplotlib.pyplot as plt import numpy as np from matplotlib.widgets import Slider, Button, RadioButtons from scipy.signal import savgol_filter import matplotlib.pyplot as plt from pylab import * import numpy as np ser = serial.Serial('COM13', 921600, timeout=None,parity=serial.PARITY_NONE) fig = plt.figure() while True: ser.flush() x = np.linspace(0, 1000, 1000) s = ser.read(2000) y1 = np.frombuffer(s, np.uint16) #y ... np array... plt.plot(x,y1,'-*',label='graf 1') plt.xlabel('TIME') plt.ylabel('ADC current') plt.title('Solenoid I/t') legend() plt.show() print(s) ser.close() # close portI will be grateful for any help
Ernest