ComPort Programming

Posted on 1999-07-30
Medium Priority
Last Modified: 2012-06-27
Any one has experience in using AnsyPro TApdComPort and TApdDataPacket?
My question is how to get data unknown length and end condition. How to get data partially?

Question by:ysimon

Expert Comment

ID: 1392042
Since you don't seem to have gotten an answer here, I'd suggest posting your question to TurboPower's newsgroups.


Accepted Solution

Worminator earned 100 total points
ID: 1392043
As I understand it all you want to do is recieve data periodically as you do not know what the length of the packet is or its end condition. Here is a code sample that will display incoming data in a memo box.

procedure TForm1.InComTrigger(CP: TObject; Msg,   TiggerHandle,Data: Word);
  C       : Char;
  InData  : String;
  Case Msg of
    //Normal Incoming data
    apw_TriggerAvail :
        if memIncomingData.Lines.Count <> 0 then
          Indata := memIncomingData.Lines[memIncomingData.Lines.Count-1]
          Indata := '';

        //For the Current no of bytes of data in the buffer do
        While Data > 0 do
          //Fetch the next character in the buffer
          C := Incom.GetChar;

          //Add that Character to the exsisting data
          Indata := InData + C;
        end;//While statement

        //If we are not at the end of the line in the memo box then we need t0
        //add the new data to the existing line
        If(Indata<>'') then
          if memIncomingData.Lines.Count <> 0 then
            memIncomingData.Lines[memIncomingData.Lines.Count-1] := Indata
           //Add new data to the next new                memIncomingData.Lines.Add(Indata);
      end;//apw_TriggerAvail :

  end;//Case Msg of

Sorry about the messy looking code but I cut and pasted it from the Delphi IDE and this edit box sucks.

This code needs to be added to the InComTrigger event of the TApdmPort component.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
How to fix display issue, screen flickering issue when I plug in power cord to the machine. Before I start explaining the solution lets check out once the issue how it looks like after I connect the power cord. most of you also have faced this…
In the video, one can understand the process of resizing images in single or bulk. Kernel Bulk Image Resizer is an easy to use tool for resizing large number of images. One can add and resize multiple images with this tool in single go. The video sh…

624 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