Trouble trying to receive data from a serial port

那年仲夏 提交于 2019-12-06 15:38:42

All you can hope is the serial sends readable text. In which case your primary goal is to figure out the baud rate. Since you are a beginner, just install docklight (or maybe picocom or whatever working tool you have available). Try every baud rate starting from the highest (115200) [check notes below] and 8 data, going downwards and for every baud rate you check this way, mess around with stop bits and parity.

Alternatively (Thanks to Trevor for inspiration) you could run a tool to check for repeating 1s and 0s. For example if your stream is 110011001100000011110011 a good candidate is 115200/2. With 111000111000111000000111000111111111 a good candidate is 115200/3 etc

For the sake of completeness, the above method might be inconclusive, since the data "might" actually be 1100110011001100. Which would make little sense as this is a non efficient encoding, but coherently with the original problem, "we don't know" what the serial sends.

Now your hope is that you finally stumble upon the correct configuration and actually get readable text. If you do, you can move back to C# and set the correct configuration and resume your debug.

If you don't find any, this means the data is in binary format and we can have no certainty about the correct transmission configuration and the data content.

Your next bet would be saving a long enough log and open it with a hex editor.


Notes:

Even though you may receive some device info (e.g. baud rate 9600) the above steps are still recommended. Infact OP stumbled across wrong info whereas 9600 did not work, 115200 did.

115200 is considered the max for UART. But with proper interface you can reach 230400 and 460800... and possibly more. To make this answer future-proof, please verify what your interface maximum is as supported by both your hardware and serial driver.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!