Solved

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

Posted on 2001-09-05
9
1,003 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
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…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 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

12 Experts available now in Live!

Get 1:1 Help Now