Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 568
  • Last Modified:

I would like to get com1 and com2,com communication examples,using Delphi 5.0!

I would like to get com1 and com2,com communication examples,using Delphi 5.0!
  can you guide me what WinControl of api should be understood and used?
  Examples ,the best.
1 Solution
this page:
is full of com port components.

using apis some to look for are creatfile,readfile,writefile etc

some examples:
//initilize a modem on com1

procedure InitModem;
Var CommPortTimeOuts: TCommTimeouts;
    DCB: TDCB;
    hCommFile : THandle;
  ReadBuffer: array[0..100] of char;
  NumberRead: DWord;
    { Open the comm port. }
    hCommFile := CreateFile(PChar('COM1'),GENERIC_READ +
    if hCommFile = INVALID_HANDLE_VALUE then
          ShowMessage('Unable to open COM1!');
    { Set Timeout values for the comm port. }
    CommPortTimeOuts.ReadIntervalTimeout        := 100;
    CommPortTimeOuts.ReadTotalTimeoutMultiplier  := 100;
    CommPortTimeOuts.ReadTotalTimeoutConstant    := 0;
    CommPortTimeOuts.WriteTotalTimeoutMultiplier := 0;
    CommPortTimeOuts.WriteTotalTimeoutConstant  := 0;
    { Set the comm port parameters. }
    DCB.BaudRate := 1200;
    DCB.ByteSize := 7;
    DCB.StopBits := ONESTOPBIT;
    DCB.Parity  := EVENPARITY;
    { Send initialization string to the port. }
    ReadBuffer := '';
    StrPCopy(ReadBuffer,'ATZ' + #13 + #10);
    { Get a response from the port. }
    ReadBuffer := '';
    { Close the port. }

get status:

procedure TForm1.Button1Click(Sender: TObject);
   CommPort : string;
   hCommFile : THandle;
   ModemStat : DWord;
   CommPort := 'COM2';

  {Open the comm port}
   hCommFile := CreateFile(PChar(CommPort),
   if hCommFile = INVALID_HANDLE_VALUE then
     ShowMessage('Unable to open '+ CommPort);

  {Get the Modem Status}
   if GetCommModemStatus(hCommFile, ModemStat) <> false then begin
     if ModemStat and MS_CTS_ON <> 0 then
       ShowMessage('clear to send  on.');
     if ModemStat and MS_DSR_ON <> 0 then
       ShowMessage('data set ready on.');
     if ModemStat and MS_RING_ON <> 0then
       ShowMessage('ring indicator on.');
     if ModemStat and MS_RLSD_ON <> 0 then
       ShowMessage('receive line signal detect is on.');

  {Close the comm port}

use one of the components from torry s Comdrv32 or async32 are pretty good and tey all come with examples of usage.

Regards Barry

Hi Barry,
Can the ComDrv32 Serial I/O Package v.2.01(By Marco Cocco.) work with D6?

Regards, supwang
hi supwang,
i have it installed in d6 personal cant honestly rememeber if  ive changed anything as i have others also like asnyc32,asyncfree(big freeware package),some tcomm ,smallport and a _qccomm32, i had most of these from d3,saves all the typing of api's ;-)
why do you ask
could you not get it to work or something ?
let us know any errors .
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Hi inthe,
I am using the MSComm(Come from VB5). :-(  I always want to change to a VCL component.
I still using D3 now, will upgrade to D6 after some months or one year. So I want this VCL component either work with D3 or D6.

Because my program need to have a very quickly response for the communication(must get the data within 20ms or less, then handle it and send back a data within 30ms...), So I create a thread for the communication. Then in the program, have two threads: One is the main thread, one is the communication thread.

Now the question is: Can the ComDrv32 work with my communication thread? And can you make the ComDrv32 for D3/D6 to me?

Regards, supwang
Hi inthe,
Could you help me? Surely I have points for you. :-)

Regards, supwang
>>Can the ComDrv32 work with my communication thread?

shoud be able to ,i have never used the mscomm so i dont know how you interfaced the threads to it.

>>And can you make the ComDrv32 for D3/D6 to me?

tats easy i just send you the version i have as it installed into my d6 personal ok.(i havent got pro version yet as mainly using d5 still.)

i am working alot lately 7 days a week and only have small time for e.e so dont think im ignoring you with late replys ;-)

leave your email i send my ComDrv32 file first thing tommorow.

Hi Barry,
Sorry for the delay.
I want the ComDrv32 for D3 version and for D6 verion.
It's very important to me, so please check the codes carefully.

About this:
-------------------------------------------- >
Because my program need to have a very quickly response for the communication(must get the data within 20ms or less, then handle it and send back a data within 30ms...), So I create a thread for the communication. Then in the program, have two threads: One is the main thread, one is the communication thread.
-------------------------------------------- <
I used a timer to create a communication thread per 300ms(contact the slave machine per 300ms), the thread like the delphi thread example.
(I don?t know if this way will cause some problem?)

What is the best way to do that? Create a communication thread and don't free it until exit the program?  
Do you still have Delphi3? Please write a example for me, using ComDrv32 at the thread.

Can you give it to me within one month? I will award you 300 points. If it spend you a lot of time, Please tell me, I will award you more points. My email is .

Thanks, supwang
(I don?t know if this way will cause some problem?)
Should be
(I don't know if this way will cause some problem.)
i have build with assembly.
to access the com 1

   tx_buffer  = $3F8;
    rx_buffer  = $3F8;
    int_enb_reg= $3F9;
    mod_cont_reg= $3FC;
    line_stat_reg= $3FD;

  Form1: TForm1;
  data : array [1..300] of byte;
  data1: array [1..300] of real;
  data_masuk:byte;//data in

{$R *.dfm}

procedure inisialisasi;
      mov ah,0 { isi register ah ( inisialisasi aktif )}
      mov dx,0 { isi reg dx ( reg.alamat ) = com1 }
      mov al,$83 { isi reg al ( ) }
      int $14  { alamat interupt}
      mov dx,int_enb_reg
      mov al,0
      out dx,al
       mov dx,mod_cont_reg
       mov al,$0
       out dx,al

procedure terima;//accept the data
var cek,d:byte;
     mov dx,line_stat_reg
     in al,dx
     mov cek,al
     cek:=cek and $1;
  until cek=$1;
     mov dx,rx_buffer
     in al,dx
     mov d,al
   data_masuk:=d; //you can use the data in here , data in
You have asked many questions and only graded 4 of them, and they were all  C and D grades, hard to understand.  ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if they are still open in 14 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.

To view your locked questions, please click the following link(s) and evaluate the proposed answer.

*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link 
POINTS FOR EXPERTS awaiting comments are listed in the link below
Moderators will finalize this question if in @14 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
Thanks everyone.
Moderator @ Experts Exchange
I am unlocking this question in preparation for cleanup.  I will return in 7 days to finalize this question.  Please leave any recommendations for the final state of this question, I will take all recommendations into consideration.  Failing any feedback, I may decide in 7 days to delete or PAQ this question with no refund.  Thanks.

Community Support Moderator @Experts Exchange
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now