Electronics > Microcontrollers

Arduino Serial Read issue.

<< < (7/7)

Psi:

--- Quote from: Teknotronix on March 27, 2012, 06:48:08 am ---
--- Quote from: PeterG on March 27, 2012, 06:24:27 am ---I have been looking at Delphi this afternoon and dont seem to be able to find a control for Serial Port communication.
Does Delphi have a native control or do people usually roll there own?

--- End quote ---
http://sourceforge.net/projects/comport/

--- End quote ---

yep, that's the one.  Tcomport is what i use as well.

I just installed it into Delphi XE1 right now  (i usually uses Delphi 7)
This should also work for Delphi XE2

Tcomport is a bit strange in its installation compared to other Delphi components.
It has a designetime and runtime package to install. but its not hard to do.


Here is how i installed it.

Download the TComport component and extract the zip to a location where you want to store 3rd party components. It's best if this isn't part of the Delphi directory.   i use d:\profile\programming\delphicomponents\tcomport\   


Installing the runtime package
- file - open - cportlibdxe.dpk  (its in the source folder of the stuff you unzipped)
- Rightclick on the CPortLibDXE.bpl entry in the delphi project manager and select compile
- Now you need to add that 'source' folder to the delphi library source list
   - click - tools - options
   - Select Environment options - delphi options - library
   - Click the button for library path
   - Click the yellow folder icon and select the source folder for Tcomport
   - Click Add and then ok

Installing the designtime package
- Click File - Open DsgnCPortDXE.dpk
- Rightclick on the DsgnCPortDXE.BPL entry in the project manager and select COMPILE
- Now Rightclick on the DsgnCPortDXE.BPL entry again and select INSTALL
- Your finished. click - File - Close all (don't have to save)

Now you should have the components installed.
You can create a new project and the Tcomport components should be in the component pallet.

Project - add new project - VCL forms application

-Drop a Tcomport on your form
-Set its comport to com1 (or whatever) and the bitrate to what you want.
-Set its connected property to true.
-Add a button that does   
--- Code: --- comport1.transmitchar(  chr(50) );
--- End code ---
   chr(50) just converts 50 from a number to a character
There are a few other ways to send data in buffers and stuff for more advanced applications but TransmitChar() is good to just get stuff working quickly.

Run your program and when you click the button it should send one byte over the serial port


To read data you can use the RxChar event for Tcomport.

an event handler might look like this


--- Code: ---procedure TForm1.ComPort1RxChar(Sender: TObject; Count: Integer);
var
   Str: String;
begin
   ComPort1.ReadStr(Str, Count); // read count number of bytes into the string str
   memo1.text := memo1.text + str;  // append data to a Tmemo. (You might want to convert it to hex though otherwise any ascii commands like
                                                     // tab or new line etc.. will cause that to happen on the memo.
end;

--- End code ---

Teknotronix:
Great to see some delphi stuff on here.

A tip for the beginners looking at this thread. Unlike some other languages like C#, there are two features (among many) that I find very powerful for writing nice clean and readable code. They are "with" statements and nested functions. Try them out, they are great.

PeterG:

--- Quote from: Teknotronix on March 27, 2012, 07:16:13 am ---Great to see some delphi stuff on here.

A tip for the beginners looking at this thread. Unlike some other languages like C#, there are two features (among many) that I find very powerful for writing nice clean and readable code. They are "with" statements and nested functions. Try them out, they are great.

--- End quote ---

now that i am starting out with Delphi, i can guarantee there will be more Delphi threads on here for a while at least... ;D ;D ;D

Thanks for the help people.

Regards

Navigation

[0] Message Index

[*] Previous page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod