一对一串行通讯 [英] Serial Communication one to one

查看:20
本文介绍了一对一串行通讯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果这是一个愚蠢的问题,请不要介意我.但我花了一些时间试图找到答案,但我找不到任何可靠的东西.也许这是一个硬件问题,但我想我会先在这里尝试.

If this is a stupid question, please don't mind me. But I spent some time trying to find the answer but I couldn't get anything solid. Maybe this is a hardware question, but I figured I'd try here first.

串行通信是否只能一对一进行?出现这种情况的原因是我有一个 arduino 板在其串行端口上侦听通信.我也有一个 python 脚本向端口提供字节.然而,每当我打开arduino的串口监视器时,与python脚本的连接都失败了.串行监视器还连接到串行端口以用于其小文本输入字段的通信.

Does Serial Communication only work one to one? The reason this came up is because I had an arduino board listening for communication on its serial port. I had a python script feed bytes to the port as well. However, whenever I opened up the arduino's serial monitor, the connection with the python script failed. The serial monitor also connects to the serial port for communication for its little text input field.

那是怎么回事?串行通信只能在单个客户端和单个服务器之间工作吗?有没有办法让多个客户端写入服务器?感谢您的建议.

So what's the deal? Does serial communication only work between a single client and a single server? Is there a way to get multiple clients writing to the server? I appreciate your suggestions.

推荐答案

与一台服务器(例如台式计算机)通信的多个客户端(例如 Arduinos)通常使用串行变体来完成:

Multiple clients (e.g. Arduinos) communicating with one server (e.g. a desktop computer) is commonly done with the serial variant:

RS-485

这是一种广泛用于工业环境的简单方法,您希望通过一个串行端口将多台设备连接到一台计算机.这种类型的布置也称为多点,因为一根电缆围绕建筑物串连,并带有 T 型接头,可将线路接入和接入每个设备.

This is a simple method widely used in industrial settings where you want to have many devices connected to one computer via one serial port. This type of arrangement is also called multi-drop, because one cable strings around a building with Tees that tap in and drop lines to each device.

用于此的硬件广泛可用.您可以购买为计算机提供硬件接口的 USB 串行适配器.以编程方式,该端口看起来就像一个 RS232 端口.对于 Arduino,您只需添加一个收发器芯片.存在大量串行收发器,例如

The hardware for this is widely available. You can buy USB serial adapters that provide the hardware interface for a computer. Programmatically the port looks just like an RS232 port. For the Arduino you would just add a transceiver chip. A sea of serial transceivers exists, e.g.

带有 485 接口的计算机 USB 适配器示例Element14 的 RS485 收发器芯片示例

所有设备都挂在同一条总线上同时侦听.使用的简单通信协议只是在每个命令之前添加一个设备地址.例如:

All the devices hang on the same bus listening at the same time. A simple communication protocol used is just add a device address before every command. For example:

  • 001SETLIGHT1 <- 告诉 Arduino001"打开灯
  • 013SETLIGHT0 <- 告诉013"关灯
  • 001SETLIGHT1 <- tells Arduino "001" to turn on the light
  • 013SETLIGHT0 <- tells "013" to turn off the light

任何挂在电缆上的设备都会忽略不以其地址开头的命令.当设备响应时,它会在其地址前面加上.

Any device hanging on the cable ignores commands that do not start with their address. When a device responds, it prepends its address.

  • 001SETLIGHT1DONE <- 来自设备001"的响应,该命令已接收并执行
  • 001SETLIGHT1DONE <- response from device "001" that the command has been received and executed

响应中的地址让接收方知道哪个设备正在通话.

The address in the response lets the receiving party know which device was talking.

这篇关于一对一串行通讯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆