c # and Comm Ports
本文关键字:Ports Comm and | 更新日期: 2023-09-27 18:04:54
嘿,我正试图打开和关闭A/V接收器,以下RS232命令:
@MAIN:VOL=Down & Chr$(13) & Chr$(10)
这在我的VB6应用程序中工作得很好:
MSCommAV.CommPort = 4
MSCommAV.RThreshold = 1
MSCommAV.Settings = "9600,N,8,1"
MSCommAV.RTSEnable = True
MSCommAV.PortOpen = True
MSCommAV.Output = "@MAIN:VOL=Down" & Chr$(13) & Chr$(10)
然而,我似乎不能让它在我的c#应用程序工作:
PCComm.CommunicationManager commAV = new PCComm.CommunicationManager();
commAV.Parity = "None";
commAV.StopBits = "One";
commAV.DataBits = "8";
commAV.BaudRate = "9600";
commAV.PortName = "COM4";
commAV.CurrentTransmissionType = PCComm.CommunicationManager.TransmissionType.Text; //.Hex
commAV.OpenPort();
commAV.WriteData("@MAIN:VOL=Down" + "'r" + "'n"); //Vol DOWN
我认为它不工作的原因是"'r"answers"'n"取代了vb6 Chr$(13) &杆(10美元)。
CommunicationManager.cs: http://snipt.org/xmklh
我不确定PCComm.CommunicationManager
是什么。然而,通过串行通信非常简单,不需要任何特殊的api。这段c#代码相当于VB6代码:
var port = new SerialPort("COM4", 9600, Parity.None, 8, StopBits.One);
port.RtsEnable = true;
port.Open();
port.Write("@MAIN:VOL=Down'r'n");
port.Close();
编辑:
这是可能的,你的CommunicationManager
是失败的,因为它没有设置RtsEnable
属性为true
。你的VB6代码在第4行做这个