• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 879
  • Last Modified:

io ports

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
andru
Asked:
andru
1 Solution
 
robert_marquardtCommented:
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
 
mgazzaCommented:
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
 
delphizedCommented:
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
 
andruAuthor Commented:
as i guessed, but wasn't sure bout parallel port.

thanks
0
 
mgazzaCommented:
no problem :D glad to help
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now