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

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

问题描述

如果这是一个愚蠢的问题,请不要介意我。但我花了一些时间,试图找到答案,但我无法得到任何固体。也许这是一个硬件问题,但我想我会第一次尝试在这里。

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.

所以,这是怎么回事?难道串行通信只有一个单一的客户端和一台服务器之间的工作吗?有没有办法让多个客户端写入服务器?我AP preciate您的建议。

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

这是一个简单的方法,广泛使用在你想拥有通过一个串行端口连接到一台计算机的许多工业设备的设置。这种类型的布置也被称为多支路,因为建筑物周围一个电缆串与三通该抽头和支线到每个设备。

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.

<一个href=\"http://www.serialgear.com/USB-to-Serial-Adapters-%28RS232,-RS422-&-RS485%29-USB-COMi-TB.html\"相对=nofollow>例电脑USB适配器485接口
<一href=\"http://www.newark.com/exar/sp485rep-l/transceiver-rs485-5mbps-5v-dip/dp/24R0589?in_merch=Popular%20Drivers%20And%20Interfaces\"相对=nofollow>从e络盟样品RS485收发芯片

Example computer USB adapter with 485 interface Sample RS485 transceiver chip from Element14

所有设备挂在同一总线同时监听。使用的每一个命令之前,只是增加一个设备地址一个简单的通信协议。例如:

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 &LT; - 告诉Arduino的001以打开光

  • 013SETLIGHT0 &LT; - 告诉013来关灯

  • 001SETLIGHT1 <- tells Arduino "001" to turn on the light
  • 013SETLIGHT0 <- tells "013" to turn off the light

任意挂在电缆设备忽略不以他们的地址开始的命令。当一个设备响应,它prepends它的地址。

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


  • 001SETLIGHT1DONE &LT; - 从设备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天全站免登陆