Solved

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

Posted on 2001-09-05
9
1,000 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
 
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 22

Expert Comment

by:mnasman
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

705 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

19 Experts available now in Live!

Get 1:1 Help Now