Solved

nrComms

Posted on 2014-03-07
10
468 Views
Last Modified: 2014-03-09
Using nrcomm1 component with a tRichEdit Called memoDMS

Settings

nrComm1.ComPort := cpCom1;
nrComm1.Terminal := memoDMS;
nrComm1.active := true;

comm port is correct
nrComm1AfterReceive is triggered but no data is shown in the tRichedit component
I have other programs working correctly with this setup

Help
0
Comment
Question by:Kevinfeening
  • 5
  • 5
10 Comments
 
LVL 24

Expert Comment

by:jimyX
ID: 39914361
Haven't used nrComm before.

But normally there are other settings (Baud rate, data bits, ...etc). Have you set everything inline with the other programs' settings?

You need to set everything in order to be able to send/receive through the com port.
0
 

Author Comment

by:Kevinfeening
ID: 39915254
Sorry I didn't explain
I copied and pasted the tNRComm and tRichedit so all setting are the same
attached is a word doc with the settings

All the program does is after the richedit has got the data then
I copy the data to a file

  assignFile(filename,ePath.text);
  rewrite(filename);
  append(filename);
  memoDMS.Refresh;
  for l := 0 to 10000 do begin
      if memoDMS.Lines.Strings[l] = '' then break;
      if memoDMS.Lines.Strings[l] <> '' then
         writeLn(filename,memoDMS.Lines.Strings[l]);
  end;

but the 2nd program has no information in the tRichedit but the tRichedit.onafterreceive
event triggers in both programs
Comms.docx
0
 
LVL 24

Expert Comment

by:jimyX
ID: 39915469
So you confirm that you have successfully connected to the port.
And you can send receive from that port but the only problem you have is that, the data received does not appear in the "memoDMS" RichEdit.

First here are some improvements to your code:

- Use Append no need to Rewrite if the file exists:

  assignFile(filename,ePath.text);
  if FileExists(ePath.text) then
    append(filename)
  else
    rewrite(filename);

Open in new window


- Do not waste resources an cycle unnecessarily around lines that might not exist.
Use actual number of lines to iterate "memoDMS.Lines.Count".

Do you want to quit reading lines if the current line is empty?

If what you read might include empty lines, then do not just quit the loop by "break" after detecting the first empty line, you have the exact number of lines to read and you will save the non-empty lines only, this way:
  for l := 0 to memoDMS.Lines.Count-1 do begin
      if memoDMS.Lines.Strings[l] <> '' then
         writeLn(filename,memoDMS.Lines.Strings[l]);
  end;

Open in new window


Or even better save the content of the memoDMS to a local variable, and then save to file form that variable, to avoid the RichEdit getting flushed with the next read before saving.

Second can you explain more on what you read and how does the other program work?
Does a TTimer do the reading from the port or you click a Button?
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:Kevinfeening
ID: 39915517
Thanks for the coding tips

But as I said the first program memodms id populated with data from the comms port
and can be exported to a text file and be seen on screen

The second program  memodms has not data displayed
0
 
LVL 24

Expert Comment

by:jimyX
ID: 39915544
>   coding tips
That was side notes, not related to the issue (at least directly).

Any input for the following?
>   So you confirm that you have successfully connected to the port.
>   And you can send receive from that port but the only problem you have is that, the data received does not appear in the "memoDMS" RichEdit.

>   can you explain more on what you read and how does the other program work?
Does a TTimer do the reading from the port or you click a Button?
0
 

Author Comment

by:Kevinfeening
ID: 39915550
Coding Tips
I actually meant thanks

Any input for the following?
>   So you confirm that you have successfully connected to the port.

Successfully connected

>   And you can send receive from that port but the only problem you have is that, the data received does not appear in the "memoDMS" RichEdit.

Yes it works in the first program not the second

>   can you explain more on what you read and how does the other program work?
Does a TTimer do the reading from the port or you click a Button?

both programs the timer allows the user to see the data before copying to the text file then memdms.clear is used
0
 
LVL 24

Expert Comment

by:jimyX
ID: 39915559
Something does not seem logical here.
If one program can connect then the other should do.

Let's go through the differences between the two programs:
1. Which Delphi version of each.
2. Can you post the code that does sending receiving from the port.
0
 

Author Comment

by:Kevinfeening
ID: 39915568
I know that's why I asked

both are on the same Delphi version

no code is used only the Nrcomm1 protocol with the settings given before for the baud rate
comport  etc and the terminal set to memoDMS

I shows data in the Memo and the other one doesn't
0
 
LVL 24

Accepted Solution

by:
jimyX earned 500 total points
ID: 39915691
Are you sure there is no any option forgotten somewhere?

This can be one of the situations where you catch one silly tiny thing, that has slipped, and you find it after flipping the project.

If you can, please attach both projects (pas & dfm), after removing whatever sensitive data that you do not want to expose (if any).
0
 

Author Comment

by:Kevinfeening
ID: 39916676
Changes the trichedit to tmemo and now works fine

Thanks for you time
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Tviruailstringtree sort multi columns on header click 1 77
Delphi inherited method 6 76
Delphi Yen format 3 45
DBCtrlGrid, Delphi, Scroll 8 39
In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question