c#和Comm Ports

Ste*_*hRT 2 c# vb6 serial-port

嘿所有我试图打开和关闭以下RS232命令的A/V接收器:

 @MAIN:VOL=Down & Chr$(13) & Chr$(10)
Run Code Online (Sandbox Code Playgroud)

这在我的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)
Run Code Online (Sandbox Code Playgroud)

但是我似乎无法在我的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
Run Code Online (Sandbox Code Playgroud)

我认为它不起作用的原因是"\ r"和"\n"取代了vb6 Chr $(13)&Chr $(10).

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

vcs*_*nes 5

我不确定是什么PCComm.CommunicationManager.但是,在没有任何特殊API的情况下通过Serial进行通信相当简单.这个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();
Run Code Online (Sandbox Code Playgroud)

编辑:

您可能CommunicationManager失败了,因为它没有设置RtsEnable属性true.您的VB6代码在第4行上执行此操作.