Solved

Serial Port

Posted on 2001-08-08
7
407 Views
Last Modified: 2010-04-06
I know Delphi isn't designed for creating device drivers but I think I can use it to send data to a serial port.  

1) Is this done with basic Delphi commands or is it a WinAPI type command?

2) Is there a resource online that will teach me the essentials?


Note: I am going to receive a box that attaches to the serial port.  I need to be able to send a string of ascii characters and read a response.

Thanks in advance for your assistance.
Don
0
Comment
Question by:d32coder
7 Comments
 
LVL 7

Accepted Solution

by:
Motaz earned 100 total points
ID: 6366917
I use a free open source component called Async, I use it for all my serial interfaces, tell me your E-Mail and I'll send it to you.

Motaz
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6366928
0
 

Author Comment

by:d32coder
ID: 6367483
Thanks Motaz: d32coder@home.com  

mnasman, Looking at your URL's now.


Don
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 3

Expert Comment

by:VSF
ID: 6368353
Sent some nice components to you via e-mail <d32coder@home.com>!
Hope they help you!


VSF
0
 
LVL 17

Expert Comment

by:inthe
ID: 6368485
hi,
just to mention that while the components above certainly make life easier ,they are wrapper for using the WinApi .
Api's like :
CreateFile()
ReadFile()
WriteFile()
Get/SetCommState()

etc are the ones mainly used.

below is example to initilize modem on Com4:

 var
  ComFile : THandle;
  TimeOuts: TCommTimeouts;
  DCB: TDCB;
  ReadBuff: array[0..100] of char;
  NumBytes: DWord;
 begin
  ComFile := CreateFile(PChar('COM4'),GENERIC_READ +
GENERIC_WRITE,0,nil,OPEN_EXISTING,FILE_FLAG_WRITE_THROUGH,0);
    if ComFile = INVALID_HANDLE_VALUE then
    begin
     ShowMessage('Unable to open COM4');
     exit;
    end;
    TimeOuts.ReadIntervalTimeout        := 100;
    TimeOuts.ReadTotalTimeoutMultiplier  := 100;
    TimeOuts.ReadTotalTimeoutConstant    := 0;
    TimeOuts.WriteTotalTimeoutMultiplier := 0;
    TimeOuts.WriteTotalTimeoutConstant  := 0;
    SetCommTimeOuts(ComFile,TimeOuts);
    GetCommState(ComFile,DCB);
    DCB.BaudRate := 5600;
    DCB.ByteSize := 7;
    DCB.StopBits := ONESTOPBIT;
    DCB.Parity  := EVENPARITY;
    SetCommState(ComFile,DCB);
    ReadBuff := '';
    StrPCopy(ReadBuff,'ATZ' + #13 + #10);
    WriteFile(ComFile,ReadBuff,Length(ReadBuff),NumBytes,NIL);
    ReadBuff := '';
    ReadFile(ComFile,ReadBuff,100,NumBytes,NIL);
    CloseHandle(ComFile);
end;

nice to know how things are done but i would still get and use some of the components mentioned above to save much time.

Regards Barry
0
 
LVL 5

Expert Comment

by:Gwena
ID: 6370261
listening :-)
0
 

Author Comment

by:d32coder
ID: 6370293
I honestly didn't expect so many responses so quickly.  I should receive the box UPS in the next day or so.  I'll report on it (and choose an answer) as soon as I get it connected.

Note: Please do not send me "cracked" components.  I'm in the software business and do not appreciate piracy.

Don
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question