通过COM端口在VB 6.0中与多个从站进行串行端口通信

问题描述:

我有一个要求,我需要通过串口设计主从通信的应用程序代码。我知道如何通过VB中的串口发送和读取数据

但是我不知道如何对逻辑进行编码,以便Master将通过通道抛出数据包

并且它将监听所有从站,但是数据将由特定从站实际接收,Slave ID是被所有其他奴隶提及并忽略。



我尝试过的事情:



我试过两个COM端口一个用于主服务器,另一个服务器用于从服务器但是没有服用多个从服务器。

I have a requirement where I need to design a code of an application for the Master Slave communication via serial ports.I got the idea how to send and read data via serial ports in VB
but i got stuck about how to code the logic so that Master will throw data packet over the channel
and it will be listening to all the slaves but data will be actually received by the particular slave which Slave ID is mentioned and ignored by the all other Slaves.

What I have tried:

I have tried for Two COM ports one for master and another for Slave but not getting for the multiple Slaves.

差不多,你不能 - 不是标准的COM端口。

COM端口通过RS232连接,这是一个硬件规范,它被定义为点对点,你需要的是多点。 PtP连接仅用于支持电缆两端的一个设备,有时您可以通过放置三个甚至四个设备来逃脱,您必须从软件中很好地控制硬件(您可以使用它)没有在VB)和你的物理COM端口的硬件供应商很好运。有些会起作用,有些则不起作用。你赢了;直到你尝试它们才知道 - 更糟糕的是,有些会在今天工作,但不会在明天工作......因为天气不同,一旦你超出规格范围就会影响电子产品。因为PSU很忙而且5V轨道有点低。因为......所有东西都在你无法控制之下。



你需要看一下多点硬件环境 - 我建议局域网或WLAN,因为它们已经存在在大多数环境中,或直接通过互联网/云。



但是使用标准COM端口?从一开始就注定要失败,除非服务器上有一个COM端口用于每个单独的从设备,这是一个物理组织的PITA。
Pretty much, you can't - not with standard COM ports.
COM ports connect via RS232, which is a hardware specification and it defined to be point-to-point where what you need is multidrop. PtP connections are only designed to support one device at each end of the cable, and while sometimes you can "get away" with putting three or even four devices on it, you have to have good control of your hardware from your software (which you don't have in VB) and a lot of luck with the hardware suppliers of your physical COM ports. Some will work, some won't. And you won;t know until you try them - and worse, some will work today, but not tomorrow ... because the weather is different, and that affects electronics once you go outside specification. Because the PSU is busy and the 5V rail is a little low. Because ... loads of things, all outside your control.

You need to look at a multidrop hardware environment - I'd suggest LAN or WLAN since they already exist in most environments, or go directly to via the internet / cloud.

But using standard COM ports? Doomed from the start unless you have one COM port on the server for each separate slave device, and that's a PITA to physically organise.


如果你真的想用Serialport做这个,你需要有一个RS232转RS485转换器。

RS485允许您有多个收听用户。所有与会者都听到了这个消息,但只有这个消息具有正确的ID(或被请求)答案 - 但您应该意识到每个与会者都可以访问通信的每个部分...
If you really want to do this with Serialport's you need to have a RS232 to RS485 Converter.
The RS485 allows you to have more than one listening attendee to the wire. All attendee's "hear" the message but only this one, who has the right ID (or is requested) answers - but you should realize that each part of the communication is allways accessible by each attendee ...

>