Link to home
Start Free TrialLog in
Avatar of johngodzbi
johngodzbi

asked on

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.
  thanks
Avatar of inthe
inthe

hi,
this page:
http://www.torry.net/modems.htm
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;
begin
 
    { Open the comm port. }
    hCommFile := CreateFile(PChar('COM1'),GENERIC_READ +
GENERIC_WRITE,0,nil,OPEN_EXISTING,FILE_FLAG_WRITE_THROUGH,0);
    if hCommFile = INVALID_HANDLE_VALUE then
    begin
          ShowMessage('Unable to open COM1!');
          exit;
    end;
 
    { Set Timeout values for the comm port. }
    CommPortTimeOuts.ReadIntervalTimeout        := 100;
    CommPortTimeOuts.ReadTotalTimeoutMultiplier  := 100;
    CommPortTimeOuts.ReadTotalTimeoutConstant    := 0;
    CommPortTimeOuts.WriteTotalTimeoutMultiplier := 0;
    CommPortTimeOuts.WriteTotalTimeoutConstant  := 0;
    SetCommTimeOuts(hCommFile,CommPortTimeOuts);
 
    { Set the comm port parameters. }
    GetCommState(hCommFile,DCB);
    DCB.BaudRate := 1200;
    DCB.ByteSize := 7;
    DCB.StopBits := ONESTOPBIT;
    DCB.Parity  := EVENPARITY;
    SetCommState(hCommFile,DCB);
 
    { Send initialization string to the port. }
    ReadBuffer := '';
    StrPCopy(ReadBuffer,'ATZ' + #13 + #10);
 
WriteFile(hCommFile,ReadBuffer,Length(ReadBuffer),NumberRead,NIL);
 
    { Get a response from the port. }
    ReadBuffer := '';
    ReadFile(hCommFile,ReadBuffer,100,NumberRead,NIL);
 
    { Close the port. }
    CloseHandle(hCommFile);
end;



get status:

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

  {Open the comm port}
   hCommFile := CreateFile(PChar(CommPort),
                           GENERIC_READ,
                           0,
                           nil,
                           OPEN_EXISTING,
                           FILE_ATTRIBUTE_NORMAL,
                           0);
   if hCommFile = INVALID_HANDLE_VALUE then
   begin
     ShowMessage('Unable to open '+ CommPort);
     exit;
   end;

  {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.');
 end;

  {Close the comm port}
   CloseHandle(hCommFile);
 end;


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 .
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
howdy,
>>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.)

ps,
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.

Regards
Barry
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 addsup@163.net .

Thanks, supwang
Sorry,
(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

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

var
  Form1: TForm1;
  i,j:integer;
  data : array [1..300] of byte;
  data1: array [1..300] of real;
  data_masuk:byte;//data in
 
implementation

{$R *.dfm}

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

procedure terima;//accept the data
var cek,d:byte;
begin
  repeat
    asm
     mov dx,line_stat_reg
     in al,dx
     mov cek,al
    end;
     cek:=cek and $1;
  until cek=$1;
   asm
     mov dx,rx_buffer
     in al,dx
     mov d,al
   end;
   data_masuk:=d; //you can use the data in here , data in
end;
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.
https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  https://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

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.
https://www.experts-exchange.com/questions/Q.20068787.html
https://www.experts-exchange.com/questions/Q.20119679.html
https://www.experts-exchange.com/questions/Q.20126714.html
https://www.experts-exchange.com/questions/Q.20134537.html
https://www.experts-exchange.com/questions/Q.20137705.html
https://www.experts-exchange.com/questions/Q.20139107.html
https://www.experts-exchange.com/questions/Q.20182826.html
https://www.experts-exchange.com/questions/Q.20192596.html
https://www.experts-exchange.com/questions/Q.20230967.html
https://www.experts-exchange.com/questions/Q.20230975.html
https://www.experts-exchange.com/questions/Q.20231020.html
https://www.experts-exchange.com/questions/Q.20258451.html
https://www.experts-exchange.com/questions/Q.20272676.html
https://www.experts-exchange.com/questions/Q.20277853.html

To view your locked questions, please click the following link(s) and evaluate the proposed answer.
https://www.experts-exchange.com/questions/Q.20070329.html
https://www.experts-exchange.com/questions/Q.20136842.html
https://www.experts-exchange.com/questions/Q.20192718.html

*****  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
https://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643 
POINTS FOR EXPERTS awaiting comments are listed in the link below
https://www.experts-exchange.com/commspt/Q.20277028.html
 
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.
Moondancer
Moderator @ Experts Exchange
ASKER CERTIFIED SOLUTION
Avatar of SpideyMod
SpideyMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial