Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to do outportb in delphi

Status
Not open for further replies.

sggaunt

Programmer
Jul 4, 2001
8,620
GB
Hello
Back to my 'C' conversion project again.
One function writes directly to registers in an AtoD card.
'C' has Outportb(address) and inportb(address) to do this does anyone know how to do it in Delphi/Pascal.
(I have seen it done as embedded assembler in native Pascal, but maybee there is another way ?)

Steve.

 
I used functions in Windows.pas such as CreateFile and WriteFile to access serial ports in Delphi.

They seemed to work well.

Andrew
 
Andrew

outportb(addr, value);

The 'C' function writes data to memory address, although it is often used to write to the serial port address, hench the name.
I am attempting to write (with no prior knowlage of 80836 asm code) some assembler to do it.
but without any sucess so far
e.g.

procedure ADC(value: real);
var HB,LB: byte
begin
//some code to convert the real to 2 bytes
// then
asm
MOV [ADC_addr] HB
MOV [ADC_addr + 1] LB
end;
end;

The assembler error messages are inadequate to say the least
Steve.
 
Please be aware that, without a special driver, you won't be able to directly access I/O ports from any NT-based Windows version...

HTH
TonHu
 
You can do it with inline assembly. The command you are looking for is out. It's been too many years, though, I don't remember the exact syntax.

However, as TonHu points out, this will absolutely fail under NT/2K/XP. There is *NO* way for your program to do it, it *MUST* be done by a device driver. There are drivers out there that are general-purpose port access systems. I don't remember a name, though.

The morons at Micro$oft figured that hardware should only be accessed through it's drivers. The idea that there might be odds and ends in an industrial environment not worth device drivers apparently didn't occur to them.

We've got some such "devices" that are absolutely one-shots. It's a standard card but the card does nothing but translate bit patterns into switches to control machinery. A device driver?! Ha!
 
Do a Google search for "Delphi com_io".

I found this to be a useful small package (with source code) on which to base a Delphi program that opened and shut relays.

Andrew
 
Thanks for that Guys
I will Check out your link Andrew,
Loren and Tonhu, You make intresting points, the original 'C' code is running on (very old) DOS based Industrial PC's the AD Card is a recent addition and comes with DOS drivers and Libararys which are huge and were not worth the effort of implementing.
I needed to write just 5 or 6 lines of 'c' to access the Cards Output.
When these PC's grind to a Halt (probobly sooner rather than later) our coustomers will probobly want to upgrade hench the project.
I belive the Card Suppliers also do Windows drivers, But these are probobly written for 'C'. I can C this is going to be a problem.
Steve
 
If you are looking for freeware to access com ports, check out this guys site:



The site is not 100% in English.
The unit is difficult to install.

Be that as it may, when you get it installed it is one of the most reliable units I have used. I use it to read scale head data streaming constantly.

andrew
 
OutPortB is a mnemonic for 'OUT a Byte to an i/o PORT' wich was relevant in 'previous' processors (8080/Z80).
If the I/O ports of your AtoD card are memory mapped (they should be...), then I'd try with the 'absolute' keyword on a variable, it's pretty well explained in the Delphi helpfile, don't want to repeat that here. ;-)

All people responding with COM-port libs are totally on the wrong track I guess... s-)

HTH
TonHu
 
hi tonhu


I cant find anything on absolute other than it is a directive, in the help files i have here (d3) i have d4 at home will look there, is the access problem still relevant, the link i posted goes to an artical where the application is very simular to mine. they seem to be talking about memory mapped io.
steve
ps use of shift key very restricted to to diy damage to right thumb!!!!!!!!!!!
 
This I got from the Delphi 5 helpfile:

To declare a variable that resides at a specified memory address, put the word absolute after the type name, followed by an address. Example:

var CrtMode: Byte absolute $0040;

This technique is useful only in low-level programming, for example when writing device drivers.
To create a new variable that resides at the same address as an existing variable, use the name of the existing variable (instead of an address) after the word absolute. For example,

var

Str: string[32];
StrLen: Byte absolute Str;

specifies that the variable StrLen should start at the same address as Str. Since the first byte of a short string contains the string’s length, the value of StrLen is the length of Str.
You cannot initialize a variable in an absolute declaration.

HTH
TonHu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top