1

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.

Kwonil
  • 69
  • 8
  • 1
    First rule of serial communication is to configure both ends to the same settings. You only mention how one end is configured. Why assume the other end is the same? *"I expect the output ..."* -- *"Output"* is relative to its source; when you neglect to mention the source, the statement becomes ambiguous. In this case "response" would be a better word choice for the data *received* from this mystery device. BTW evaluation of *"weird characters"* is simpler by examining the raw data instead of the ASCII translations. E.G. log the session data, then review the log file in a hex editor. – sawdust May 27 '21 at 07:41
  • @sawdust I appreciate your comment with detailed explanation. I am sorry to have confused you by using the ambiguous word. I am new to serial communication, I have tried to use the appropriate terminology as much as I can, but I haven't been able to. Now I am trying to understand and follow your comment. Reading your comment I feel I have to provide more information, including the setting of the other end (If my understanding is correct, this is the source). – Kwonil May 27 '21 at 09:07
  • My first question here is what is "the setting" you are mentioning to? Do you mean the baud rate, parity, and stop bits? If so, I followed the configuration of the device (9600 baud 8 N 1) when I get the response from the device with minicom, picocom, and pyserial. The second question is how to "log the session data"? If there is any software or command for this, I would appreciate if you could point me to the right way to do this. – Kwonil May 27 '21 at 09:07
  • 1
    *"Do you mean the baud rate, parity, and stop bits?"* -- Yes, as well as frame (aka character) size and flow-control (hardware or software or none). **Minicom** has a logging capability, aka "capture". Did you notice that after **minicom** starts up, it displays the line `Press CTRL-A Z for help on special keys`? – sawdust May 27 '21 at 22:00
  • 1
    You need to ensure you do not have a hardware issue. Number one concern is that the ground connection of the serial link is secure, i.e. the 3rd wire besides RxD & TxD (plus optional HW flow control). Any chance of EMI, e.g. nearby sources of RF)? Long cable? Crappy cable or connections? Cable is coiled? Have you tried testing on a different host computer with different cable and another mystery device? – sawdust May 27 '21 at 22:20
  • I really appreciate your comments. From your comment I was able to get valuable and helpful hints mostly regarding the hardware part. There was a non-twisted and non-shielded cable. There was also no ground cable. Potential noise sources may be the RFs from nearby instruments. I have two different sets with the same hardware/software configurations. Let me try to figure it out! Many thanks. – Kwonil May 28 '21 at 00:42

0 Answers0