inpout32.dll
BlitzMax Forums/BlitzMax Programming/inpout32.dll
| ||
SuperStrict Global IOP:Int = LoadLibraryA("inpout32") Global Out32:Int(Port:Int, Value:Int) = GetProcAddress(IOP, "Out32") Global Lpt1:Long = $9800 Graphics 800, 600 While Not KeyDown(KEY_ESCAPE) Out32(Lpt1, 1) Wend End I'm trying to get a LED to blink through parallel port and i'm (trying to) using inpout32.dll or it. On my laptop (doesn't have parallel port) this code crashes, but on me PC it doesn't, but it doesn't light up the LED either. Another application that i downloaded from the internet uses the same library and does light up the LED, so i'ts not the hardware. Haven't loaded a library in Bmax before, so maybe someone could give me a hand on it, what i'm doing wrong? |
| ||
are you sure your ints are not 16 bits integers in the declaration? try changing them to short |
| ||
Doesn't it need to use the stdcall calling convention? If so, it should have "win32" before GetProcAddress... Global Out32:Byte(Port:Short, Value:Byte) "win32" = GetProcAddress(IOP, "Out32") Like ziggy states, $9800 would be a Short (Lpt1:Short = $9800), as is Port. The Out32 function should return a Byte and Value is also a Byte. On another note, shouldn't the compiler be complaining about the Long being supplied when it's expecting an Int in the original post? |
| ||
thanks for the help and i finally found that my LPT port address was wrong too. it's not Global Lpt1:Long = 888 and the LED is now blinking. |
| ||
I would love to see your code on this. If you are willing to share. |
| ||
I've already developed my code too far to post it here, too many different files and stuff. But here is the code that should work:Global IOP:Int = LoadLibraryA("inpout32") Global Out32:Int(port:Short, value:Short) = GetProcAddress(IOP, "Out32") Global Lpt1:short = 888 Graphics 800, 600 While Not KeyDown(KEY_ESCAPE) Local result:Byte = Out32(Lpt1, $01) Wend End not sure if there's any need for the result variable. pins: $01 first pin, $02 second, $04 ..., $08, $10, $20, $40, $80 |
| ||
Hmm, you're still using the wrong data types for Value and Out32, even though you've seen what can happen if you do (random crashes/overwriting memory etc). If you insist on using different data types then you should cast them first before passing them. |
| ||
these aren't wrong data types. i read many forums and both out32 function's parameters are short. this is the code i currently have and it works w/o crashes Global IOP:Int = LoadLibraryA("INPOUT32") Global Out32:Byte(Port:Short, Value:Short) "win32" = GetProcAddress(IOP, "Out32") Type TInpout Method setPort(port:Short, state:Short) Local result:Byte = Out32(port, state) End Method End Type and this code generates the short for pin states: ' PINS Global pin:Short[9] pin[0] = $00 pin[1] = $01 pin[2] = $02 pin[3] = $04 pin[4] = $08 pin[5] = $10 pin[6] = $20 pin[7] = $40 pin[8] = $80 Type TPins Field pins:Short = 0 ' Pin numbers from 1 to 8; state is either false or true Method setPin:Byte(pinNum:Byte, state:Byte) If pinNum < 1 Or pinNum > 8 Then Return False Select state Case 0, False ' If flag exists then remove it If Self.getPinState(pinNum) Then Self.pins = Self.pins - pin[pinNum] Default ' If flag doesn't exist, add it If Not Self.getPinState(pinNum) Then Self.pins = Self.pins + pin[pinNum] End Select Return True End Method ' returns pin state Method getPinState:Short(pinNum:Byte) If Self.pins & pin[pinNum] Then Return True Else Return False EndIf End Method ' returns Short of all pins state Method getPins:Short() Return Self.pins End Method ' shuts down all pins Method closePins() Self.pins = 0 End Method End Type |
| ||
Yet you've made two corrections since your second code post (the post I was referring to), namely 'Out32:Int' to 'Out32:Byte' and the addition of "win32"... Global Out32:Int(port:Short, value:Short) = GetProcAddress(IOP, "Out32") Global Out32:Byte(Port:Short, Value:Short) "win32" = GetProcAddress(IOP, "Out32") ...so if nothing was wrong, why change it? I'm just trying to give you some help, use whatever data types you like, I couldn't give a toss. |
| ||
yea, i can see it too. i didn't copy it from my code. but from the first post i made in this r´thread and changed it as i remembered i did the changes. Anyways the last code works. |