Author Topic: Is there a bug in the Serial Port class ? (hope not!)  (Read 22287 times)

GlennP

  • Frequent Contributor
  • ****
  • Posts: 141
Is there a bug in the Serial Port class ? (hope not!)
« on: November 03, 2011, 12:27:00 pm »
Hi,
It's me again. Question the following bit of code:

for (int i = 0; i < Length; i++)
            {
                CommandSent = Command1.Substring(j, 1);
                myComPort.Write(CommandSent);
                //MessageBox.Show(CommandSent);
                richTextBox1.Text += CommandSent;
                j++;
            }
            myComPort.Write("\r\n");

works, while using the staight
myComPort.Write(Command1);
does not, is this due to a slight gap being introduced by the for loop? or am I wrong!
 

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Is there a bug in the Serial Port class ? (hope not!)
« Reply #1 on: November 03, 2011, 01:18:05 pm »
Be sure you have a string in Command1. Try

myComPort.Write("test");

Jan

GlennP

  • Frequent Contributor
  • ****
  • Posts: 141
Re: Is there a bug in the Serial Port class ? (hope not!)
« Reply #2 on: November 04, 2011, 05:11:44 am »
Tried that long ago one of the boards that can register comms only see's one one character. The latest boards we are producing seem to not reply but with my cludgy method using the for loop they respond and act normally.  I am thinking that the buffer on the serial port is too small, if I had not seen this behavoir with more than one chip family (MSP430 & PIC16F) I would be thinking it is due to a manufactures issue but multiple chips, multiple families mean it is something else.  Someone (not me!) being a little stingy with buffer size ?

Glenn

Also I have had chat to the designer of the board he says the buffer is about 40 bytes which should be enough with for the messages.  The message is " L255:8:000 \n" if this is sent using the Write method does not work but sending it the 'for' loop above seems work.
 
« Last Edit: November 04, 2011, 01:05:36 pm by GlennP »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Is there a bug in the Serial Port class ? (hope not!)
« Reply #3 on: November 04, 2011, 10:36:12 am »
If it works at a slower baud rate, it's likely an issue with how fast the firmware can remove the received data from the serial-port's buffer.

Jan

GlennP

  • Frequent Contributor
  • ****
  • Posts: 141
Re: Is there a bug in the Serial Port class ? (hope not!)
« Reply #4 on: November 04, 2011, 01:11:16 pm »
So, it's not my problem the board wont recieve at the speed its being sent at (!) That could well solve it, why does HyperTerm work though?

Glenn
TGIF

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Is there a bug in the Serial Port class ? (hope not!)
« Reply #5 on: November 04, 2011, 04:45:50 pm »
If there is a buffering issue, use flow control.

The first step is to verify that the data is going out on the line to the board. Then investigate why the board isn't responding correctly.

Jan