Solved

SerialNG read a line

Posted on 2004-04-28
21
913 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

742 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