Lazarus
Home
Forum
Help
TinyPortal
Search
Login
Register
Lazarus
»
Programming
»
Packages and Libraries
»
TComPort
Free Pascal
Website
Downloads
Wiki
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
FAQ
Wiki
Bugtracker
Packages
IRC channel
Developer Blog
Follow us on Twitter
Latest SVN
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
Search
Advanced search
« previous
next »
Print
Pages:
1
2
[
3
]
4
Author
Topic: TComPort (Read 31324 times)
Jurassic Pork
Hero Member
Posts: 682
Re: TComPort
«
Reply #30 on:
May 20, 2016, 12:52:46 am »
you can change the source code of the
lazserialsetup.pas
file of the
tlazserial
component :
Code: Pascal
[Select]
procedure
EditComPort
(
ComPort
:
TLazSerial
)
;
begin
with
TComSetupFrm
.
Create
(
nil
)
do
begin
ComComboBox1
.
Text
:
=
ComPort
.
Device
;
ComComboBox2
.
Text
:
=
BaudRateToStr
(
ComPort
.
BaudRate
)
;
ComComboBox3
.
Text
:
=
DataBitsToStr
(
ComPort
.
DataBits
)
;
ComComBoBox4
.
Text
:
=
StopBitsToStr
(
ComPort
.
StopBits
)
;
ComComBoBox5
.
Text
:
=
ParityToStr
(
ComPort
.
Parity
)
;
ComComBoBox6
.
Text
:
=
FlowControlToStr
(
ComPort
.
FlowControl
)
;
if
ShowModal
=
mrOK
then
begin
ComPort
.
Close
;
ComPort
.
Device
:
=
ComComboBox1
.
Text
;
ComPort
.
BaudRate
:
=
StrToBaudRate
(
ComComboBox2
.
Text
)
;
ComPort
.
DataBits
:
=
StrToDataBits
(
ComComboBox3
.
Text
)
;
ComPort
.
StopBits
:
=
StrToStopBits
(
ComComboBox4
.
Text
)
;
ComPort
.
Parity
:
=
StrToParity
(
ComComboBox5
.
Text
)
;
ComPort
.
FlowCOntrol
:
=
StrToFlowControl
(
ComComboBox6
.
Text
)
;
// ComPort.Open;
end
;
Free
;
end
;
end
;
when the
OK
button of the dialog window is clicked you pass in the
if ShowModal = mrOK then
part of the code.
For the
CANCEL
button you must add code.
Friendly, J.P
Logged
dawid75_75
New member
Posts: 14
Re: TComPort
«
Reply #31 on:
May 20, 2016, 01:20:23 am »
Thank you for help
I have one more question - is there any possibility to see the Setup Dialog in project window like I can see, e.g.: TForm1? I'm pretty sure that I saw it when I had opened LazSerial sertest project first time but I closed it immediately. I've got no idea why
Regards
PS: Sorry for my English, it's not my native language
«
Last Edit: May 20, 2016, 01:40:25 am by dawid75_75
»
Logged
Jurassic Pork
Hero Member
Posts: 682
Re: TComPort
«
Reply #32 on:
May 20, 2016, 10:11:29 am »
hello,
you can add the file
Lazserialsetup.pas
from the lazserial package folder to your project (don't copy it just add) .
don't forget if you change anything in the setup dialog form or in the pascal file , it is the Tlazserial component that is modified.
See Attachment
As you can see in the attachment, English is not my natural language
Friendly, J.P
Logged
dawid75_75
New member
Posts: 14
Re: TComPort
«
Reply #33 on:
May 20, 2016, 10:35:56 pm »
Hello,
I did what you wrote but when I am choosing Setup form in 'View Project Forms' window Lazarus opens it in source editor and I still can't see it in project window. How can I open it in project window?
Regards
Logged
Jurassic Pork
Hero Member
Posts: 682
Re: TComPort
«
Reply #34 on:
May 20, 2016, 11:26:34 pm »
hello,
what is your O.S and your lazarus version ?
can you show me your project inspector window ?
Friendly, J.P
Logged
dawid75_75
New member
Posts: 14
Re: TComPort
«
Reply #35 on:
May 21, 2016, 10:39:58 am »
Hello,
I work on Win10 x64 and Lazarus 1.6 32bit.
Screen is in the attachment.
Regards
Logged
Jurassic Pork
Hero Member
Posts: 682
Re: TComPort
«
Reply #36 on:
May 21, 2016, 11:33:07 am »
hello,
you use Tcomport not Tlazserial ?
Logged
dawid75_75
New member
Posts: 14
Re: TComPort
«
Reply #37 on:
May 21, 2016, 12:42:17 pm »
Hello,
My professor asked me to do it by TComport but finally I'll use LazSerial. I noticed that LazSerial works more stable
Now I'm just practising establishing connection between PC and atmega and I have to show working software to my professor. Next I'll rewrite my soft on LazSerial
So again - how can I open and edit Setup Dialog?
«
Last Edit: May 21, 2016, 01:04:32 pm by dawid75_75
»
Logged
dawid75_75
New member
Posts: 14
Re: TComPort
«
Reply #38 on:
May 21, 2016, 04:19:09 pm »
Ah, to the hell with TComport, I rewrote my soft with LazSerial
Screen is in attachment.
I have one more question - when I was reading LazSerial.pas file I found that line:
// function ReadBuffer(var buf; size: integer): integer;
Why this line is inactive? In the future I will in need of receiving numerical data from Atmega and that line - receiving numbers, not strings - will be very, very helpful. For what reason that instruction is inactive?
Logged
Jurassic Pork
Hero Member
Posts: 682
Re: TComPort
«
Reply #39 on:
May 22, 2016, 09:18:23 am »
hello,
don't worry for this inactive line (tlazserial is based on 5dpoSerial and in this package the line is inactive).
Tlazserial works with binary data :
Example :
project to send binary data on a port and received data on another port :
Procedure to send binary data :
Code: Pascal
[Select]
procedure
TFMain
.
BSendDataClick
(
Sender
:
TObject
)
;
var
TempList
:
TstringList
;
mBuffer
:
array
[
0
..
100
]
of
Byte
;
x
:
Integer
;
begin
TempList
:
=
TStringList
.
Create
;
{ construire l'objet liste }
TempList
.
CommaText
:
=
OutputData
.
Text
;
//OutData TEdit comma formated hexa data
For
x
:
=
0
to
TempList
.
Count
-
1
do
begin
mBuffer
[
x
]
:
=
StrToInt
(
'$'
+
TempList
[
x
]
)
;
End
;
Serial1
.
WriteBuffer
(
mBuffer
,
TempList
.
Count
)
;
// Timer1.Enabled := True;
end
;
Procédure to receive data from the other serial port (the Two Serial ports aree linked) :
Code: Pascal
[Select]
procedure
TFMain
.
SerialRxData
(
Sender
:
TObject
)
;
var
S
,
HexaS
:
string
;
i
:
integer
;
begin
S
:
=
Serial
.
ReadData
;
for
I
:
=
1
to
Length
(
S
)
do
begin
HexaS
:
=
HexaS
+
InttoHex
(
Ord
(
S
[
I
]
)
,
2
)
+
' '
;
end
;
if
Length
(
S
)
>
0
then
Memo
.
Lines
.
Add
(
HexaS
)
;
end
;
the Receive procedure display the received data in Hexa in the memo control.
Friendly, J.P
Logged
dawid75_75
New member
Posts: 14
Re: TComPort
«
Reply #40 on:
November 03, 2016, 12:02:26 am »
Hello everyone again
I've been working in Lazarus for a while and I've got problem. I receive data by TComPort and some data are corrupted. How do I know it? I just see the same data in Realterm without any problem.
I'll tell you what is going on - I receive by COM packet of 13 bytes of data. Every packet starts from 0x01 end ends by 0x04. In Realterm I can see all packets in good condition, nothing is lost. But in Lazarus in TComPort about 20% of packets are corrupted, e.g. some bytes are lost or some bytes have different values than real ones.
I receive packet by this code:
Code: Pascal
[Select]
Serial
.
Read
(
RxBuffer
,
Count
)
;
in
OnRxChar
event.
What can cause that behaviour? If you Guys have any idea, please, answer
BR,
Dawid.
«
Last Edit: November 03, 2016, 01:03:49 pm by dawid75_75
»
Logged
Jurassic Pork
Hero Member
Posts: 682
Re: TComPort
«
Reply #41 on:
November 03, 2016, 12:54:47 am »
hello,
see
here
for
Reading data in packets
.
Friendly, J.P
Logged
dawid75_75
New member
Posts: 14
Re: TComPort
«
Reply #42 on:
November 03, 2016, 11:11:15 am »
Hello,
thanks for your reply
I did it and situation looks better.
But something still happens.
My data packet looks like this:
StartString:=#1
StopString:=#4
Example packet (dec values):
1 107 4 139 57 42 44 85 255 58 212 63 4
This is all procedure I receive data and show it on ListBox:
Code: Pascal
[Select]
procedure
TMainWindow
.
DataPacketPacket
(
Sender
:
TObject
;
const
Str
:
string
)
;
const
FrameStartPos
=
0
;
const
FrameEndPos
=
12
;
var
RxBuffer
:
array
[
1
..
FrameEndPos
+
1
]
of
Byte
=
(
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
)
;
c
:
Integer
=
0
;
i
:
integer
=
0
;
licznik
:
Integer
=
0
;
NStr
:
String
;
begin
for
i
:
=
1
to
13
do
begin
c
:
=
ord
(
Str
[
i
]
)
;
RxBuffer
[
i
]
:
=
c
;
end
;
i
:
=
0
;
NStr
:
=
' '
;
for
i
:
=
1
to
13
do
begin
NStr
:
=
NStr
+
IntToStr
(
RxBuffer
[
i
]
)
+
' '
;
//ComMemo.Text:=ComMemo.T
end
;
if
(
(
RxBuffer
[
1
]
<>
1
)
Or
(
RxBuffer
[
13
]
<>
4
)
)
then
begin
BadDataCnt
:
=
BadDataCnt
+
1
;
BadData
.
Caption
:
=
IntToStr
(
BadDataCnt
)
;
end
;
Listbox1
.
Items
.
Add
(
NStr
)
;
Serial
.
ClearBuffer
(
true
,
true
)
;
end
;
Most of data is correct, but some data has changed order. I mean that:
139 57 42 44 85 255 58 212 63 4 (1 107 4) -> Should be on the beginning of the packet.
As you can see, first three elements are on the end of the packet, and I don't know why.
I noticed that I got all packet when I set Size in TDataPacket on 14, but I've got 13 bytes in packet.
Any ideas about all of that?
Regards,
D.
«
Last Edit: November 03, 2016, 11:26:21 am by dawid75_75
»
Logged
Jurassic Pork
Hero Member
Posts: 682
Re: TComPort
«
Reply #43 on:
November 03, 2016, 12:47:45 pm »
hello dawid75_75,
Something is strange in your packet :
Quote from: dawid75_75 on November 03, 2016, 11:11:15 am
Example packet (dec values):
1 107 4 139 57 42 44 85 255 58 212 63 4
and also you say :
Quote
Every packet starts from
0x00
EDIT : rectify in his primary message by dawid
you have a stopstring inside your packet, so it isn't a stop string. is it possible to have also a #1 inside your packet ?
Can you show us some lines of what you receive exactly (without format or filter ) ?
Friendly, J.P
«
Last Edit: November 03, 2016, 01:10:09 pm by Jurassic Pork
»
Logged
dawid75_75
New member
Posts: 14
Re: TComPort
«
Reply #44 on:
November 03, 2016, 01:19:55 pm »
Ah, I made a mistake.
Every packet starts from 0x01
(I corrected that in a post above). And I set StartString:=#1.
And actually it is possible to have 0x01 and 0x04 inside a packet which are not a start/stop strings. In fact, I thought that isn't a problem when I set Size in DataPacket. Am I wrong? Will program crash when I receive start or stop string inside a packet?
Raw data in software I wrote in Lazarus are ASCII characters corresponding to decimal values I send by COM to the program. Next action is getting their decimal values to the RxBuffer and finally IntToStr function to show them in ListBox. I am not in the house now, I send some lines later, but now I can tell that most of packets look correct, like this:
StartString:=#1 ->
1 107 4 139 57 42 44 85 255 58 212 63 4
<-StopString:=#4, all packet = 13 bytes.
but some packets have changed order like this:
missed first three bytes ->
139 57 42 44 85 255 58 212 63 4
<- Stop character equals 0x04; start character equals 0x01 ->
1 107 4
and these three bytes are
moved from the beginning to the end of string
.
«
Last Edit: November 03, 2016, 01:23:30 pm by dawid75_75
»
Logged
Print
Pages:
1
2
[
3
]
4
« previous
next »
Lazarus
»
Programming
»
Packages and Libraries
»
TComPort
Recent
Material Design
by
lainz
[
Today
at 03:58:40 am]
Lack of SSL on wiki?
by
tvleavitt
[
Today
at 03:58:16 am]
LAMW: Android 7.1.2
by
jmpessoa
[
Today
at 03:56:42 am]
MacOS Installation is a m...
by
tvleavitt
[
Today
at 03:38:26 am]
macOS 32-bit app warning
by
dbannon
[
Today
at 02:43:13 am]
An advice - um conselho
by
hrayon
[
Today
at 01:58:27 am]
Ubuntu Launcher not using...
by
soerensen3
[
Today
at 12:29:27 am]
[solved] indy IRC and Uml...
by
mica
[
Today
at 12:12:39 am]
Find text
by
justnewbie
[April 20, 2018, 11:59:00 pm]
Compiler can't find TPU f...
by
CzarAlex
[April 20, 2018, 10:11:33 pm]