Solved

SerialNG read a line

Posted on 2004-04-28
21
912 Views
Last Modified: 2011-10-03
Im trying to get SerialNG to read until the end of line any examples would be great.
Thanks in advice

Edit: Here is the link http://www.domis.de/cms/index.php?module=ContentExpress&func=display&ceid=8
Tom
0
Comment
Question by:T0masz
  • 9
  • 3
  • 3
  • +3
21 Comments
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10942846
Never heard of it, you may want to post code related to what youa re doing, to see if we can suggest a fix that way

Shane
0
 

Author Comment

by:T0masz
ID: 10942935
Im writing a service that would read a line from a serial port phrase the line, then write it to a file/database.

Tom
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10942961
Well, for those of us who have never heard of,  let alone used,  such control, we will need to see your attempt at doing it. DO you have any code where you tried it yourself.  We have no idea what the Properties, Methods, or Events of the control are..... Im assuming it has some basic functionality like most serial components though...

Shane
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

 

Author Comment

by:T0masz
ID: 10943007
The SerialNG has 2 ways of getting data, onclusterrx or oncharrx, the cluster doesnt really work for me since it stops reading the cluster after certain amount of data,time. So I figured I would use onrxcharevent and read every character add it onto a string until \n then phrase the string append to a file.

Tom
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10943072
You still haven't posted any of the code on your attempt....can we see it...

Shane
0
 

Author Comment

by:T0masz
ID: 10943545
procedure TForm1.Timer1Timer(Sender: TObject);
var i : Integer;
begin
 SerialPortNG1.Active := True;
 if not SerialPortNG1.Active then
    begin
      memoResult.Lines.Add('Error: Port could not be opened');
      Exit;
    end;
  if SerialPortNG1.NextClusterSize >= 0 then
        memoResult.Lines.Add(SerialPortNG1.ReadNextClusterAsString);
  end;

For now this reads the cluster every second, I have no clue what it treats as a cluster tho...

Tom
0
 
LVL 17

Expert Comment

by:mokule
ID: 10943836

I'll suggest You reading from serial port without any component.
It's really easy.
Several lines of code or so and You've got full control of what You are doing.

0
 

Author Comment

by:T0masz
ID: 10944180
anyone have an idea how to seperate the cluster into strings? I was thinking about separating them by \n or something but im still working on it.

Tom
0
 
LVL 3

Expert Comment

by:Kunfufaresi
ID: 10944583
Hello,

I would suggest use event if possible and not timer, buffer might get filled up in less than a second or maybe you might reduce it to 50ms. Seperating the cluster string(!) wouldnt be a problem if it has a repeating sequence for marking eoln. Although if you told us more about the input device and what sort of data you are trying to aquire, does it have linebreaks it might help, for instance i'm not much good with serial input, but is your hardware 8bit? if it is 4bit then the eoln code could be hidden inside the character and you would have to deal with it on bit level.

Kunfu Faresi
0
 

Author Comment

by:T0masz
ID: 10944646
its a 8bit phone call monitor, I tried using this function but couldnt get it to seperate by \n

--snip--
function split(input:string;schar:char;s:integer):string;
    var
       i,n:integer;
       schop: string;
    begin
       n := 1;
       for i := 1 to length(input) do
       begin
         if (input[i] = schar) then
         begin
           inc(n);
           if n = s then
           split := schop
           else
           schop := '';
           end
         else
           schop := schop + input[i];
         end;
    end;
--snip---
0
 
LVL 17

Expert Comment

by:mokule
ID: 10944695

I can see some strange things in this function. Maybe I don't understand.

Could You write what was it supposed to do?
0
 

Author Comment

by:T0masz
ID: 10944718
it should returns the Nth string that matches the schar so lets say in a string "1 2 3" split(string," ",2); would return 2

Tom
0
 
LVL 3

Expert Comment

by:Kunfufaresi
ID: 10944844
maybe your break is chr(9) or something similar have you tried dumping it as ascii values from serial port  using something like
---snip--
var
 s,s2:String;
 i:integer;
begin
 s2 := 'abc';
 for i := 1 to length(s2) do
  s := s + inttostr( ord( s2[i] ) );
---snip--

where s2 is what you get from serial port? there are some characters that would look like a space in some controls but actually has some other like value chr(9) TAB.

Kunfu Faresi
0
 
LVL 17

Expert Comment

by:mokule
ID: 10944871
1.
function split(input:string;schar:char;s:integer):string;
    var
       i,n:integer;
       schop: string;
    begin
       n := 1;
       for i := 1 to length(input) do
       begin
         if (input[i] = schar) then
         begin
           inc(n);
           if n = s then
           begin
           split := schop;
           break;              // no need to check further
           end
           else
           schop := '';
           end
         else
           schop := schop + input[i];
         end;
// to allow return 3 from your example
        if n=s-1 then
         split := schop;
    end;

2. You wanted to have schar=\n ?
   But what do you mean by \n #10, #13 or #10#13
0
 

Author Comment

by:T0masz
ID: 10963237
Sorry, I was on a one day trip, couldnt respond, I have no clue what the answer to #2 is... any way to check? I hooked up a cisco router to my serial port and it reads everything just fine,  but now I have to split the clusters by newline chars then for every line phrase and save it, and with the rest of the string ( after \n ) I would have to store it, and then reattach it the next time the cluster event happends. And I still cant get it to split by the newline char.

Tom
0
 
LVL 1

Expert Comment

by:mornao
ID: 10987210
I use serial ports for all sorts of things - and have found SerialNG at the difficult end.

I use AsyncFree without any difficulties, - with that you can build up whatever strings you like as they appear at the port, then any string parser would do - even Delphi's inbuilt one.

Newline characters (\n in C) have two meanings depending on platform - Windows and Unix. In essence it is not a character but a sequence depending on platform.

One interprets '\n' as
 Delphi                #13, the other as #13#10
 Hex                    h0D        -           h0D0A,
 Ascii symbology   CR          -           CR,LF
, though which requires what I am unsure. One platform cares, the other does not (as it automatically puts in the LF, Linefeed, #10, h0A)  

 
0
 

Author Comment

by:T0masz
ID: 10997240
I tried splitting the lines but Its all messed up, can anyone post a working example ( using any component ) that would just read the line and display/write it somewhere. I would really appreciated, since I have no clue how to do it myself using SerialNG...
Tom
0
 

Author Comment

by:T0masz
ID: 11008003
uciacomport did the trick, great component.

Tom
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 13302472
PAQed with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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