CHAR 通讯端口命令

发布于 2024-11-28 17:17:23 字数 1134 浏览 0 评论 0原文

我正在尝试使用以下命令发送 RS232 连接的投影仪以将其打开:

commProj.Parity = "None";
commProj.StopBits = "One";
commProj.DataBits = "8";
commProj.BaudRate = "19200";
commProj.PortName = "COM6";
commProj.CurrentTransmissionType = PCComm.CommunicationManager.TransmissionType.Text; //.Hex
commProj.OpenPort();
commProj.WriteData((char)33 + (char)137 + (char)1 + (char)80 + (char)87 + (char)49 + "\n"); //turn on proj

问题是它不起作用。

我已经用 VB6 端口完成了此操作,并且工作得很好:

 public static PCComm.CommunicationManager commProj = new PCComm.CommunicationManager();

 MSCommProj.CommPort = 6
 MSCommProj.Settings = "19200,N,8,1"
 MSCommProj.PortOpen = True 
 MSCommProj.Output = Chr(33) & Chr(137) & Chr(1) & Chr(80) & Chr(87) & Chr(49) & Chr(10)

我缺少什么?

David

CommunicationManager.cs: http://snipt.org/xmklh

在此处输入图像描述 在此处输入图像描述 在此处输入图像描述

I am trying to use the following to send over an RS232 connected projector to turn it on:

commProj.Parity = "None";
commProj.StopBits = "One";
commProj.DataBits = "8";
commProj.BaudRate = "19200";
commProj.PortName = "COM6";
commProj.CurrentTransmissionType = PCComm.CommunicationManager.TransmissionType.Text; //.Hex
commProj.OpenPort();
commProj.WriteData((char)33 + (char)137 + (char)1 + (char)80 + (char)87 + (char)49 + "\n"); //turn on proj

Problem being is that it doesnt work.

I have done this with a VB6 port and it works just fine:

 public static PCComm.CommunicationManager commProj = new PCComm.CommunicationManager();

 MSCommProj.CommPort = 6
 MSCommProj.Settings = "19200,N,8,1"
 MSCommProj.PortOpen = True 
 MSCommProj.Output = Chr(33) & Chr(137) & Chr(1) & Chr(80) & Chr(87) & Chr(49) & Chr(10)

What am i missing?

David

CommunicationManager.cs: http://snipt.org/xmklh

enter image description here
enter image description here
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

混吃等死 2024-12-05 17:17:23

好的,手册很有帮助。尝试将 CurrentTransmissionType 更改为 TransmissionType.Hex 并发送字符串 21890100000a

commProj.CurrentTransmissionType = TransmissionType.Hex;
commProj.WriteData("21890100000a");

编辑

抱歉,那是“连接检查” 。使用 2189015057310a 表示on,使用 2189015057300a 表示off

Okay, the manual helps a lot. Try changing the CurrentTransmissionType to TransmissionType.Hex and sending the string 21890100000a

commProj.CurrentTransmissionType = TransmissionType.Hex;
commProj.WriteData("21890100000a");

EDIT

Sorry, that was "connection check". Use 2189015057310a for on and 2189015057300a for off.

甜柠檬 2024-12-05 17:17:23

char 的 plus(+) 运算符不会连接其相加的值。所以你最终会传递“387\n”来写入数据。

您需要创建一个 char 数组,然后将其转换为字符串:

commProj.WriteData(new string(new char[] { (char)33, (char)37, (char)1, (char)80, (char)87, (char)49, '\n' }));

The plus(+) operator for char's doesn't concatenate the values it adds them. So you end up passing "387\n" to write data.

You need to create a char array and then convert that to a string instead:

commProj.WriteData(new string(new char[] { (char)33, (char)37, (char)1, (char)80, (char)87, (char)49, '\n' }));
无风消散 2024-12-05 17:17:23

我不知道 commProj 是什么类型的对象(具体来说),但我的猜测是问题来自于将每个数值转换为字符。一个 char 的大小为 2 个字节。我建议尝试编写一个包含数据的字节数组,或者将字符串与这些字符连接起来,然后将字符串转换为 ascii 文本。

I don't know what kind of object commProj is (specifically) but my guess is that the problem comes from casting each numeric value to a char. A char is 2 bytes in size. I recommend either trying to write a Byte array with your data in it, or concatenating a string with these chars and then converting the string to ascii text.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文