Topic: Com Port Receive Buffer

Hello,
I have been using the COM port to receive data and it has been fine when receiving about 12 bytes of data, which is all I have required till now.
My new project consists of a microcontroller which is collecting telemetry, forming a text string about 50 bytes long, and that goes into the PC COM port. I started out using the standard COM port example from Dmitry as it receives COM port data and adds each newly received line into a Memo field. I did this to see how the data looks and to use it as a starting place.
Now when it receives 50 bytes of incoming data, it adds a line to the Memo field but it is only the first 31 bytes of the received data and then it adds the remaining 19 or so bytes in the following line. The entire string consists of 8 sections which are all comma delimited and when I use the SplitString function, it only splits up the data which appears in the second line of the newly added data in the memo field.
I know it is difficult to describe as I have hardware involved as well but I hope it makes some kind of sense.
Dmitry, is there some limit to the receive buffer size which could be causing this problem? Also is it possible to add a function that can report how many bytes of data are in the receive buffer? Some software allows being able to set the size of the receive buffer and that would be good too.
Thanks,
David

Re: Com Port Receive Buffer

Hello.


Please attach your project with examples of data.

Dmitry.

Re: Com Port Receive Buffer

Hello Dmitry,
Thanks. Please find the project attached and a screenshot is included in the zip file.
The string read into the COM port is about 50 characters and it arrives with the commas in place, just as you see it on the screen except when it is received in the MVD application, it splits the data across two lines. Then when I use the SplitString function, it only acts on the second line that appears in the window. Really I need to be able to split the string into its 8 parts.
I have tried several other serial communications programs and they always display the data as a single line each time a transmission is received.
I am using the latest version of MVD.
Once we get past this situation, I need to add another 20 to 30 bytes to each telemetry string.
Thanks for your help.
Regards,
David

Post's attachments

Attachment icon TelemetryTest.zip 383.26 kb, 393 downloads since 2018-01-08 

Re: Com Port Receive Buffer

Hello Again,
please see the attached image which shows the data arriving and being displayed on another serial communication program. Each transmission is correctly displayed as a single line.
Thank you for your help, David.

Post's attachments

Attachment icon CorrectDataDisplay.PNG 12.05 kb, 226 downloads since 2018-01-09 

Re: Com Port Receive Buffer

Hello.


Check it out

procedure OnRecieveComData(Sender: TObject; Data: string);
var
    sLine: string;
begin

    sLine := sLine + Data;
    if Pos(Data, #13) > 1 then
    begin
      sLine := ReplaceStr(sLine, #13, '');
      sLine := ReplaceStr(sLine, #10, '');
      TelemetryArray := SplitString(sLine, ',');
      Form1.Label6.Caption := TelemetryArray[0];
      Form1.Label7.Caption := TelemetryArray[1];
      Form1.Label8.Caption := TelemetryArray[2];
      Form1.Memo1.Lines.Add(sLine);
      sLine := '';
    end;
end;

If not working, please attach text file with data from Memo. I need real data from COM port, not just picture of data.

Dmitry.

Re: Com Port Receive Buffer

Thanks Dmitry,
When running the code you supplied, there is no data at all added to the memo field. I added a couple of lines as below.

procedure OnRecieveComData(Sender: TObject; Data: string);
var
    sLine: string;

begin
sLine := sLine + Data;
    if Pos(Data, #13) > 1 then
    begin
      sLine := ReplaceStr(sLine, #13, '');
      sLine := ReplaceStr(sLine, #10, '');
      TelemetryArray := SplitString(sLine, ',');
      Form1.Label6.Caption := TelemetryArray[0];
      Form1.Label7.Caption := TelemetryArray[1];
      Form1.Label8.Caption := TelemetryArray[2];
      Form1.Memo1.Lines.Add(sLine);
      sLine := '';
    end;
    Form1.Memo1.Lines.Add(sLine);        // Added by David
    sLine := '';                                                  // Added by David
end;

With the modified code as above, I get the data printed out again but in the incorrect way still.
I have checked the code for the micro controller and there is no control codes are anything else added. It is just simply ASCII characters.
Then I changed the code in the micro controller so it would send a shorter string. The problem remained in that the text added to the MEMO box is still spread over two lines.
I have now tried four other software programs which all display the received data correctly with the complete string as a single line.
Please find a text file attached which has data recorded with a comms program..
thanks and regards,
David

Post's attachments

Attachment icon RecordedTelemetry.TXT 3.03 kb, 546 downloads since 2018-01-10 

Re: Com Port Receive Buffer

I need data from memo component from your project, like on screenshot TelemetryTest.PNG
Not from another comms program.

Dmitry.

Re: Com Port Receive Buffer

Hello Dmitry,
I added a button with the command
Form1.Memo1.Lines.SaveToFile('c:\Telemetry\MemoText.txt');
as you will see in the attachment. The saved file MemoText.txt is in the zip file. Please let me know if I need to get the data in some other way.
Thanks,
David

Post's attachments

Attachment icon TelemetryTest2.zip 337.98 kb, 390 downloads since 2018-01-11 

Re: Com Port Receive Buffer

Check it out

procedure OnRecieveComData(Sender: TObject; Data: string);
var
    sLine: string;
begin
    sLine := sLine + Data;
    if Pos(#13, Data) > 1 then
    begin
      sLine := ReplaceStr(sLine, #13, '');
      sLine := ReplaceStr(sLine, #10, '');
      TelemetryArray := SplitString(sLine, ',');
      Form1.Label6.Caption := TelemetryArray[0];   
      Form1.Label7.Caption := TelemetryArray[1];
      Form1.Label8.Caption := TelemetryArray[2];
      Form1.Memo1.Lines.Add(sLine);
      sLine := '';
    end;
end;

was mistake in this line
Pos(#13, Data)

Dmitry.

10 (edited by radsoft 2018-01-16 21:48:50)

Re: Com Port Receive Buffer

Hello Dmitry,
Thanks, that has solved it.
Still curious about these characters 13 and 10, I changed the two ReplaceStr lines to replace them with 'xx' and 'yy' as in the code below. The data lines print as they should with each transmission printed on a single line but now with xxyy on the end of each line. That isn't really expected. I attached a screenshot. Does this indicate something strange going on?

procedure OnRecieveComData(Sender: TObject; Data: string);
var
    sLine: string;
begin
    sLine := sLine + Data;
    if Pos(#13, Data) > 1 then
    begin
      sLine := ReplaceStr(sLine, #13, 'xx');                  // Radsoft
      sLine := ReplaceStr(sLine, #10, 'yy');                  // Radsoft
      TelemetryArray := SplitString(sLine, ',');
      Form1.Label6.Caption := TelemetryArray[0];   
      Form1.Label7.Caption := TelemetryArray[1];
      Form1.Label8.Caption := TelemetryArray[2];
      Form1.Memo1.Lines.Add(sLine);
      sLine := '';
    end;
end;

Regards,
David

Post's attachments

Attachment icon TelemetryDisplayWithxxyy.PNG 22.08 kb, 224 downloads since 2018-01-16