Solved

Serial Port

Posted on 2001-08-08
7
406 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to fill array with TArray.Create? 14 90
Delphi Form ownership 4 89
how to update exe applicatio from internet ? 6 78
Delphi: sending SMS on android platform 1 21
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

773 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