StealthRT
StealthRT

Reputation: 10542

c # and Comm Ports

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

Upvotes: 2

Views: 910

Answers (1)

vcsjones
vcsjones

Reputation: 141588

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.

Upvotes: 5

Related Questions