RS232 SerialPort class

D

David

Hi all,

I am trying to use the RS232 serial port but appear to be having problems.

Intially, it looks like the equipment I am connecting to is the one with the
problem, but the potential also does lie with the SerialPort class.

Here is my scenario... this is what I have tested.

I have to receive data in from the serial port by a parallel to serial
convertor.

I have tested the parallel to serial convertor successfully using HyperTerm.
It works flawlessly. However, I need to get the data into my program,
written in C#

The program I have written works flawlessly with a loopback adapter, it also
works fine when connected to another device that outputs RS232 data (in my
case, a freeview box with an RS232 adapter)

However, from the parallel to serial device, I cannot read the data. In
fact, it does not even get to the datareceived event. (listening on RS232)

Is there something Hyperterm is doing that I don't know about? some sort of
low level communication potentially?

Is there a bug in the SerialPort class that is not following strict RS232
protocol?

I cannot rule out the device, but then again, I cannot rule out SerialPort
class.

Incidentally, I have tried this on 2 computers now to read the device.

I can supply code, but I have written now two different versions from two
different internet sources, however, it seems to me to not be based on code,
but most likely on the actual serialport class itself.

Any ideas whatsoever would be most appreciated as I have been battling this
one issue for over a month now (and only recently realised that I could use
hyperterm to ensure that the device is working).

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
D

David

Hi Peter,

Yes, all the config settings are correct. I am not even getting any noise or
the event firing.

Here is my config function. This is done on a button press. I have my config
set to exactly the same as Hyperterm. I will double check all settings
again.

I know that RS232, while a standard is subject to interpretation and is
implemented in different ways by different manufacturers. This leads me to
think that the problem could still be on either side.

private void SetCommPort()
{
if (RS232.IsOpen)
{
RS232.Close();
}

try
{
writetofile("Attempting to set port : " +
PortCombo.SelectedItem.ToString(), "debug.txt");
RS232.PortName = PortCombo.SelectedItem.ToString();

writetofile("Attempting to set BAUD : " +
BaudRateCombo.SelectedItem.ToString(), "debug.txt");
RS232.BaudRate =
Convert.ToInt32(BaudRateCombo.SelectedItem);

writetofile("Attempting to set Parity : " +
ParityCombo.SelectedItem.ToString(), "debug.txt");
switch (ParityCombo.SelectedItem.ToString())
{
case "None":
RS232.Parity = System.IO.Ports.Parity.None;
break;
case "Odd":
RS232.Parity = System.IO.Ports.Parity.Odd;
break;
case "Even":
RS232.Parity = System.IO.Ports.Parity.Even;
break;
case "Mark":
RS232.Parity = System.IO.Ports.Parity.Mark;
break;
case "Space":
RS232.Parity = System.IO.Ports.Parity.Space;
break;
}
writetofile("Attempting to set Data Bits : " +
DataBitsCombo.SelectedItem.ToString(), "debug.txt");
RS232.DataBits =
Convert.ToInt32(DataBitsCombo.SelectedItem);

writetofile("Attempting to set Stop Bits : " +
StopBitsCombo.SelectedItem.ToString(), "debug.txt");
switch (StopBitsCombo.SelectedItem.ToString())
{
case "None":
RS232.StopBits = System.IO.Ports.StopBits.None;
break;
case "One":
RS232.StopBits = System.IO.Ports.StopBits.One;
break;
case "Two":
RS232.StopBits = System.IO.Ports.StopBits.Two;
break;
case "OnePointFive":
RS232.StopBits =
System.IO.Ports.StopBits.OnePointFive;
break;

}

writetofile("Attempting to set Handshake : " +
HandshakeCombo.SelectedItem.ToString(), "debug.txt");
switch (HandshakeCombo.SelectedItem.ToString())
{
case "Xon/XOff":
RS232.Handshake = Handshake.XOnXOff;
break;
case "Hardware":
RS232.Handshake = Handshake.RequestToSend;
break;
}


RS232.Open();
}
catch
{
MessageBox.Show("There is a problem with the serial port
settings.");
}
}

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available


Peter Duniho said:
[...]
Any ideas whatsoever would be most appreciated as I have been battling
this
one issue for over a month now (and only recently realised that I could
use
hyperterm to ensure that the device is working).

It's not the kind of question that is practical to answer via a newsgroup.
Too many different variables, many of which are knowable only by you.

But, usually when this sort of question comes up, it turns out to be that
the person has simply not set the serial port configuration correctly. Go
back and double check that you've got baud rate, data length, start/stop
bits, and all the flow-control/handshaking settings exactly the same in
your .NET program as for what works in Hyperterm.

Pete
 
M

Marven Lee

David wrote....
switch (HandshakeCombo.SelectedItem.ToString())
{
case "Xon/XOff":
RS232.Handshake = Handshake.XOnXOff;
break;
case "Hardware":
RS232.Handshake = Handshake.RequestToSend;
break;
}

Could you need to set both with RequestToSendXOnXOff ?

Also have you set DtrEnable to true ?
 
D

David

Marv... excellent...

I wasn't even aware that existed. That has worked for the hardware
handshake.

Do I need to use that for the Xon / XOff as well? I don't have it in there
and it doesn't work here, but it is not too major a problem. However, I do
know that the Xon / XOff in hyperterm does work.

I have also expanded that switch case to have both and none...

writetofile("Attempting to set Handshake : " +
HandshakeCombo.SelectedItem.ToString(), "debug.txt");
switch (HandshakeCombo.SelectedItem.ToString())
{
case "Xon/XOff":
RS232.Handshake = Handshake.XOnXOff;
break;
case "Hardware":
RS232.Handshake = Handshake.RequestToSend;
RS232.DtrEnable = true;
break;
case "Both":
RS232.Handshake = Handshake.RequestToSendXOnXOff;
RS232.DtrEnable = true;
break;
default:
RS232.Handshake = Handshake.None;
break;
}


--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
M

Marven Lee

David wrote in message...
Marv... excellent...

I wasn't even aware that existed. That has worked for the hardware
handshake.

Do I need to use that for the Xon / XOff as well? I don't have it in there
and it doesn't work here, but it is not too major a problem. However, I do
know that the Xon / XOff in hyperterm does work.

I have also expanded that switch case to have both and none...

To be honest I've only recently learned a bit about serial port programming,
so don't fully understand it.

I always thought serial programming used hardware or software flow control,
not both at the same time.

I think I'm right in saying that DTR line is used to indicate to the device
(DCE?)
that the serial port is opened and ready, some devices must depend on it,
others
don't.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top