简体   繁体   中英

RS232 with raspberry pi

My issue is to make a serial communication between raspberry pi and another hardware. The recommended connection for this hardware is as shown on the manual, I have to connect, RX, TX, GND, RS, and CS.

But on raspberry pi we have only RX, TX so I connected RX and TX and The GNG of Pi to this hardware. I modified Pi's parameters as shown on the link : here

Then I maked a simple python program that initialize the communication, and send data. Here is the code : import serial,os port=serial.Serial("/dev/ttyAMA0",baudrate=9600) print ('port is ok') port.write('Command') rcv=port.read(10) print rcv

after running this code on pi, I got ('port is ok'), But the problem is that this hardware don't respond correctly to the command, and as respoce it gave me normally OK, but I got some extra caracter( non readable). Is that a problem of encoding? Can some one help about this?

您需要检查其他硬件上的波特率,或确保接收到的消息的长度=打印消息的长度。

In a serial communication, there are two important things to be careful :

  • The two devices have to work with the same baudrate IF the link is bidirectional.
  • When writing data on serial, you have to flush data just after the write(). refer to here for it. In a lot of case, flush isn't needed, but when two different devices have to communicate, it could unlock the comm'.

If it's not efficient, try to set up your other device with the same conf (no flow control, etc)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM