Python Forum
I need a serial device expert!
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I need a serial device expert!
#1
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:

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:
        continue
Data 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.
Reply


Messages In This Thread
I need a serial device expert! - by Caesars_10th - Dec-05-2018, 12:04 AM
RE: I need a serial device expert! - by Larz60+ - Dec-05-2018, 12:51 AM
RE: I need a serial device expert! - by Larz60+ - Dec-11-2018, 08:07 PM
RE: I need a serial device expert! - by Larz60+ - Dec-14-2018, 02:58 AM
RE: I need a serial device expert! - by Larz60+ - Dec-14-2018, 12:05 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  pyserial/serial "has no attribute 'Serial' " gowb0w 9 4,183 Aug-24-2023, 07:56 AM
Last Post: gowb0w
  How would you (as an python expert) make this code more efficient/simple coder_sw99 3 1,820 Feb-21-2022, 10:52 AM
Last Post: Gribouillis
  Reading UDP from external device without device software ikdemartijn 2 3,430 Dec-03-2019, 04:29 PM
Last Post: Larz60+
  Display device details i.e connected with more than one device shintonp 6 5,338 May-10-2017, 06:00 AM
Last Post: shintonp

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020