Solved

io ports

Posted on 2003-12-08
5
872 Views
Last Modified: 2010-04-05
i gather that the rtl stuff is depreciated. however i can't find any documentation on using streams to access the io ports. in  particular the serial and parallel ports, or maybe also usb.

please point me to the right documentation and maybe also 3rd party components that allow access to io ports.

tia
0
Comment
Question by:andru
[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
5 Comments
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 9902653
There is no good reason to connect streams to IO ports because usually you want to use the Win32 API functions directly.
All COM port components work that way.
USB is impossible because the USB port is nonexistent. You always talk to devices.
0
 
LVL 1

Accepted Solution

by:
mgazza earned 125 total points
ID: 9906285
hi,
you cant assess the usb without a device driver the computer doesnt know how to talk to the device

but you can talk to the com or parallel port
comm is a string with ither 'COM1' ect or 'LPT1'

close the handle when your finished with it

CommFile := CreateFile(pchar(comm), GENERIC_READ or GENERIC_WRITE, 0, Nil,
                                      OPEN_EXISTING,
                                      FILE_ATTRIBUTE_NORMAL, 0);

   if CommFile = INVALID_HANDLE_VALUE then
     application.Terminate;

you can read or write to the port using readfile or writefile
look at the microsoft documentation about this
if you want to setup a braud speed ect use

if not SetupComm(CommFile, RxBufferSize, TxBufferSize) then
   showmessage('Error 1');

if not GetCommState(CommFile, DCB) then
   showmessage('Error 2');

if not BuildCommDCB(@Config[1], DCB) then
   showmessage('Error 3');

if not SetCommState(CommFile, DCB) then
   showmessage('Error 4');

with CommTimeouts do
begin
   ReadIntervalTimeout := 0;
   ReadTotalTimeoutMultiplier := 0;
   ReadTotalTimeoutConstant := 1000;
   WriteTotalTimeoutMultiplier := 0;
   WriteTotalTimeoutConstant := 1000;
end;

if not SetCommTimeouts(CommFile, CommTimeouts) then
showmessage('Error 5');

that will all setup your comport for reading or writting
var
   CommFile: THandle;
   Comm:string='COM1:';
   DCB: TDCB;
   Config : String= 'baud=19200 parity=n data=8 stop=1' +#0 ;
   CommTimeouts : TCommTimeouts;
   Data:array [0..255] of word;
 Const
   RxBufferSize = 256;
   TxBufferSize = 256;
0
 
LVL 5

Expert Comment

by:delphized
ID: 9908078
I use Async Professional for Delphi and it works great for me.
I stopped on version 3, but they went open source as far as I know...
so just have a look at source forge for more information.
0
 

Author Comment

by:andru
ID: 9915133
as i guessed, but wasn't sure bout parallel port.

thanks
0
 
LVL 1

Expert Comment

by:mgazza
ID: 9915412
no problem :D glad to help
0

Featured Post

Independent Software Vendors: 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 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