Solved

SerialNG read a line

Posted on 2004-04-28
21
900 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
 

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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

759 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

20 Experts available now in Live!

Get 1:1 Help Now