News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

ports

Started by JHER VON ARBANEL, January 12, 2006, 03:30:11 PM

Previous topic - Next topic

JHER VON ARBANEL

hi, in DOS i used "out",and "in " to with ports in masm32 is it the same? can any body give me a few lines,how can i use ports, like 3f8 or other port thx

Tedd

Accessing ports is the same.

But, windows 'protects' the ports, so unless you're creating a driver or system service, accessing the ports will throw an exception at best.

It's a security thing. If you can access ports, then you can access any device directly, without any kind of security checking.
No snowflake in an avalanche feels responsible.

farrier

JHER VON ARBANEL,

Since 3f8 is a parallel printer port address, I'm assuming you want to print.  You can use CreateFile with ReadFile and WriteFile to access LPT1, LPT2, COM1-8 etc.  There is an example in the SDK with the title "Configuring a Communications Resource"

hth,

farrier
It is a GOOD day to code!
Some assembly required!
ASM me!
With every mistake, we must surely be learning. (George...Bush)

MichaelW

The I/O port 3F8h is the base address for the first serial port. Attempting to access this I/O port from a Windows app will trigger an exception under any version of Windows AFAIK. I seem to recall there being a few I/O ports (300h+?) that you can access from a Windows app running under Windows 9x, but this is limited to ports that Windows does not use. You can, however, access most or all of the I/O ports that are commonly used by DOS apps, from a DOS app running under Windows 2000 at least, and probably under Windows XP.

eschew obfuscation

farrier

MichaelW,

You're right, I was thinking of 378h :red  But you can still send and receive data to and from a serial port as "COM1", COM2", etc. using standard windows api, as stated above.  No need for drivers or changing user levels.   This is true unless you are doing something really low level!

farrier
It is a GOOD day to code!
Some assembly required!
ASM me!
With every mistake, we must surely be learning. (George...Bush)

MichaelW

Quote from: farrier on January 13, 2006, 12:39:28 AM
But you can still send and receive data to and from a serial port as "COM1", COM2", etc. using standard windows api, as stated above.  No need for drivers or changing user levels.   This is true unless you are doing something really low level!

Sorry, I did not mean to give the impression that I was disagreeing with any of this. I was just pointing out to the OP what you can and cannot do with the I/O ports.



eschew obfuscation

JHER VON ARBANEL

thx , i trying to control a little robot and i need any two port to control it, a serial and a paralalel. I use to program in DOS, it works there but, i prefer masm32 couse it works with the API, and the graph interface is better. So can y u give some functions to do it, or some lines of code, i dont really know where to start



thx

farrier

JHER VON ARBANEL,

Go to google.com and type in what I suggested above:

Configuring a Communications Resource

The first link returned is the one--MSDN--that taught me everything I needed to read and write from/to serial and parallel ports.  Also search this site and win.asmcommunity.net , this has been discussed often.

farrier
It is a GOOD day to code!
Some assembly required!
ASM me!
With every mistake, we must surely be learning. (George...Bush)

IAO

Hi to all.

Mr. JHER VON ARBANEL
My English is poor. But try.

Goto--> " http://www.radasm.com"    and look     "Tutorials using Inpout32.dll "   into   "RadASM projects"

No tutorial. It have 5 different programs.


by(t)e ('-').
"There is no way to peace. Peace is the way."    Mahatma Gandhi

P1

http://www.madwizard.org/view.php?page=downloads Download AsmIO and you will need WinIO from http://www.internals.com/.

This will get you back to a 'port' style programming for the robot.

Regards,  P1  :8)

MichaelW

I think WinIo will work ok for devices that Windows is not using, but in testing some Identify Device code that accessed the hard drive command/control block registers I discovered that I could occasionally cause Windows to report a drive controller error. I abandoned the project because I couldn't find any reliable method of avoiding the errors, and IMO the risk of data loss was too great.

WinIo does work as advertised, and I had no problems interfacing to it using MASM.

eschew obfuscation

BogdanOntanu

Quote from: MichaelW on January 19, 2006, 07:49:02 PM
I think WinIo will work ok for devices that Windows is not using, but in testing some Identify Device code that accessed the hard drive command/control block registers I discovered that I could occasionally cause Windows to report a drive controller error. I abandoned the project because I couldn't find any reliable method of avoiding the errors, and IMO the risk of data loss was too great.

WinIo does work as advertised, and I had no problems interfacing to it using MASM.


That is normal, even if WinIO and other do give you the option to write directly on ports in WinNT/2k/XP you must also consider the fact that a complex OS is accessing the same ports in the same time as you do.

I am amazed that you did not loose any data; I guess Windows recovered the controller from the error condition state.
But imagine the consequences of a device reset command sent in the middle of a FAT or MFT on disk data structure writting :D

Accessing devices that are in use or possible in use by Windows must be done via a Kernel Mode Driver and folowing the guidance, interfaces, framework and API from the Windows DDK.

However for directly accessing HDD there are many solutions involving sending IOCTL comands to the existing Windows HDD driver and this will at least maintain coherency with the lowest disk device driver; Filesystems might be affected by random writes anyway...

Ambition is a lame excuse for the ones not brave enough to be lazy.
http://www.oby.ro

P1

He will most likely use a dedicated PC ( Setup lean & mean like a RTC ) for this and hopefully disable any drivers using those ports.  Keep memory free of CPU robbing programs.

Otherwise his project will not perform the way he desires.

Regards,  P1

JHER VON ARBANEL

thx for the replies, the best tout that i found  was form radmasn, well its an example but it is enough for anybody to understand and begin usign ports, and to really program in low level
  thx to everyone http://www.radasm.com/ look at radasmprojects then look out Tutorials using Inpout32.dll and its mmm ....  new (08-01-2005)

IAO

Hi to all:
My English is poor. But try.


Quote from: JHER VON ARBANEL on January 22, 2006, 04:24:04 PM
The best tout that i found was form radasm, well its an example but it is enough for anybody
to understand and begin usign ports, and to really program in low level.

By Your commentary I feel very happy.
I thought that nobody, would understand those sources.
It gives spirit me to follow.



In Spanish:
Por Tu comentario me siento muy feliz.
Pensé que nadie, entendería esos fuentes.
Me da ánimo para seguir.




by(t)e ('-').
"There is no way to peace. Peace is the way."    Mahatma Gandhi