Compact Framework串行端口和平衡 [英] Compact Framework serial port and balance

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

问题描述

因此,要打开串行端口并通过串行端口成功地从天平传输数据,我需要确保serialPort对象上的设置与天平的实际设置匹配。

So, to open up a serial port and successfully transmit data from the balance through the serial port, i need to make sure that the settings on the serialPort object match the actual settings of the balance.

现在,问题是如何检测由于设置不同而未建立连接? serialPort.Open不会引发任何异常以指示已建立连接。是的,这些设置是有效的,但是如果它们与设备(余额)设置不匹配;我为何不了解余额差额的问题呢?

Now, the question is how do i detect that the connection hasn't been established due to the settings being different? No exception is thrown by serialPort.Open to indicate that the connection has been established. Yes, the settings are valid, but if they don't match the device (balance) settings; I am in the dark as to why the weight off the balance is not being captured.

这里有输入吗?

推荐答案

如果情况很近,但是仍然不正确,.NET串行端口对象甚至可能不会给您错误(即,直到发生灾难性事件为止。)

If things are close, but still incorrect, the .NET serial port object may not even give you an error (that is, until something catastrophic occurs).

我最常见的串行端口通信故障是由于波特率不匹配而发生的。如果您知道一条消息,可以得到一个回声,请尝试此作为握手工作的一部分。您正在连接的设备可能带有状态消息。请求不会造成任何伤害,您会发现通信是否正确进行。

My most common serial port communication failure occurs due to mismatched baud rates. If you have a message that you know you can get an 'echo' for, try that as part of a handshaking effort. Perhaps the device you're connecting to has a 'status' message. No harm will come from requesting it, and you will find out if communication is flowing correctly.

对于软件握手(xon xoff),您几乎无法做检测是否正确配置。串行端口对象可以执行任何操作,从完全忽略它到发生线程异常错误,这取决于基础的串行端口驱动程序实现。我有完全忽略xon / xoff并将字符直接传递到程序中的串行端口驱动程序-yikes!

For software handshaking (xon xoff) There's very little you can do to detect whether or not it's configured right. The serial port object can do anything from ignore it completely to have thread exception errors, depending on the underlying serial port driver implementation. I've had serial port drivers that completely ignore xon/xoff, and pass the characters straight into the program - yikes!

对于硬件握手,波特的基本回声策略费率可能会有所不同,具体取决于您设备的工作方式。如果您知道它将进行硬件握手,则可以检测到并打开它。如果该设备需要硬件握手并且没有打开,则可能什么也没有,反之亦然。

For hardware handshaking, the basic echo strategy for baud rate may work, depending on how your device works. If you know that it will do hardware handshaking, you may be able to detect it and turn it on. If the device requires hardware handshaking and it's not on, you may get nothing, and vice versa.

另一种很少使用的设置是DTR引脚-数据终端就绪。一些串行设备要求对此进行断言(即,设置为true)以表明是时候开始发送数据了。默认情况下设置为false;

Another setting that's more rarely used is the DTR pin - data terminal ready. Some serial devices require that this be asserted (ie, set to true) to indicate that it's time to start sending data. It's set to false by default; give toggling it a whirl.

请注意,串行端口对象是...挑剔的。虽然不是必需的,但我会考虑在进行任何更改之前关闭端口。

Note that the serial port object is ... finicky. While not necessarily required, I would consider closing the port before you make any changes.

编辑:

谢谢根据您的评论,看起来是您的设备。它说默认设置应该是:

Thanks to your comments, it looks like this is your device. It says the default settings should be:


  • 1200波特率

  • 奇偶校验

  • 1个停止位

  • 硬件握手

  • 1200 baud
  • Odd parity
  • 1 stop bit
  • Hardware handshaking

未指定多少个数据位,但是设备说它支持7和8。我会尝试这两个。它还说它支持600、1200、2400、4800、9600和19200波特。

It doesn't specify how many data bits, but the device says it supports 7 and 8. I'd try both of those. It also says it supports 600, 1200, 2400, 4800, 9600, and 19200 baud.

如果您已打开硬件握手功能,请启用DTR(不同的功能)和在所有不同的波特率之间循环切换,很有可能这不是您的设置。可能是所使用的串行电缆未正确连接到您的设备。一些串行电缆是直通电缆,其中一侧的1-9引脚与另一侧的1-9引脚完全匹配。然后,您有了交叉电缆,其中的 TX和 RX电缆被切换了(这样,当一侧发送时,另一侧接收到了非常方便的电缆。)

If you've turned on hardware handshaking, enabled DTR (different things) and cycled through all the different baud rates, there's a good chance that it's not your settings. It could be that the serial cable that's being used may be wired incorrectly for your device. Some serial cables are 'passthrough' cables, where the 1-9 pins on one side match exactly with the 1-9 pins on the other. Then, you have 'crossover' cables, where the "TX" and "RX" cables are switched (so that when one side transmits, the other side receives, a very handy cable.)

考虑在手册后面的命令表中查看;您可以执行打印软件版本命令来获取某种回显。

Consider looking at the command table in the back of the manual there; there's a "print software version" command you could issue to get some type of echo back.

这篇关于Compact Framework串行端口和平衡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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