Delphi 7 Serial Port ExampleDelphi

Don't use a component! Here's an example how to open a com port with code.then you can use the WriteFile and ReadFile functions to write and read data to and from the com port.varhCommFile: THandle;procedure TForm1.Button1Click(Sender: TObject);varNumberWritten, BytesRead, BytesToRead: LongWord;Data: String;Buffer: PChar;beginhCommFile:= CreateFile('COM2', GENERICWRITE or GENERICREAD, 0, nil, OPENEXISTING, FILEATTRIBUTENORMAL, 0); //Change COM1 to the comport you are using.if hCommFile = INVALIDHANDLEVALUE thenbeginShowMessage('Unable to open COM1');Exit;end;NumberWritten:= 0;Data:= 'Data come here.'

Quote 'Alaadin Bayar' wrote:Hi,I want to have a simple delphi code written with WinAPI functionscreatefile, writefile, and readfile for serial com ports!!Can anybody send it to me?I have just what you want - its a 312 line component that we used to interface with a joystick for an armoured vehicle. Unfortunately it belongs to the company I work for.

It only took me a day to code and debug so it shouldn't be too hard if nobody else has the code for you.I suggest looking at the Win32/MSDN help on CreateFile and associated 'objects' like DCB. If you use FILEFLAGOVERLAPPED you don't have to worry about the data direction and WriteFile is easy and ReadFile is almost as easy. Quote Alaadin Bayar wrote: I want to have a simple delphi code written with WinAPI functions createfile, writefile, and readfile for serial com ports!!You are possibly better off using a pre-written component that handlesall of this for you.Some (free) Comm Port Components I use are:1. ComPort Library, by Dejan CrnilaE-mail: dejan.@yahoo.comHome page: Varian Async32 ComponentsVarian SoftwareHomePage: Ekkehard Domning - Serialng ComponentHackerLecturer in Electronics and ComputingSchool of EngineeringGriffith University - Gold CoastAustralia. If you download a couple of freeware comm port components you can look atthe source and see what is going on. I don't use the components because 1)I always seem to need something not provided by the component 2) Commsoften need debugging and tweaking and I end up fiddling and debugging insidethe component - its simpler to work on straight code!

Delphi 7 Serial Port Example Of Number

3) Most programsonly open one comm port so a set of functions with a few static vars doesthe job as well as a component.Here's some typical bits and pieces.