CHAR 通讯端口命令
我正在尝试使用以下命令发送 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好的,手册很有帮助。尝试将
CurrentTransmissionType
更改为TransmissionType.Hex
并发送字符串21890100000a
编辑
抱歉,那是“连接检查” 。使用
2189015057310a
表示on
,使用2189015057300a
表示off
。Okay, the manual helps a lot. Try changing the
CurrentTransmissionType
toTransmissionType.Hex
and sending the string21890100000a
EDIT
Sorry, that was "connection check". Use
2189015057310a
foron
and2189015057300a
foroff
.char 的 plus(+) 运算符不会连接其相加的值。所以你最终会传递“387\n”来写入数据。
您需要创建一个 char 数组,然后将其转换为字符串:
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 是什么类型的对象(具体来说),但我的猜测是问题来自于将每个数值转换为字符。一个 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.