Solved

Serial Port

Posted on 2001-08-08
7
408 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…

734 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