Hi,
I'm writing a program for communication with RS232. The device works to 9600,8,N,1 and 300,7,E,1.
If the program is used to 9600 it works properly, while when I use the 300 baud it doesn't work.
Are there any problems with communication at 300 baud in C#?
For the reading on the RS232 I use serialport.ReadChar(). Can I use it at 300 baud?
I'm usign System.IO.Ports.SerialPort as library.
Thanks,
Gerardo
Loading
Sam HobbsPosted Sep 14, 2011, 9:14 PM
I assume you know that 9600,8,N,1 means 9600 baud and 8 bits and no parity (error checking) and one stop bit. I am not sure what a stop bit is. And 300,7,E,1 means 7 bits and even parity.
Are you also familiar with flow control? I think there are two types of flow control; hardware and software. It is used to keep the two ends synchronized, so that one end does not go too fast or slow. At 300 baud it is very easy for one end to go too fast. So be sure that the flow control is set properly.
I think that Handshake is the same as flow control. I see in your code above that you have Handshake.None; that could be a problem.
gerardo tisoPosted Sep 14, 2011, 7:56 PM
Sam HobbsPosted Sep 14, 2011, 7:07 PM
Unless it does not work with HyperTerminal, and then you have made a huge diagnostic leap.
Assuming that C# is the problem and ignoring other possibilities is the type of problem that is often impossible to solve.
gerardo tisoPosted Sep 14, 2011, 6:18 PM
I have a problem only with C#!
Sam HobbsPosted Sep 14, 2011, 6:13 PM
VulpesPosted Sep 14, 2011, 12:07 PM
http://stackoverflow.com/questions/7107407/communicate-with-kohler-meter-in-c
http://stackoverflow.com/questions/6992530/change-baud-rate-in-c-without-closing-connection
It's difficult to know what else to suggest but, if you could post the VB6 code, it might give us some clues.
gerardo tisoPosted Sep 14, 2011, 11:54 AM
VulpesPosted Sep 14, 2011, 11:29 AM
gerardo tisoPosted Sep 14, 2011, 11:13 AM
VulpesPosted Sep 14, 2011, 10:35 AM
If it's the same machine, can you post it here so we can see if there's anything we're missing.
gerardo tisoPosted Sep 14, 2011, 10:24 AM
I'm using the HDD free serial port monitor for the monitoring the serial communication.
Normally, I don't have any characters on the serial. Often I have two or three bad characters.
VulpesPosted Sep 14, 2011, 10:03 AM
I'd try replacing this bit of code:
gerardo tisoPosted Sep 14, 2011, 9:59 AM
deepender singlaPosted Sep 14, 2011, 9:35 AM
gerardo tisoPosted Sep 14, 2011, 9:33 AM
public void Seriale()
{
System.IO.Ports.SerialPort seriale = new SerialPort();
byte[] messaggio = new byte[5], ricezione = new byte[25];
seriale.BaudRate = 300;
seriale.DataBits = 7;
seriale.Handshake = Handshake.None;
seriale.Parity = Parity.Even;
seriale.StopBits = StopBits.One;
seriale.PortName = "COM3";
seriale.ReadTimeout = 1000;
seriale.Open();
seriale.Encoding = System.Text.Encoding.GetEncoding(1252);
messaggio[0] = (byte)0x2F;
messaggio[1] = (byte)0X3F;
messaggio[2] = (byte)0x21;
messaggio[3] = (byte)0x0D;
messaggio[4] = (byte)0x0A;
for (int i = 0; i < 5; i++)
{
seriale.Write(messaggio, i, 1);
}
for (int i = 0; i < 25; i++)
{
ricezione[i] = (byte)seriale.ReadByte();
seriale.DiscardInBuffer();
}
}
I have tried the same code in VB6 and the device works!
Are there some troubles regarding to 300 baud communication in C# .NET 2010?
VulpesPosted Sep 14, 2011, 9:14 AM
deepender singlaPosted Sep 14, 2011, 9:10 AM
gerardo tisoPosted Sep 14, 2011, 9:06 AM
deepender singlaPosted Sep 14, 2011, 8:52 AM