?
Solved

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

Posted on 2001-09-05
9
Medium Priority
?
1,012 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 600 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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 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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month9 days, 23 hours left to enroll

762 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