Solved

nrComms

Posted on 2014-03-07
10
447 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now