Solved

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

Posted on 2001-06-17
11
536 Views
Last Modified: 2010-04-06
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
0
Comment
Question by:johngodzbi
11 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 6199534
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

0
 
LVL 2

Expert Comment

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

Regards, supwang
0
 
LVL 17

Expert Comment

by:inthe
ID: 6760329
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 .
0
 
LVL 2

Expert Comment

by:SupWang
ID: 6760697
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
0
 
LVL 2

Expert Comment

by:SupWang
ID: 6765905
Hi inthe,
Could you help me? Surely I have points for you. :-)

Regards, supwang
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 17

Expert Comment

by:inthe
ID: 6775099
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
0
 
LVL 2

Expert Comment

by:SupWang
ID: 6813313
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
0
 
LVL 2

Expert Comment

by:SupWang
ID: 6813321
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.)
0
 

Expert Comment

by:surodimedjo
ID: 6818277
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;
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6976082
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.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://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.
http://www.experts-exchange.com/questions/Q.20068787.html
http://www.experts-exchange.com/questions/Q.20119679.html
http://www.experts-exchange.com/questions/Q.20126714.html
http://www.experts-exchange.com/questions/Q.20134537.html
http://www.experts-exchange.com/questions/Q.20137705.html
http://www.experts-exchange.com/questions/Q.20139107.html
http://www.experts-exchange.com/questions/Q.20182826.html
http://www.experts-exchange.com/questions/Q.20192596.html
http://www.experts-exchange.com/questions/Q.20230967.html
http://www.experts-exchange.com/questions/Q.20230975.html
http://www.experts-exchange.com/questions/Q.20231020.html
http://www.experts-exchange.com/questions/Q.20258451.html
http://www.experts-exchange.com/questions/Q.20272676.html
http://www.experts-exchange.com/questions/Q.20277853.html

To view your locked questions, please click the following link(s) and evaluate the proposed answer.
http://www.experts-exchange.com/questions/Q.20070329.html
http://www.experts-exchange.com/questions/Q.20136842.html
http://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
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643
POINTS FOR EXPERTS awaiting comments are listed in the link below
http://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
0
 

Accepted Solution

by:
SpideyMod earned 0 total points
ID: 8280605
All,
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.

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Filemaker 14 vs Delphi Embarcadero 7 160
How to fill array with TArray.Create? 14 68
delphi exception 7 58
Base1 Encode/Decode 3 31
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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now