newbie struggling with printer port access

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by hanz.

Hi all!
Having just purchased PB and now trying to do some bit fiddling with the printed port, I cannot get the following code snippet to work ( which I found here under a "WinIO" thread...)
The snippet compiles without any errors, but does not produce any change in the LEDs which I have connected to the port. I have put the winio.dll and winio.sys under pb\compilers and the 'wrapper' file under pb\plib\userlib.

However if I run Debug (under DOS) I can change the data ok. I have tried this on a laptop and also a desktop with win98.

;WinIO_Test
;compiles ok, but no effect on the port!
;
#DATA = $378 ; base address LPT1
#STATUS = $379
#CONTROL = $37A
;
If OpenLibrary(0, "WinIo.dll")
CallFunction(0, "InitializeWinIO")
;out $ff to LPT1
CallFunction(0, "SetPortVal", DATA, $ff, 1)
CallFunction(0, "ShutDownWinIO")
EndIf
End

Further I have unsuccesfully tried in-line assembly. Here I get an error message (forward the file..) or the compiler does not like the out $378, $ff instruction. Where do I find a list of asm opcodes? According to the NASM docs this is a legal opcode...

;Asm lpt1 test
;out $378, $ff ;does not like this...
mov dx, $378
mov ax, $ff
out dx, ax
end

Any assistance is greatly appreciated!


73,
de ZL1HB
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tinman.
Originally posted by hanz

CallFunction(0, "SetPortVal", DATA, $ff, 1)
Looks like you should be using #DATA there

--
It's not minimalist - I'm increasing efficiency by reducing input effort.
(Win98first ed. + SP1, PB3.40)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Denis.

Asm lpt1 test
;out $378, $ff ;does not like this...
mov dx, $378
mov ax, $ff

For in-line assembly hexa values, you have to write your hexa value with an h at the end without '$'.
if your hexa number begin with a letter (A to F)put '0' before it.

0ffh instead of $ff
378h "" " $378


Denis
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

Inline asm should convert this hexa values to correct one. It's only needed when you use direct Asm with '!'.

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

Remember you must install WinIO correctly
before first use (logged in as ADMIN).

Checking all return values of the functions
you call wouldnt be a bad idea too.
(See WinIO documentation for this)

Copy the WinIO files also to your app
dir, where your source/exe is.

http://home.t-online.de/home/ExpressTrack/PB_WinIO.zip

cya,
...Danilo
(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by hanz.
Originally posted by fred

Inline asm should convert this hexa values to correct one. It's only needed when you use direct Asm with '!'.

Fred - AlphaSND
I think I have learned that in PB you can use the "$hex" notation, whilst in ASM you must use the "h-appended" notation. Anyway, this works fine now:

;Asm port test
;Toggle port bits...

loop:
mov dx, 378h
mov ax, 0h
out dx, ax
Delay(2000)

mov dx, 378h
mov ax, 0ffh
out dx, ax
Delay(2000)

Goto loop
End

Again, pb refuses to compile if I use the '$hex' notation.
Why would the "OUT imm8, AL" opcode not compile?. The error message is "AL (or AX or EAX) is not a valid operator"
Where can I find a reference to the "!" notation. What is meant with direct asm? Is above not direct asm?

many thanks!

73,
de ZL1HB
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by hanz.
Originally posted by Danilo

Remember you must install WinIO correctly
before first use (logged in as ADMIN).

Checking all return values of the functions
you call wouldnt be a bad idea too.
(See WinIO documentation for this)

Copy the WinIO files also to your app
dir, where your source/exe is.

http://home.t-online.de/home/ExpressTrack/PB_WinIO.zip

cya,
...Danilo
(registered PureBasic user)
Success!!
I have struggled with this one, but for reference for those who are also starting off here:

1- In PB the variable, function names etc. are case in-sensitive
2- I you use a dll, the calling parameters are case SENSITIVE
3- To use the WinIo dll you only have to drop the winio.dll and the winio.sys in the pb\complilers directory.

I have 'discovered' how to check the return values of the called functions. What did not work in my original code snipped was that I called a function with "InitializeWinIO" whilst the parameter should have been called "Initialize WinIo"
I hope that this is correct. In anycase all is well now and I thank everybody for their help!

This is the working code snippet:

;WinIoTest
#DATA = $378 ; base address LPT1
#STATUS = $379
#CONTROL = $37A

If OpenLibrary(0, "WinIo.dll")
MessageRequester("OpenLib", "WinIo Opened", 0)
If CallFunction(0, "InitializeWinIo")
MessageRequester("CallFunction", "WinIo Initialised", 0)
Else
MessageRequester("OpenLib", "WinIo NOT Initialised", 0)
EndIf
;out $ff to LPT1
CallFunction(0, "SetPortVal", #DATA, $00, 1)
CallFunction(0, "ShutdownWinIo")
Else
MessageRequester("OpenLib", "WinIo NOTOpen", 0)
EndIf

End




73,
de ZL1HB
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tinman.
Originally posted by hanz

2- I you use a dll, the calling parameters are case SENSITIVE
Just to point out, the reason it is case sensitive is nothing to do with PureBasic (and it is not the parameters for the dll function, but the function name). The reason the function name is case sensitive is because Windows obviously performs a case sensitive search for functions in DLLs.


--
It's not minimalist - I'm increasing efficiency by reducing input effort.
(Win98first ed. + SP1, PB3.40)
Post Reply