Solved

io ports

Posted on 2003-12-08
5
868 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
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

10 Experts available now in Live!

Get 1:1 Help Now