Solved

Basic equivalent in Delphi 5 for "OPEN "COM1:1200,N,7..."

Posted on 2001-09-05
9
1,010 Views
Last Modified: 2009-12-16
In Basic i can start the reading of serial ports via

OPEN "COM1:1200,N,7,2,RS,CS,DS,CD" AS variable
then i can work with variable.

What is the equvalent programm code in Delphi 5?

0
Comment
Question by:tzigan
[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
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 9

Expert Comment

by:ITugay
ID: 6456430
Hi tzigan,

if you have to open port with your custom settings (i mean baud rate, parity and so on) then it would be good idea to use special component. There  is a lot of them can be found in internet. e.g. www.torry.net

-----
Igor
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 6456521
Varian Async32 is a good component, freeware:

http://www.varian-software.com/

0
 

Author Comment

by:tzigan
ID: 6456546
1.Yes, i know this page. But isn't there a way to do it so easy like in Basic? It is only to open the port and read the datas.
2.is anywhere a doc for Async32. I loaded this file, but it seems to be not very easy to work with the component. I'm not a "port speci" and it has settings without end.
0
Technology Partners: 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 9

Expert Comment

by:ITugay
ID: 6456560
Hi tzigan,

no, there is no easy way to open the port like you described above. I'm not sure you want to write a lot of API's functions. It much more difficult then to use component. Using component is better way to go.

COM1:1200,N,7,2,RS,CS,DS,CD

any component should has this property:
COM1 - port no
1200 - baud rate
N - parity none
7 - number of data bits
2 - number stop bits

DS, RS, CS, CD - runtime property

------
Igor
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6456645
Hello

 there are alot of serial components in these links

http://www.torry.net/modems.htm

http://www.vclcomponents.com/search.asp?ID_CATEGORY=166&GRP=1

you can find free serial components there

Mohammed


0
 
LVL 17

Accepted Solution

by:
inthe earned 200 total points
ID: 6456741
under windows you need to use api calls,these can be used via a component to "wrap" them or as api calls directly.
a component is probably better if your new to it but heres an example anyways,it just initilizes the modem and it shows some of the apis to start with:
TCcb & TCommTimeouts are defined by deklphi and contain most of what you will need.
i would suggest to see win32.hlp for related apis to GetCommState ,cause there are a few (or downloading some of the components mentioned and browsing the source code can lead to interesting stuff.)

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;

 
0
 
LVL 17

Expert Comment

by:inthe
ID: 6456750
is there something specfic you need to do listen for messages? talk to modem etc.. some components/api's are better than others depending on your purpose.
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6456903
Is the MSCOMM OCX still installed with Windows?  I know this used to be around in the real early days of VB, but it may not be anymore.  Just thinking out loud :)
0
 

Author Comment

by:tzigan
ID: 6456994
Thanks all, i think to have infos enougth to fix my problem
0

Featured Post

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!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

717 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