如何构建串行(RS422 或 RS232)消息以通过 PuTTy 与 Sick LMS200 通信? [英] How to build a serial (RS422 or RS232) message to communicate with Sick LMS200 via PuTTy?

查看:125
本文介绍了如何构建串行(RS422 或 RS232)消息以通过 PuTTy 与 Sick LMS200 通信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个串行设备(生病的 LMS200)使用 RS422 到 USB 转换器连接到我的 PC.LMS200 上的串行设置(波特率、停止位等...)与我的 PC 匹配并且正在通信(使用 LMS200 附带的应用程序进行验证).我需要编写一个与 LMS 通信的自定义应用程序.

I have a serial device (sick LMS200) connected to my PC using a RS422 to USB converter. The serial settings (baud, stop bits, etc...) on the LMS200 and my PC match and are communicating (verified using an application that ships with the LMS200). I need to write a custom application which communicates with the LMS.

在开始构建应用程序之前,我需要弄清楚如何在 PC 和 LMS 之间交换数据报.为了解决这个问题,我一直在尝试使用 PuTTy 手动发送数据报.LMS 手册 ( https://drive.google.com/open?id=0Byv4owwJZnRYVUJPMXdud0Z6Uzg) 定义数据报类型以及如何构建它们.例如,在手册的第 46 页上,可以看到一个向单元发送特定指令的数据报;它看起来像这样:02 00 02 00 30 01 31 18.

Before I can begin building my application I need to figure out how to exchange datagrams between the PC and the LMS. To figure this out I have been trying to manually send datagrams using PuTTy. The manual for the LMS ( https://drive.google.com/open?id=0Byv4owwJZnRYVUJPMXdud0Z6Uzg) defines the datagram types and how they should be built. For example, on pg 46 of the manual it is possible to see a datagram that sends a specific instruction to the unit; it looks like this: 02 00 02 00 30 01 31 18.

但是,当我使用 PuTTy 发送字符串 02 00 02 00 30 01 31 18 时,LMS 没有响应(它应该响应).我相信它没有响应,因为数据报缺少一些串行头数据或者我没有正确表示十六进制值(我尝试使用 0x00 表示诸如 00 之类的字节和 00h 但没有成功).你能帮我用手册制定一个有效的串行消息吗?我已经在这方面工作了很长时间,但我很难理解如何将手册中的信息转换为有效的数据报.

However when I use PuTTy to send the string 02 00 02 00 30 01 31 18 the LMS does not respond (which it should). I believe it does not respond because the datagram is missing either some serial header data or I am not representing the hex values correctly (I tried to represent bytes such as00 using 0x00 and 00h but had no success). Can you please help me formulate a valid serial message using the manual? I have been at this for a very long time and I am having a really hard time understanding how to convert the information in the manual into a valid datagram.

如果我能提供更多信息,请告诉我.提前致谢.

Please let me know if I can provide any more info. Thanks in advance.

推荐答案

我没有正确表示十六进制值(我尝试使用 0x00 和 00h 表示诸如 00 之类的字节,但没有成功).

I am not representing the hex values correctly (I tried to represent bytes such as00 using 0x00 and 00h but had no success).

终端/PC键盘上的Ctrl键可用于生成ASCII控制字符(即字节值为0x000x1F).
就像 Shift 键生成键的移位或大写字符(而不是其未移位或小写字符)一样,Ctrl 键(带有一个字母或几个其他键)可以生成一个 ASCII 控制字符.

The Ctrl key on terminal/PC keyboards can be used to generate ASCII control characters (i.e. the unprintable characters with byte values of 0x00 through 0x1F).
Just like the Shift key generates the shifted or uppercase character of the key (instead of its unshifted or lower-case character), the Ctrl key (with an alphabetic or a few other keys) can generate an ASCII control character.

典型的美国 PC 键盘可以通过键入 ctrl-@ 生成 ASCII 'NUL' 字符,即按住 CTRLShift 键,然后键入2(因为@"字符是美国 PC 键盘上 2 键的移位字符).

The typical USA PC keyboard can generate an ASCII 'NUL' character by typing ctrl-@, that is, by holding down the CTRL and Shift keys, and typing 2 (since the '@' character is the shifted character of the 2 key on USA PC keyboards).

以类似的方式为 'SOH' 或 0x01 键入 ctrl-A(即 CTRL+A 键,Shift 不是必需的),对于 'STX' 或 0x02 键入 ctrl-B,等等.
对于 'SUB' 或 0x1A,输入 ctrl-Z.
对于ESC"或0x1B,输入Esc 键.
对于 'FS' 或 0x1C,输入 ctrl-\(或 CTRL+\).
对于 'GS' 或 0x1D 输入 ctrl-](或 CTRL+]).
对于RS"或0x1E,输入ctrl-^(或CTRL+Shift+6).
对于 'US' 或 0x1F,输入 ctrl-_(或 CTRL+Shift+-).

In similar fashion for 'SOH' or 0x01 type ctrl-A (i.e. CTRL+A keys, the Shift is not necessary), for 'STX' or 0x02 type ctrl-B, et cetera.
For 'SUB' or 0x1A type ctrl-Z.
For 'ESC' or 0x1B type the Esc key.
For 'FS' or 0x1C type ctrl-\ (or CTRL+\).
For 'GS' or 0x1D type ctrl-] (or CTRL+]).
For 'RS' or 0x1E type ctrl-^ (or CTRL+Shift+6).
For 'US' or 0x1F type ctrl-_ (or CTRL+Shift+-).

请注意,一些经常使用的 ASCII 控制代码具有专用键,例如
'HT' 具有 0x09Tab 键,
'BS' 有 0x08Backspace 键,
'LF' 具有 0x0AEnter 键(在 Linux 中),并且
'ESC' 具有 0x1BEsc 键.

Note that a few oft-used ASCII control codes have dedicated keys, e.g.
'HT' has the Tab key for 0x09,
'BS' has the Backspace key for 0x08,
'LF' has the Enter key (in Linux) for 0x0A, and
'ESC' has the Esc key for 0x1B.

当您不知道如何从键盘生成 ASCII 控制字符时,您可以退回使用十六进制编辑器(而不是文本编辑器)在文件中创建消息,然后发送文件.

When you don't know how to generate the ASCII control characters from the keyboard, you could fall back on creating the message in a file using a hex editor (not a text editor), and then send the file.

实际上,二进制文件可能是手动生成二进制消息的最可靠方法.当代码被 shell 或应用程序拦截为它的特殊指令(例如 ctrl-C 或 ctrl-Z 以中止程序)而不是将其视为数据时,手动键入控制代码可能会失败.
转义输入数据是一种可以避免这种情况的方法.
电话调制解调器在透明(又名数据)模式下设法避免了这个问题,方法是需要时间保护(即特定的空闲时间)来将命令与数据区分开来.

Actually the binary file could be the most reliable method of hand-generation of binary messages. Hand-typing of control codes could fail when a code is intercepted by the shell or application program as a special directive to it (e.g. ctrl-C or ctrl-Z to abort the program) rather than treating it as data.
Escaping the input data is one method that might be available to avoid this.
Phone modems have managed to avoid this issue when in transparent (aka data) mode, by requiring a time guard (i.e. specific idle times) to separate and differentiate commands from data.

这篇关于如何构建串行(RS422 或 RS232)消息以通过 PuTTy 与 Sick LMS200 通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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