* * *

Author Topic: TComPort  (Read 22552 times)

serbod

  • Full Member
  • ***
  • Posts: 107
Re: TComPort
« Reply #15 on: October 22, 2013, 08:00:58 am »
You can use this:
https://code.google.com/p/dataport/

it use Ararat Synapse serial port, but added some thread-safe routines, events, cross-platform compatibility (tested on Windows and Linux, x86 and ARM processors)

eldonfsr

  • Jr. Member
  • **
  • Posts: 96
Re: TComPort
« Reply #16 on: October 27, 2013, 03:39:13 am »
Is great job but some properties for port are missing databits,  stopbits and other wich ones must have serial port for connect, is rigth or i wrong.

thanks.

serbod

  • Full Member
  • ***
  • Posts: 107
Re: TComPort
« Reply #17 on: October 27, 2013, 11:45:43 am »
All serial port properties can be specified in Open(InitStr). For example, Open('COM1,9600,8,N,1,0,1'). It's preffered way to set, because it supported in all DataPort components and can be easy stored in configuration files.

eldonfsr

  • Jr. Member
  • **
  • Posts: 96
Re: TComPort
« Reply #18 on: October 27, 2013, 08:27:40 pm »
Yeah is true is synapse, i forgot how that set up the serial port ok thanks let me test your components i let you know if found some bug or all is working very well, thanks we still in contact.


maxid

  • Newbie
  • Posts: 2
Re: TComPort
« Reply #19 on: June 11, 2015, 06:12:37 pm »
how use the tcommportdatapacket?
i need send and receive an Record with diferent values

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 620
Re: TComPort
« Reply #20 on: June 13, 2015, 02:07:29 am »
hello,

Reading data in packets
About packets
When application is connected to some sort of serial device like data loggers which constantly send
data to PC, data is usually sent in packets. Packet is a string of characters, usually of constant size,
with some start and/or stop characters. Application can parse incoming data inside OnRxChar
event handler, but its much easier to use TComDataPacket component, which does parsing process
automatically.
One TCustomComPort can have more than one TComDataPacket components linked, so
application can easily recieve packets of different sizes and forms.
When packet is formed OnPacket event is triggered with packet string as parameter. Any data that
is discarded during the process of packet forming goes through OnDiscard event.
If TComDataPacket component is linked to TCustomComPort component, OnRxChar event of
TCustomComPort is not triggered, so application has to use OnRxBuf event handler if it also needs
unparsed incoming data.
Start and stop conditions
Application sets up packet by setting start and stop conditions. This is accomplished by setting
StartString, StopString and Size properties of TComDataPacket component.
If StartString property is not empty, packet starts when StartString string has arrived in input buffer.
If StartString is empty, packet starts immidiately when any charachter arrives in input buffer.
Stop condition is defined by StopString and Size property. If Size is 0, size stop condition is
ignored. If Size is larger than 0, packet is ended when packet size reaches Size charachters. If
StopString is not empty, packet stops when StopString string arrives in input buffer. If Size is larger
than 0 and StopString is not empty, packet is ended when size of packet reaches Size charachters or
StopString string arrives in input buffer. If Size is 0 and StopString is 0 then packet is not defined
and OnPacket has the same effect as OnRxBuf event handler.
Example
Some PBX device sends data to PC in packets, starting with STX (start-of-text) charachter and
ending with ETX (end-of-text) charachter. Before opening serial port, application should set up start
and stop condition like this:
Code: [Select]
begin
 // set start and stop condition for packet
 ComDataPacket1.StartString := #2;
 ComDataPacket1.StopString := #3;
 // now open the port
 ComPort1.Open;
end;
Note
ComDataPacket1 has to be linked to ComPort1 component.

Custom packets
Some packets have specific form and sometimes application can't use standard start and stop
conditions. To form a custom packet, application has write OnCustomStart and/or OnCustomStop
event handler of TComDataPacket component. If OnCustomStart event handler is assigned,
StartString start condition is ignored and it is defined inside event handler. Simillary, if
OnCustomStop event handler is assigned, StopString and Size stop conditions are ignored and
defined in OnCustomStop event handler.
Example
Data from serial device is sent to PC in the following format: #packet_size#packet_data
where packet_size is size of packet including header and packet_data is raw data.
Code: [Select]
var
 CurrentPacketSize: Integer;
procedure ComDataPacket1CustomStart(Sender: TObject; const Str: string; var Pos: Integer);
var
 P1, P2: Integer;
begin
 Pos := 0; // no start position yet
 P1 := System.Pos('#', Str);
 if P1 = 0 then
 Exit; // no start charachter found
 P2 := System.Pos('#', Copy(Str, P1 + 1, Length(Str) – P1)); // second # charachter
 if P2 = 0 then
 Exit; // no second start charachter found
 P2 := P2 + P1;
 Pos := P1; // start position of packet defined at first # charachter
 try
 // determine packet size
 CurrentPacketSize := StrToInt(Copy(Str, P1 + 1, P2 – P1 - 1));
 except
 CurrentPacketSize := P2 – P1 + 1; // packet size is corrupted, cut only #…# part
 end;
end;
procedure ComDataPacket1CustomStop(Sender: TObject; const Str: string; var Pos: Integer);
begin
 if CurrentPacketSize <= Length(Str) then
 Pos := CurrentPacketSize; // set stop position
end;

Friendly J.P
« Last Edit: June 13, 2015, 02:11:26 am by Jurassic Pork »

eny

  • Hero Member
  • *****
  • Posts: 1553
Re: TComPort
« Reply #21 on: June 13, 2015, 06:08:41 am »
how use the tcommportdatapacket?
i need send and receive an Record with diferent values
By not cross posting and creating a new thread with your question.
All posts based on: Win10 (Win64); Lazarus 1.4.2 'stable' (#49524 win32) unless specified otherwise...

katonacs73

  • Newbie
  • Posts: 2
Re: TComPort
« Reply #22 on: March 21, 2016, 11:30:13 am »
Here last chabge to cport lib if some bady using that i hope can help this.

I know that it is an old topic, but I downloaded the given file, tried to install CPortLib on Windows 7 and I still get the error message:
Code: Pascal  [Select]
  1. CPort.pas(28,1) Fatal: Syntax error, "identifier" expected but "TYPE" found
Can anybody tell me what is wrong?

I use Lazarus 1.6 with FPC 3.0, Windows 7 64 bit.
« Last Edit: March 21, 2016, 11:44:32 am by katonacs73 »

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 620
Re: TComPort
« Reply #23 on: March 22, 2016, 02:36:52 am »
hello,
i have no problem to compile and install Tcomport package under Windows 7 64 bits but i use Lazarus 1.6  Windows 32 bits . 

In the begin of the file Cport.pas , have you all the lines in $IFDEF   condition greyed ?   

Code: Pascal  [Select]
  1. (******************************************************
  2.  * ComPort Library ver. 3.0                           *
  3.  * for Free Pascal 2.0.4                              *
  4.  * Writen by HILD Gérald, 2007                        *
  5.  * This work based by the Original comport            *
  6.  *   for Delphi 3, 4, 5, 6, 7 and                     *
  7.  *   C++ Builder 3, 4, 5, 6                           *
  8.  * written by Dejan Crnila, 1998 - 2002               *
  9.  * maintained by Lars B. Dybdahl, 2003                *
  10.  * Homepage: http://comport.sf.net/                   *
  11.  *****************************************************)
  12.  
  13. unit CPort;
  14.  
  15. {$mode objfpc}{$H+}
  16.  
  17. interface
  18.  
  19. uses
  20.   Classes,SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls,
  21.   {$IFDEF WIN32}
  22.   Windows, Messages, IniFiles, Registry;
  23.   {$ENDIF}
  24.   {$IFDEF LINUX}
  25.   libc, KernelIoCtl;
  26.   {$ENDIF}
  27.  
  28. type
  29.   // various types
  30.   TPort = string;

For me the lines in $IFDEF WIN32 are not greyed.

Friendly, J.P

diegobincoletto

  • New member
  • *
  • Posts: 6
Re: TComPort
« Reply #24 on: April 28, 2016, 06:27:14 pm »
I am having problems installing Cportlib10 package.
Im using Lazarus 1.6 on Win7 64

dawid75_75

  • New member
  • *
  • Posts: 14
Re: TComPort
« Reply #25 on: May 15, 2016, 03:07:16 pm »
I work on Win10 x64 and I couldn't install CPortlib 10 on Lazarus 1.6 x64. I had that error:

1.CPort.pas(28,1) Fatal: Syntax error, "identifier" expected but "TYPE" found

Next, I tried to install it on Lazarus 1.6 x86 and it works fine. I have another problem - I can't find a simple example how to use LazSerial or Comport. Is there anybody who has that example or knows where I can find it?

Regards :)

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 620
Re: TComPort
« Reply #26 on: May 15, 2016, 08:18:17 pm »
hello,
tlazserial has an example :  sertest   :P

Friendly, J.P
« Last Edit: May 15, 2016, 08:21:06 pm by Jurassic Pork »

dawid75_75

  • New member
  • *
  • Posts: 14
Re: TComPort
« Reply #27 on: May 19, 2016, 08:02:25 pm »
Yes, sure :) Ok, so I can connect with my uP, but  I have another question - is there any possibility to modify the Setup Dialog? I mean that dialog window which I can call by "ShowSetupDialog" order.
Regards :)

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 620
Re: TComPort
« Reply #28 on: May 19, 2016, 11:52:24 pm »
hello,
what do you want to modify in the setup dialog ?
 

Friendly, J.P

dawid75_75

  • New member
  • *
  • Posts: 14
Re: TComPort
« Reply #29 on: May 19, 2016, 11:58:22 pm »
Hi,
I would like to add some procedures to "OK" and "Cancel" button in that Dialog.
Regards :)

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus