Dec-05-2018, 12:04 AM
Hello! I am very new to python and possibly just as new to information flow from devices to computers. The only thing I know is that everything is sent in 0's and 1's. What I don't know is how or where the information is altered into hex or text or numbers we see on the screen.
What I'm trying to to do is capture the data stream coming from a sensor over a RS232 to USB cable (serial). This stream is constantly sent by the device as it actively measures at 100 HZ. I have had some luck in recording the incoming data and even decoding it:
______________________
Code:
2018-12-04 16:59:17.806247 %RAWIMUSA,0,16425.970;0,16425.963510000,00250001,491,32,16,19,-13,24*1ac8f7bf
2018-12-04 16:59:17.807748 %RAWIMUSA,0,16425.980;0,16425.973518000,00250001,492,32,16,9,2,20*840e4396
2018-12-04 16:59:17.810751 %RAWIMUSA,0,16425.990;0,16425.983525000,00250001,491,32,16,24,11,11*f009e545
2018-12-04 16:59:17.971362
2018-12-04 16:59:17.991376
2018-12-04 16:59:18.011390
2018-12-04 16:59:18.031404
2018-12-04 16:59:18.051418
2018-12-04 16:59:18.071433
2018-12-04 16:59:18.091446
2018-12-04 16:59:18.111460
2018-12-04 16:59:18.131474
2018-12-04 16:59:18.151488
2018-12-04 16:59:18.171502
2018-12-04 16:59:18.194518 %RAWIMUSA,0,16426.030;0,16426.023556000,00250001,492,32,16,15,13,35*cf4498a9
2018-12-04 16:59:18.196019 %RAWIMUSA,0,16426.040;0,16426.033564000,00250002,490,32,16,12,-16,32*285c7481
2018-12-04 16:59:18.197520 %RAWIMUSA,0,16426.050;0,16426.043571000,00250001,492,32,16,26,21,23*fce60dbf
2018-12-04 16:59:18.199021 %RAWIMUSA,0,16426.060;0,16426.053579000,00250001,494,33,16,10,10,18*ecebcd5c
2018-12-04 16:59:18.201023 %RAWIMUSA,0,16426.070;0,16426.063586000,00250001,491,32,16,16,-6,32*948490d5
2018-12-04 16:59:18.203524 %RAWIMUSA,0,16426.080;0,16426.073594000,00250002,491,32,16,15,27,28*b4abd72d
_______________________
However, you will notice that there is a significant 0.4 second jump between data points. This happens systematically and I can't figure out any way to improve it. The baudrate, bytesize, and stopbit values I know are correct. With my limited knowledge, I want to guess that its a buffering issue? But I don't know how any of that really works, which is why I am here looking for the experts!
I should note that I am using:
Windows 10
Python 3.7 with PyCharm 2018.2.4
Any ideas on how I can receive each message closer to the actual time steps of 0.01? without a 0.4 second jump.
What I'm trying to to do is capture the data stream coming from a sensor over a RS232 to USB cable (serial). This stream is constantly sent by the device as it actively measures at 100 HZ. I have had some luck in recording the incoming data and even decoding it:
______________________
Code:
import datetime import serial ser = serial.Serial() ser.port = 'COM3' ser.baudrate =9600#460800 ser.timeout = 0.02 ser.bytesize = 8 ser.stopbits = 1 ser.open() f = open('asciitest.txt', 'w') while 1: line = ser.readline() time = datetime.datetime.now() try: print(str(time) + ' ' + str(line.replace(b'\r\n', b'').decode('utf-8')) + '\n') f.write(str(time) + ' ' + str(line.replace(b'\r\n', b'').decode('utf-8')) + '\n') except UnicodeDecodeError: continueData Result:
2018-12-04 16:59:17.806247 %RAWIMUSA,0,16425.970;0,16425.963510000,00250001,491,32,16,19,-13,24*1ac8f7bf
2018-12-04 16:59:17.807748 %RAWIMUSA,0,16425.980;0,16425.973518000,00250001,492,32,16,9,2,20*840e4396
2018-12-04 16:59:17.810751 %RAWIMUSA,0,16425.990;0,16425.983525000,00250001,491,32,16,24,11,11*f009e545
2018-12-04 16:59:17.971362
2018-12-04 16:59:17.991376
2018-12-04 16:59:18.011390
2018-12-04 16:59:18.031404
2018-12-04 16:59:18.051418
2018-12-04 16:59:18.071433
2018-12-04 16:59:18.091446
2018-12-04 16:59:18.111460
2018-12-04 16:59:18.131474
2018-12-04 16:59:18.151488
2018-12-04 16:59:18.171502
2018-12-04 16:59:18.194518 %RAWIMUSA,0,16426.030;0,16426.023556000,00250001,492,32,16,15,13,35*cf4498a9
2018-12-04 16:59:18.196019 %RAWIMUSA,0,16426.040;0,16426.033564000,00250002,490,32,16,12,-16,32*285c7481
2018-12-04 16:59:18.197520 %RAWIMUSA,0,16426.050;0,16426.043571000,00250001,492,32,16,26,21,23*fce60dbf
2018-12-04 16:59:18.199021 %RAWIMUSA,0,16426.060;0,16426.053579000,00250001,494,33,16,10,10,18*ecebcd5c
2018-12-04 16:59:18.201023 %RAWIMUSA,0,16426.070;0,16426.063586000,00250001,491,32,16,16,-6,32*948490d5
2018-12-04 16:59:18.203524 %RAWIMUSA,0,16426.080;0,16426.073594000,00250002,491,32,16,15,27,28*b4abd72d
_______________________
However, you will notice that there is a significant 0.4 second jump between data points. This happens systematically and I can't figure out any way to improve it. The baudrate, bytesize, and stopbit values I know are correct. With my limited knowledge, I want to guess that its a buffering issue? But I don't know how any of that really works, which is why I am here looking for the experts!
I should note that I am using:
Windows 10
Python 3.7 with PyCharm 2018.2.4
Any ideas on how I can receive each message closer to the actual time steps of 0.01? without a 0.4 second jump.