I am working with a codec and am trying to poll the state of RS232 serial pin 1 (CD high/low).
The code I have I think is right but I am second guessing myself and was hoping someone could confirm or correct me.
According to the the data sheet of the codec Pin 1 should be High when a call is active. I suspect i have done something wrong because while in a call I get a return of false (low).
This is a Windows Forms application and I am using System.IO.Ports
private void button4_Click(object sender, EventArgs e)
{
if (!serialPort1.IsOpen)
{
serialPort1.Open();
}
bool test = serialPort1.CDHolding;
if (test == false)
{
MessageBox.Show("Pin low");
}
else
{
MessageBox.Show("Pin high");
}
}
Also is there an easy way to show the actual voltage on the pin?
There really isn’t much here we can tell you that you don’t already know. Yes SerialPort.CDHolding “Gets the state of the Carrier Detect line for the port.” I would first verify (electrically) the state of the pin, and then check that against what this property tells you. I’m guessing it is telling you the correct state.
When it comes to serial ports, I would always double check your pin-out; depending on the hardware and connector, they can be incredibly non-standard, and are easy to mess up.
You ask about showing the voltage on the pin. Do you mean programattically? No, that is impossible. That is a digital input line; once it hits the UART it is a digital signal, you cannot know the analog voltage.
Just as an additional tidbit, this property is actually just a wrapper that calls the Win32 GetCommModemStatus function, and returns true if bit 7 (decimal 128) is set.