如何将ASCII设置命令发送到外部设备(传感器)? [英] How to send a set up command in ASCII to External device (Sensor)?

查看:157
本文介绍了如何将ASCII设置命令发送到外部设备(传感器)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

抱怨愚蠢的问题,但我是网络和编程的新手,所以想要一些帮助

我想与通过以太网/ IP连接的传感器进行通信。我已建立连接但我无法发送ASCII设置命令。我该怎么做才能发送ASCII命令并获得反馈?我尝试通过下面给出的代码这样做。



sRN EIIpAddr是来自设备手册的命令。通过终端程序发送此命令会给出正确的反馈(即给出设备的IP)



Apologies for asking stupid question but I am new to the world of networking and Programming so wanted some help
I want to communicate with my sensor which is connected via ethernet/IP. I have established connection but I am unable to send the ASCII setup command. What should I do to send ASCII command and get feedback? I tried doing so by the code given below.

sRN EIIpAddr is the command from device manual. This command when sent via terminal program gives proper feedback(i.e gives the ip of the device)

message = "[STX]sRN EIIpAddr[ETX]"; // Command to be sent
if (send(s, message, strlen(message), 0) < 0)
{
    printf("Send failed");
    return 1;
}
printf("Data Send\n");

if ((recv_size = recv(s, server_reply, 2000, 0)) == SOCKET_ERROR)
{
    printf("recv failed");
}

printf("Reply received\n");





我得到的输出是数据发送但我没有收到任何反馈。



The output that I get is Data send but then I don't receive any feedback.

推荐答案

STX ETX 通常是指ASCII控制字符

控制角色 - 维基百科,免费的百科全书 [ ^ ]

无法显示ASCII控制字符,因此为了显示放置它们的位置,将它们显示为 [STX] [ETX] 但你必须用它们的ASCII代码替换它们。

这意味着 [STX] 必须用值为 0x02 的单个ASCII字符替换。

这意味着 [ETX] 必须替换为单个ASCII字符值 0x03



IpAddr 也可能被其他东西取代。只有传感器文档会告诉你。



寻找教程和用户论坛是一个好主意。
STX and ETX usually refer to ASCII control characters
Control character - Wikipedia, the free encyclopedia[^]
An ASCII control character can't be displayed, thus to show you where to put them, it is a common usage to show them as [STX] and [ETX] but you have to replace them by their ASCII codes.
It means that [STX] must be replaced by a single ASCII character of value 0x02.
It means that [ETX] must be replaced by a single ASCII character of value 0x03.

It is also possible that IpAddr should be replaced by something else. Only sensor documentation will tell you.

It is a good idea to look for tutorials and users forums.


似乎您使用本PDF文档中描述的传感器:

电报配置和操作LMS1xx,LMS5xx,TiM3xx,JEF300,JEF500 [ ^ ]。



但是它描述了通过终端程序进行的通信(串行连接)。如果传感器连接到串行端口,则必须使用串行通信而不是网络功能。请参阅串行通信 [ ^ ]如何做到这一点。



As已在解决方案1中注明并在手册中描述, STX ETX 是指特殊字符。因此要发送的字符串应如下所示:

It seems that you use a sensor described in this PDF document:
Telegrams for Configuring and Operating the LMS1xx, LMS5xx, TiM3xx, JEF300, JEF500[^].

But that describes the communication via a terminal program (serial connection). If the sensor is connected to a serial port, you must use serial communication rather than network functions. See Serial Communications[^] on how to do this.

As already noted in solution 1 and described in the manual, STX and ETX refer to special characters. So the string to be send should look like:
message = "\x02sRN EIIpAddr\x03";

这篇关于如何将ASCII设置命令发送到外部设备(传感器)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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