开发者

c # and Comm Ports

开发者 https://www.devze.com 2023-03-27 13:02 出处:网络
Hey all i am trying to turn an A/V reciever on and off this the following RS232 command: @MAIN:VOL=Down & Chr$(13) & Chr$(10)

Hey all i am trying to turn an A/V reciever on and off this the following RS232 command:

 @MAIN:VOL=Down & Chr$(13) & Chr$(10)

This works just fine in my VB6 app:

 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)

However i can not seem to get it working in my C# app:

 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

I think the reason why its not working is the "\r" and "\n" replacing the vb6 Chr$(13) & Chr$(10).

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


I'm not sure what PCComm.CommunicationManager is. However, it's fairly simple to communicate via Serial without any special APIs. This C# code is the equivalent of the VB6 code:

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();

EDIT:

It's possible that your CommunicationManager is failing because it is not setting the RtsEnable property to true. Your VB6 code is doing that on line 4.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号