Incomplete data or weird characters during serial communication

1.8k Views Asked by At

I am struggling with reading data from the device. I've searched for this issue with many different keywords, but couldn't find my case.

I am a beginner at serial communication. Thanks in advance for the help and advice from the experts.

The first issue with minicom (and picocom)

When I send the command (in this case, M;\r\n) multiple times, which is from the manual of the device, I expect the output something like +0000.00;+0000.00;+0000.00;+0000.00;+0694.09;+0694.10;+20.7;+000;+000.

However, what I received are the incomplete strings and the strings with some weird characters like ��ÚZڂ²Êʢ in minicom or ▒▒▒▒ in picocom. I can receive the complete data only few times. The picocom looks more stable but is still not complete.

OUTPUT

By minicom:

Welcome to minicom 2.7.1

OPTIONS: I18n
Compiled on May  6 2018, 08:30:41.
Port /dev/ttyS0, 02:19:52

Press CTRL-A Z for help on special keys

;;+0000.0ÿÛۃ��kþ;;+0000.00;+0000.00;+0694.10;+0694.12;+20.6;+000;�²ê¢~ꢊ�û+0694.12;+20.6;+000;+000
;;+0000.00;+0000.00;+0694.11;+0694.12;+20.6;+000;+000
;ëÿ;+0000.®ÿ»¿▒ÿ¿r��ÚZڂ²Êʢr��ÚZڒ�r²ÚZڂ��ÚZڂ��j¤ø;;+0000.00;+0000.00;+0694.11;+0694.12;+20.6;+000;+000
;;+0000.00;+0000.00;+0694.11;+0694.12;+20.6;+000;+000
;;+0000.0»û��û;;+0000.00;+0000.00;+0694.10;+0694.11;+20.6;+000;+000
;ëÿ;+0000.00;+0000.00;+0694.10;+0694.11;+20.6;+000;+000
;ëÿ;+0000.00;+0000.00;+0694.10;+0694.11;+20.6;+000;+00;;+0000.00;+0000.00;+0694.10;+0694.11;+20.6;+000;+000
;ëÿ;+0000.00;+0000.00;+0694.10;+0694.11;+20.6;+000;+000
;ëÿ;+0000.00;+0000.00;+0694.10;+0694.11;+20.6;+000;;+0000.00;+0000.00;+0694.10;+0694.11;+20.6;+000;+000
;;+0000.00;+0000.00;+0694.10;+0694.11;+20.6;+000;+000
;;+0000.00;+0000.00;+0694.10;+0694.11;+20.6;+000;+000
;;+0000.00;+0000.00;+0694.10;+0694.11;+20.6;+000;+000
;ë;+0000.00;+0000.00;+0694.10;+0694.11;+20.7;+000;+000
;;+0000.00;+0000.00;+0694.10;+0694.11;+20.7;+000;+000
ÿû+0694.10;+0694.11;+20.7;+000;+000
;;+0000.00;+0000.00;+0694.11;+0694.11;+20.7;+000;+000
;;+0000.00;+0000.00;+0694.10;+0694.11;+20.7;+000;+000
;;+0000.00;+0000.00;+0694.10;+0694.11;+20.7;+000;+000
;ëÿ;+0000.00;+0000.00;+0694.10;+0694.11;+20.7;+000;+000
;ëÿ;+0694.10;+0694.11;+20.7;+000;+000
ÿû/0000.00;+0000.00;+0694.10;+0694.11;+20.7;+000;+000
;;+0000.00;+0000.00;+0694.10;+0694.11;+20.8;+000;+000
;;+0000.00;+0000.00;+0694.10;+0694.11;+20.8;+000;+000
|;ëÿ;+0000.00;+0000.00;+0694.10;+0694.11;+20.8;+000;+000
»ÿ;+0000.0뻫»Ëˣsÿû+20.7;+000;+000
;;+0000.00;+0000.00;+0694.10;+0694.11;+20.7;+000;+000
;;+0000.00;+0000.00;+0694.10;+0694.11;+20.7;+000;+000
;;+0000.00;+0000.00;+0694.10;+0694.11;+20.7;+000;+000
;;+0000.00;+0000.00;+0694.10;+0694.11;+20.8;+000;+000
;;+0000.00;+0000.00;+0694.10;+0694.11;+20.7;+000;+000
;;+0000.00;+0000.00;+0694.10;+0694.11;+20.7;+000;+000
;ëÿ;+0000.00;+0000.00;+0694.10;+0694.11;+20.7;+000;+000
»+0694.10;+0694.11;+20.7;+000;+000
;;+0000.00;+0000.00;+0694.10;+0694.10;+20.7;+000;+000
;;+0000.00;+0000.00;+0694.10;+0694.10;+20.7;+000;+000
;ëÿ;+0000.00;+0000.00;+0694.10;+0694.10;+20.7;+000;+000
ÿû+0694.10;+0694.10;+20.7;+000;+000
°¹▒¿³ÏϿó��ÚZ�rºÚZڂ��ÚZڂ��j¤ø+0000.00;+0000.00;+0000.00;+0000.00;+0694.09;+0694.10;+20.7;+000;+000
;ëÿ;+0000.00;+0000.00;+0694.09;+0694.10;+20.7;+000»ÿ;+0000.0;;+0000.00;+0000.00;+0694.09;+0694.10;+20.7;+000;+000
;;+0000.00;+0000.00;+0694.09;+0694.10;+20.7;+000;+000
»+0694.09;+0694.10;+20.7;+000;+000
ÊþåÏ9¦▒%&L�7;+000;+000
+0000.00;+0000.00;+0000.00;+0000.00;+0694.09;+0694.10;+20.7;+000;+000
;ëÿ;+0000.00;+0000.00;+0694.09;+0694.10;+20.7;+000;+000
;;+0000.00;+0000.00;+0694.09;+0694.10;+20.7;+000;+000
;;+0000.00;+0000.00;+0694.09;+0694.10;+20.7;+000;+000
;;+0000.00;+0000.00;+0694.09;+0694.10;+20.7;+000;+000

By picocom:

picocom v3.1

port is        : /dev/ttyS0
flowcontrol    : none
baudrate is    : 9600
parity is      : none
databits are   : 8
stopbits are   : 1
escape is      : C-a
local echo is  : no
noinit is      : no
noreset is     : no
hangup is      : no
nolock is      : no
send_cmd is    : sz -vv
receive_cmd is : rz -vv -E
imap is        :
omap is        :
emap is        : crcrlf,delbs,
logfile is     : none
initstring     : none
exit_after is  : not set
exit is        : no

Type [C-a] [C-h] to see available commands
Terminal ready
;▒▒;+0000.00;+0000.00;+0694.08;+0694.10;+20.9;+000;+000
▒▒▒▒>00;+0694.08;+0694.10;+20.9;+000;+000
+0000.00;+0000.00;+0000.00;+0000.00;+0694.08;+0694.10;+20.9;+000;+000
+0000.00;+0000.00;+0000.00;+0000.00;+0694.08;+0694.10;+20.9;+000;+000
+0000.00;+0000.00;+0000.00;+0000.00;+0694.08;+0694.10;+20.9;+000;+000
+0000.00;+0000.00;+0000.00;+0000.00;+0694.07;+0694.10;+20.9;+000;+000
+0000.00;+0000.00;+0000.00;+0000.00;+0694.07;+0694.10;+20.9;+000;+000
+0000.00;+0000.00;+0000.00;+0000.00;+0694.07;+0694.10;+20.9;+000;+000
+0000.00;+0000.00;+0000.00;+0000.00;+0694.07;+0694.10;+20.9;+000;+000
+0000.00;+0000.00;+0000.00;+0000.00;+0694.07;+0694.10;+20.9;+000;+000
+0000.00;+0000.00;+0000.00;+0000.00;+0694.07;+0694.10;+20.9;+000;+000
+0000.00;+0000.00;+0000.00;+0000.00;+0694.07;+0694.10;+20.9;+000;+000
+0000.00;+0000.00;+0000.00;+0000.00;+0694.07;+0694.10;+20.9;+000;+000
+0000.00;+0000.00;+0000.00;+0000.00;+0694.07;+0694.10;+20.9;+000;+000
+0000.00;+0000.00;+0000.00;+0000.00;+0694.07;+0694.10;+20.9;+000;+000
+0000.00;+0000.00;+0000.00;+0000.00;+0694.07;+0694.10;+20.9;+000;+000
+0000.00;+0000.00;+0000.00;+0000.00;+0694.07;+0694.10;+20.9;+000;+000
+0000.00;+0000.00;+0000.00;+0000.00;+0694.07;+0694.10;+20.9;+000;+000
+0000.00;+0000.00;+0000.00;+0000.00;+0694.07;+0694.10;+20.9;+000;+000
+0000.00;+0000.00;+0000.00;+0000.00;+0694.07;+0694.10;+20.9;+000;+000
▒▒;+0000.00;+0000.00;+0694.08;+0694.10;+20.9;+000;+000
+0000.00▒ۣs▒▒▒▒20.9;+000;+000
+0000.00;+0000.00;+0000.00;+0000.00;+0694.07;+0694.10;+20.9;+000;+000
;▒▒;+0000.00;+0000.00;+0694.07;+0694.10;+20.9;+000;+000
▒▒;+0000.00;+0000.00;+0694.07;+0694.10;+20.9;+000;+000
;▒▒;+0000.00;+0000.00;+0694.07;+0694.10;+20.9;+000;+000
+0000.00;+0000.00;+0000.00;+0000.00;+0694.07;+0694.10;+20.9;+000;+000
+0000.00;+0000.00;+0000.00;+0000.00;+0694.07;+0694.10;+20.9;+000;+000
+0000.00;+0000.00;+0000.00;+0000.00;+0694.07;+0694.10;+20.9;+000;+000
+0000.00;+0000.00;+0000.00;+0000.00;+0694.07;+0694.10;+20.9;+000;+000
+0000.00;+0000.00;+0000.00;+0000.00;+0694.07;+0694.10;+20.9;+000;+000

The second issue with pyserial

I think the second issue may be related to the first issue. Ultimately I want to read the data from the device and log it by python (pyserial). This is the part of my code to read the data.

ser = serial.Serial(port='/dev/ttyS4', baudrate=9600)
ser.write(str.encode('M;\r'))
time.sleep(.2)
data = ser.readline()
data = data.decode("utf-8")
ser.close()

This code block runs every N seconds. Basically, this code works once it received the first data, but need unexpected long delay to receive the first complete data.

In other words, print(len(data)) always gives 0 before successfully receiving the first data. After waiting for a very long time with zero len(data), it receives the data well at some time (nonzero len(data) without any weird characters). Once it successfully received the data, the code continues to work fine without any problems as I want it to.

The problem here is that I have to wait for a very long time to receive a complete data string (even longer than 3 days (!)). Can anybody help me to resolve these issues? Thank you.

0

There are 0 best solutions below