pr2501
asked on
Comunication with PC and MCU over RS232.
My APP consist of two edit boxes:
Edit1Read for TX (transfer data from variable "outMCU") and
Edit2Write for RX (receive data into variable " inMCU").
Whats the way to approach to this problem?
Edit1Read for TX (transfer data from variable "outMCU") and
Edit2Write for RX (receive data into variable " inMCU").
Whats the way to approach to this problem?
ASKER
outMCU and inMCU are two variables in MCU.
Edit1 box is for showing data from MCU and Edit2 is for sending data to MCU.
MyAPP should use RS232 protocol for communication between PC and MCU.
I can't do that.
Edit1 box is for showing data from MCU and Edit2 is for sending data to MCU.
MyAPP should use RS232 protocol for communication between PC and MCU.
I can't do that.
RS232 is not a protocol, but a transport mechanism.
There is a good, easy and opensource RS232 driver here: http://sourceforge.net/projects/comport/
There is a good, easy and opensource RS232 driver here: http://sourceforge.net/projects/comport/
ASKER
It's some time that i had not worked with Turbo Delphi.
Pleas, explain me how to add libraries to all other Delphi libraries
and how add TComport object to Tool palete.
Pleas, explain me how to add libraries to all other Delphi libraries
and how add TComport object to Tool palete.
ASKER
I have Turbo delphi.
While trying to install com port components i get next error:
This version is not licensed to load third-parity components or IDE addins.
While trying to install com port components i get next error:
This version is not licensed to load third-parity components or IDE addins.
need protocol of MCU data exchange for writing simple code.
Other way:
uses OoMisc, AdPort;
procedure doit;
var rs:TApdComPort
Begin
rs:=TApdComPort.create(nil );
try
rs.ComNumber:=1;//com number
rs.Baud:=19200;//baud rate
rs.Open:=true;
rs.PutString('Hello, MCU, love Y');
...read help for asyncpro suite, http://sourceforge.net/projects/tpapro/
finally
rs.destroy;
end;//try
end;
Other way:
uses OoMisc, AdPort;
procedure doit;
var rs:TApdComPort
Begin
rs:=TApdComPort.create(nil
try
rs.ComNumber:=1;//com number
rs.Baud:=19200;//baud rate
rs.Open:=true;
rs.PutString('Hello, MCU, love Y');
...read help for asyncpro suite, http://sourceforge.net/projects/tpapro/
finally
rs.destroy;
end;//try
end;
ASKER
Ustin19
Thank you:
I'LL begin to work on it this evening.
Thank you:
I'LL begin to work on it this evening.
ASKER
To install TurboPower APRO into your IDE, take the following steps:
1. Unzip the release files into a directory (e.g., d:\apro).
2. Start Delphi or C++Builder.
3. Add the source subdirectory (e.g., d:\apro\source) to the IDE's
library path.
4. Open & compile the runtime package specific to the IDE being
used.
5. Open & install the designtime package specific to the IDE being
used. The IDE should notify you the components have been
installed.
I have problem at point 3.
What must i write into atached picture in the Library path field if my files are located at
C:\Program Files\AsyncPro\source?
path.bmp
1. Unzip the release files into a directory (e.g., d:\apro).
2. Start Delphi or C++Builder.
3. Add the source subdirectory (e.g., d:\apro\source) to the IDE's
library path.
4. Open & compile the runtime package specific to the IDE being
used.
5. Open & install the designtime package specific to the IDE being
used. The IDE should notify you the components have been
installed.
I have problem at point 3.
What must i write into atached picture in the Library path field if my files are located at
C:\Program Files\AsyncPro\source?
path.bmp
ASKER
And it looks next problem(obstacle) still remains.
This version is not licensed to load third-parity components or IDE addins.
ASKER
Another thing way this this downloaded packet is exe file?
19exe.bmp
19exe.bmp
IDE is not licensed, but you CAN write
uses somethirdpartyfile
and create\destroy components in runtime (as in my examle above)
uses somethirdpartyfile
and create\destroy components in runtime (as in my examle above)
ASKER
After adding of OoMisc, AdPort (pas) to my project i get next error:
[Pascal Fatal Error] OoMisc.pas(42): F1026 File not found: 'AWDEFINE.INC'
Where do i get missed file and where to copy it?
{Global defines potentially affecting this unit}
{$I AWDEFINE.INC}
ASKER
I got it. It is in:
C:\Program Files\Borland\BDS\4.0\sour
What must i do to resolve this problem?
ASKER
Forget my last question.
At my home PC everething compiles fine.
Now can yo pleas write me code for simple comunication betwin PC and MCU.
Just a form with two tedits.
One for transmit (after a button is pushed) and other for reading 3 ASCII characters when they come from MCU?
At my home PC everething compiles fine.
Now can yo pleas write me code for simple comunication betwin PC and MCU.
Just a form with two tedits.
One for transmit (after a button is pushed) and other for reading 3 ASCII characters when they come from MCU?
it is NO WAY to write universal code sample, which will work with all devices :)
So, i need mcu datasheet (at least, good is to use sample unit in lab) for do this sample. AFAIR, OnData event represents the RX data coming event, putstring\putchar methods invokes TX wire to send data. MCU can use any set of signals (fe DRS, RI etc) wires state up or down before sending\receiving data, this is depending ONLY FROM MCU. Read datasheet and all will be all right :)
So, i need mcu datasheet (at least, good is to use sample unit in lab) for do this sample. AFAIR, OnData event represents the RX data coming event, putstring\putchar methods invokes TX wire to send data. MCU can use any set of signals (fe DRS, RI etc) wires state up or down before sending\receiving data, this is depending ONLY FROM MCU. Read datasheet and all will be all right :)
ASKER
Thank you very much.
1.
It is that i have done all this work in the past with PIC MCU (assembler) and with Java.
And there were more that a year of hard work.
2.
Now i'm on ATmega8535 (Pascal) and Delphi.
In my school times(point1) i used first to communicate with Hyper terminal (windows).
And in my case have done all the work MCU (it sends characters and recives them (elaborate data) by
MCU code).
Now i have intention to do it in same way.
I'm able to send characters itch 3 seconds from mcu and see them in Hyper terminal (communication program).
And if i type a character into Hype terminal my mcu can switch an output on.
First:
My Delphi app has to
- constantly check if character over the serial com port has arrived
- or to recognize an interrupt in that case.
Second:
Just to send data forward when it get it in specific buffer (or when specific variable is different of initial value).
1.
It is that i have done all this work in the past with PIC MCU (assembler) and with Java.
And there were more that a year of hard work.
2.
Now i'm on ATmega8535 (Pascal) and Delphi.
In my school times(point1) i used first to communicate with Hyper terminal (windows).
And in my case have done all the work MCU (it sends characters and recives them (elaborate data) by
MCU code).
Now i have intention to do it in same way.
I'm able to send characters itch 3 seconds from mcu and see them in Hyper terminal (communication program).
And if i type a character into Hype terminal my mcu can switch an output on.
First:
My Delphi app has to
- constantly check if character over the serial com port has arrived
- or to recognize an interrupt in that case.
Second:
Just to send data forward when it get it in specific buffer (or when specific variable is different of initial value).
so, try use putstring to send smth and handle OnTrigger\OnTriggerAvail event and use .GetBlock method to retrive data (in prev post it was incorrectly written method names, sorry)
ASKER
ok,
need some time, let you know
need some time, let you know
ASKER
I need more time to make my MCU work appropriately.
(i still don't get right measured values(i'm observing them in Hyper terminal))
I could go on Delphi but then i'll have to turn back.
(i still don't get right measured values(i'm observing them in Hyper terminal))
I could go on Delphi but then i'll have to turn back.
ASKER
I can send data now.
And i'll proceed with looking for procedures for reading.
And i'll proceed with looking for procedures for reading.
MCU does answer you?
To read data use .getchar\.getblock methods in OnTriggerAvail event
To read data use .getchar\.getblock methods in OnTriggerAvail event
ASKER
Next code i use for sending data
var
Form1: TForm1;
sendCharacter:string;
buffer:string[255];
implementation
{$R *.dfm}
procedure doit;
var rs:TApdComPort;
Begin
rs:=TApdComPort.create(nil);
try
rs.ComNumber:=1;//com number
rs.Baud:=4800;//baud rate
rs.Open:=true;
rs.PutString(sendCharacter);
finally
rs.destroy;
end;//try
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
sendCharacter:='1';
doit;
end;
procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
sendCharacter:='0';
doit;
end;
end.
ASKER
But can't insert next:
procedure Tform1.TriggerAvail (CP:TObject;Count:Word);
var
I:word;
C:char;
begin
for I:= 1 to count do begin
c:= ApdcomPort.getChar;
end;
if(pos('x',buffer)>0) then
caption:='x';
end;
ASKER
I forgot to insert next line in code before:
Bufer:= Bufer+c;
Bufer:= Bufer+c;
procedure Tform1.TriggerAvail (CP:TObject;Count:Word);
var
I:word;
C:char;
begin
for I:= 1 to count do begin
c:= ApdcomPort.getChar;
end;
Bufer:= Bufer+c;
if(pos('x',buffer)>0) then
caption:='x';
end;
ASKER
I have got picture how to create\destroy components in runtime , but i can't work with events
can you be more specific what you need help with?
ASKER
After :
var rs:TApdComPort;
and:
rs:=TApdComPort.create(nil );
properties can be asignet to "rs":
rs.ComNumber:=1;//
But how do i deal with events(onTriggerAvail) of ApdcomPort component?
var rs:TApdComPort;
and:
rs:=TApdComPort.create(nil
properties can be asignet to "rs":
rs.ComNumber:=1;//
But how do i deal with events(onTriggerAvail) of ApdcomPort component?
first you have to make a event handler with the right arguments. For that, find in the sourcefile the declaration.
I don't use this comport object, so this is only an example, it's not correct:
I don't use this comport object, so this is only an example, it's not correct:
procedure TForm1.OnTriggerAvail(Sender: TObject; Data; string); // an example, probably not correct!
begin
// ..
end;
procedure TForm1.FormCreate();
var rs:TApdComPort;
begin
rs:=TApdComPort.create(nil);
rs.ComNumber:=1;//
rs.OnTriggerAvail := OnTriggerAvail;
so easy:
type TOnTriggerAvail=procedure( Sender: TObject; Data; string);
procedure myOnTriggerAvail(Sender: TObject; Data; string);
Begin
//do smth;
end;
...
yuor:
var rs:TApdComPort;
and:
rs:=TApdComPort.create(nil );
properties can be asignet to "rs":
rs.ComNumber:=1;//
rs.OnTriggerAvail:=myOnTri ggerAvail;
type TOnTriggerAvail=procedure(
procedure myOnTriggerAvail(Sender: TObject; Data; string);
Begin
//do smth;
end;
...
yuor:
var rs:TApdComPort;
and:
rs:=TApdComPort.create(nil
properties can be asignet to "rs":
rs.ComNumber:=1;//
rs.OnTriggerAvail:=myOnTri
my private email is z642d@freemail.ru and i will read it periodically (now i have been deportated to russia with very silly internet)
and probably (if my solution will not work) you need try rewrite declaration of NOnTriggerAvail as
type TOnTriggerAvail=procedure( Sender: TObject; Data; string) of object;
type TOnTriggerAvail=procedure(
> type TOnTriggerAvail=procedure( Sender: TObject; Data; string) of object;
you almost never have to do this if you use a component, only if you are writing one
you almost never have to do this if you use a component, only if you are writing one
ASKER
Today i had no time.
I'LL go on at evening or tomorow.
I'LL go on at evening or tomorow.
ASKER
It says:
[Pascal Error] Unit1.pas(49): E2009 Incompatible types: 'method pointer and regular procedure'
for next line:
rs.OnTriggerAvail:=myOnTri
ASKER
I supose if there is posible to manupolate (create and destroy) with components it must be
posible to work with events.
ASKER
"first you have to make a event handler with the right arguments. For that, find in the sourcefile the declaration."
Is the next code declaration which i should look for?
Is the next code declaration which i should look for?
{Trigger events}
property OnTriggerAvail : TTriggerAvailEvent
read FOnTriggerAvail write SetOnTriggerAvail;
yes, now look what TTriggerAvailEvent looks like, find the declaration.
ASKER
{Specific trigger event handlers}
TTriggerAvailEvent = procedure(CP : TObject; Count : Word) of object;
If is this what i need,
pleas tich me how to use it (and that is for all what must be done if i wont to use events).
TTriggerAvailEvent = procedure(CP : TObject; Count : Word) of object;
If is this what i need,
pleas tich me how to use it (and that is for all what must be done if i wont to use events).
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much
Just another thing:
because i'm receiving more characters not only one c into TEdit.
How to make next work: edit1.Text:= ccc;
for i:=1 to count do begin
c:= fADPComport.Getchar;
// ccc:=ccc and c;
end;
procedure TForm1.OnTriggerAvail(CP: TObject; Count: word);
var
i:word;
c:char;
begin
for i:=1 to count do begin
c:= fADPComport.Getchar;
end;
edit1.Text:= c;
end;
ASKER
ccc:=CCC+c;
yes, that's it. Although it seems logical that the component has a method which gives you all data at once as a string.
ASKER
jes,
latly i'll surely find it
thank you again
latly i'll surely find it
thank you again
What are the variables outMCU and inMCU, what are the edit boxes for, where are you using RS232, what is the problem?