嘿,我正在试着用下面的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“和"\n”替换了vb6的Chr$(13)和Chr$(10)。
CommunicationManager.cs:http://snipt.org/xmklh
发布于 2011-08-10 10:20:28
我不确定PCComm.CommunicationManager是什么。但是,通过Serial进行通信相当简单,不需要任何特殊的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行就是这样做的。
https://stackoverflow.com/questions/7005141
复制相似问题