Solved

nrComms

Posted on 2014-03-07
10
443 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

746 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

11 Experts available now in Live!

Get 1:1 Help Now