Solved

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

Posted on 2001-09-05
9
1,005 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
  • 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

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.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

810 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