10 Replies - 11233 Views - Last Post: 22 August 2012 - 05:36 AM Rate Topic: -----

#1 TNT  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 03-February 08

How do I access interrupts in Visual Basic

Posted 03 February 2008 - 04:57 PM

I need top be able to use interrupts (like in the old Quick Basic - which can do it quite easily) but I am now using Visual Basic and that capability seems to have gone away. What can I do to be able send information to an interrupt (in Visual Basic) and then get information from an interrupt. like using INP and OUT in Quick Basic. I know I am using an obsolete programming language (Visual Basic - I'm even using version 5 because I've had it for so long and it does "almost" everything I want to do)

This forum suggested I change to VB.net for some reason. Can VB.net access interrupts or what are the advantages of VB.net. What will that cost me? Will I have to junk all the working code and subroutines that I use in Visual Basic? Just suggesting a different language is not an answer to a specific question. If it is impossible, just say so. Why did MS have to change what was working rather than just make it better? (that last question is just rhetorical and isn't expecting an answer)

I just want to access interrups in Visual Basic. I found one downloadable package that (almost) works, but only returns one byte (max 255) not the whole thing.

Too many questions? Too few answers. Impossible, so it seems ... is anybody out there smart enough to have accessed interrupts from Visual Basic (version5) ? HOW?

Is This A Good Question/Topic? 0
  • +

Replies To: How do I access interrupts in Visual Basic

#2 Nayana  Icon User is offline

  • DIC Hawk - 나야나 नयन:
  • member icon

Reputation: 31
  • View blog
  • Posts: 824
  • Joined: 14-November 07

Re: How do I access interrupts in Visual Basic

Posted 03 February 2008 - 09:49 PM

A question I have to ask, is what interrupts are you trying to access. When programming on Windows, unless you're writing a driver or something, you should let Windows handle the interrupts and have it notify you via the API.
Was This Post Helpful? 0
  • +
  • -

#3 TNT  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 03-February 08

Re: How do I access interrupts in Visual Basic

Posted 04 February 2008 - 11:28 AM

View PostNayana, on 3 Feb, 2008 - 09:49 PM, said:

A question I have to ask, is what interrupts are you trying to access. When programming on Windows, unless you're writing a driver or something, you should let Windows handle the interrupts and have it notify you via the API.

Was This Post Helpful? 0
  • +
  • -

#4 TNT  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 03-February 08

Re: How do I access interrupts in Visual Basic

Posted 04 February 2008 - 11:39 AM

I am trying to access interupt &70h which I believe it the parallel port to the printer.

The purpose is to send commands out the printer port to control a device attached to that port. The application I am trying to move to Visual Basic (from Quick Basic) is an application that controls a model train using DCC (Digital Command Control). By sending various signals to the DCC, the model train locomotives can be started, stopped and various lights and whistles can be controlled on the locomotives. Because it is a digital system, several model engines and their accessories can be controlled at the same time and one computer can also control the entire model railraid including all switches and building lights and signaling, etc.

DCC is well established, but using a PC computer to control it all is still developmental.

I expect this ability to send values via the interrpup can also be used to control other robotic systems such as radiation field scanners for physics applications and perhaps even for robotic hobbiests.

But first I need to know how to send via an interrupt and read the result of that port. Sort of like the Quick Basic INP and OUT command.
Was This Post Helpful? 0
  • +
  • -

#5 Nayana  Icon User is offline

  • DIC Hawk - 나야나 नयन:
  • member icon

Reputation: 31
  • View blog
  • Posts: 824
  • Joined: 14-November 07

Re: How do I access interrupts in Visual Basic

Posted 04 February 2008 - 07:27 PM

OK, for a short answer, you can't actually do that in NT (NT4, Win2K, XP, Vista), it only works on crap windows (95, 98, ME). This is because using the inp and out methods allows random programs to access the port at the same time.

If you want to access IO directly, you must you a kernel mode driver, and you're probably not in the mood for writing one of those, and you can't really do it in VB anyway.

There is however, a nice bunch of people that in their infinite kindness wrote an ActiveX DLL that you can use from VB to control the port. Their DLL includes it's own kernel mode driver. That DLL can be downloaded here.

Just download the file (Inpout32.dll), and keep it in the same directory as your project.

You can then declare the Inp and Out functions in a seperate BAS file like so:
Public Declare Function Inp Lib "inpout32.dll" Alias "Inp32" _
	(ByVal PortAddress As Integer) _
	As Integer
	
Public Declare Sub Out Lib "inpout32.dll" Alias "Out32" _
	(ByVal PortAddress As Integer, _
	ByVal Value As Integer)



By the way, those aren't actually interrupts. Interrupts are a different thing.

Oh, and to access the port from VB.net would be using exactly the same method.

This post has been edited by Nayana: 04 February 2008 - 07:26 PM

Was This Post Helpful? 1
  • +
  • -

#6 TNT  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 03-February 08

Re: How do I access interrupts in Visual Basic

Posted 05 February 2008 - 12:33 AM

Thank you for a prompt and considered reply that actually (almost) worked. I have tried this Inpout32.DLL stuff and it works. They even have a little test form and program to demonstrate it and to use as a sample piece of code that works just fine as THEY expect it to.

HOWEVER. .. it returns a single integer from the interrupt port
as in : Public Declare Function Inp Lib "inpout32.dll" Alias "Inp32" _
(ByVal PortAddress As Integer) As Integer

RATHER THAN, the expect type of value as follows:

Public Type RegType
	AX As Integer   ' installed
	BX As Integer   ' mode
	CX As Integer   ' nActive
	DX As Integer
	BP As Integer
	SI As Integer
	DI As Integer
	Flags As Integer
End Type
			   
	Public inRegs As RegType
	Public outRegs As RegType
	Public PortNumber As String	 ' port being eg: &70h
	Public ValueFromPort As String ' hexadecimal
	Public ValueToPort As String


The various .AX .BX . CX etc. each contain different bits of information that are needed for a returned value from a parallel port. This InpOut32.DLL routine returns (as far as I can tell) only the one single integer.

The following code snippit shows how I'm expecting to be able to use the various items in the data type (as in this modified old DOS routine).

___________

1112  Select case iOption
		  Case 1
1120		   inRegs.AX = &H1		 'turn system on
				  Call INTERRUPT(&H70, InRegs, OutRegs)
				  Exit Sub

		  Case 2
1130		  inRegs.AX = &H0		 'turn system off
				 Call INTERRUPT(&H70, InRegs, OutRegs)
				 Exit Sub

' Case 3 and 4 not shown in this example)

		 Case 5 ' do nothing
				  Exit Sub

		 Case 6  'DCC reset
1350		  inRegs.AX = &H100
				 Call INTERRUPT(&H70, InRegs, OutRegs)
				 'f OutRegs.AX = 0 Then Print "  DCC SYSTEM RESET "
				 'If OutRegs.AX < 0 Or OutRegs.AX > 0 Then Print "  RESET UNSUCCESSFUL"
				 'Print "		 ANY KEY WILL CONTINUE FROM RESET"
1355		   'A$ = INKEY$: If A$ = "" Then GoTo 1355
				  'CLS
				 exit sub
		
	  End select
	  Exit Sub

__________________

(indents and leading spaces don't seem to be allowed in this post - so the above snippet is not formatted with indents for readablity - Sorry)
_________________________

I still would like to find a way to access the interrups and get back information of the 'RegType' type as described above.

There was another package that I found on the interenet that I downloaded called VBASM that had the expected data type structure, but I couldn't get it to work. Evidentally the .DLL was incompatibel or maybe I needed to'register' the .DLL (I don't know how to do that) Have you happened to have tried the VBASM code to accomplish access to interrupts in Visual Basic? That seems closer to what I need, but I can't get it to work.

Thanks for your helpful suggestion, but I'm still stuck.....
Was This Post Helpful? 0
  • +
  • -

#7 Nayana  Icon User is offline

  • DIC Hawk - 나야나 नयन:
  • member icon

Reputation: 31
  • View blog
  • Posts: 824
  • Joined: 14-November 07

Re: How do I access interrupts in Visual Basic

Posted 05 February 2008 - 01:02 AM

You can use indentations, if you put your code inside tags like this: :code:

I haven't actually tried the code (and I can't) because I don't have a parallel port.

I also haven't read the docs, but I assume that the Integer should have all the information you need in it. Remember you can access all the bits in the Integer seperately.

Like:
If myInt And 1 Then
  'bit 0 is set
ElseIf myInt And 2 then
  'bit 1 is set
ElseIf myInt and 4 Then
  'bit 2 is set
ElseIf myInt and 8 Then
  'bit 3 is set
ElseIf myInt and &H10 Then
  'bit 4 is set


and so forth. With &H20,&H40,&H80,&H100 etc.

&Hxxx in basic means xxx is in hexadecimal format.

You could also check it with a function like this
Function BitIsSet(value As Integer, bit As Integer) As Boolean
  Return (value And 2 ^ bit) > 0
End Function


Was This Post Helpful? 0
  • +
  • -

#8 TNT  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 03-February 08

Re: How do I access interrupts in Visual Basic

Posted 05 February 2008 - 01:48 AM

The snippet I included isn't intended to work, only to show how I am expecting to use the information I get back from the interrupt.

Using the InpOut stuff I usually just get back a single integer rather than anything that would fit into the "type" structure. I can surely look at the separate bits in the integer, but I don't think that is what I need to do.

Are you suggestion that ...
With &H20,&H40,&H80,&H100 etc. might be the separate part of the type structure that I am looking for. I don't think so, but I am still trying anything I can.

The vbASM from Softcircuits (from about 10 years ago?) seems to be 16 bit and maybe that is why it won't work in Visual Basic (32-bit ?) I'm still searching the internet for something that might work.

Let me know if you have an ideas to solve this.
Was This Post Helpful? 0
  • +
  • -

#9 Nayana  Icon User is offline

  • DIC Hawk - 나야나 नयन:
  • member icon

Reputation: 31
  • View blog
  • Posts: 824
  • Joined: 14-November 07

Re: How do I access interrupts in Visual Basic

Posted 05 February 2008 - 02:58 AM

Reading at the port address will give you the data byte (inside an integer). So that only goes up to &H80.

If you read at the port address + 1, then you will get an integer containing the byte of the status data.
Was This Post Helpful? 0
  • +
  • -

#10 TRANERAECK  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 22-August 12

Re: How do I access interrupts in Visual Basic

Posted 22 August 2012 - 05:22 AM

View PostTNT, on 05 February 2008 - 12:33 AM, said:

Thank you for a prompt and considered reply that actually (almost) worked. I have tried this Inpout32.DLL stuff and it works. They even have a little test form and program to demonstrate it and to use as a sample piece of code that works just fine as THEY expect it to.

HOWEVER. .. it returns a single integer from the interrupt port
as in : Public Declare Function Inp Lib "inpout32.dll" Alias "Inp32" _
(ByVal PortAddress As Integer) As Integer

RATHER THAN, the expect type of value as follows:

Public Type RegType
	AX As Integer   ' installed
	BX As Integer   ' mode
	CX As Integer   ' nActive
	DX As Integer
	BP As Integer
	SI As Integer
	DI As Integer
	Flags As Integer
End Type
			   
	Public inRegs As RegType
	Public outRegs As RegType
	Public PortNumber As String	 ' port being eg: &70h
	Public ValueFromPort As String ' hexadecimal
	Public ValueToPort As String


The various .AX .BX . CX etc. each contain different bits of information that are needed for a returned value from a parallel port. This InpOut32.DLL routine returns (as far as I can tell) only the one single integer.

The following code snippit shows how I'm expecting to be able to use the various items in the data type (as in this modified old DOS routine).

___________

1112  Select case iOption
		  Case 1
1120		   inRegs.AX = &H1		 'turn system on
				  Call INTERRUPT(&H70, InRegs, OutRegs)
				  Exit Sub

		  Case 2
1130		  inRegs.AX = &H0		 'turn system off
				 Call INTERRUPT(&H70, InRegs, OutRegs)
				 Exit Sub

' Case 3 and 4 not shown in this example)

		 Case 5 ' do nothing
				  Exit Sub

		 Case 6  'DCC reset
1350		  inRegs.AX = &H100
				 Call INTERRUPT(&H70, InRegs, OutRegs)
				 'f OutRegs.AX = 0 Then Print "  DCC SYSTEM RESET "
				 'If OutRegs.AX < 0 Or OutRegs.AX > 0 Then Print "  RESET UNSUCCESSFUL"
				 'Print "		 ANY KEY WILL CONTINUE FROM RESET"
1355		   'A$ = INKEY$: If A$ = "" Then GoTo 1355
				  'CLS
				 exit sub
		
	  End select
	  Exit Sub

__________________

(indents and leading spaces don't seem to be allowed in this post - so the above snippet is not formatted with indents for readablity - Sorry)
_________________________

I still would like to find a way to access the interrups and get back information of the 'RegType' type as described above.

There was another package that I found on the interenet that I downloaded called VBASM that had the expected data type structure, but I couldn't get it to work. Evidentally the .DLL was incompatibel or maybe I needed to'register' the .DLL (I don't know how to do that) Have you happened to have tried the VBASM code to accomplish access to interrupts in Visual Basic? That seems closer to what I need, but I can't get it to work.

Thanks for your helpful suggestion, but I'm still stuck.....

I know how to register a dll and that could be your problem! First after registering a dll if you are not using it anymore you will have to remove it from your registry. It will be listed in hkey root under the name of the dll way down the list after extensions. A good cleaner could remove it, I use free windows registry cleaner and sometimes it misses; but you have to change the path of the dll.
Now to register a dll you have to go to start menu and click on run
in the dialog box type:
regsvr32 [name of dll with extension and path]
That is all here is to it feel free to contact me for more info about interrupt looking for same thing myself for vbscript or java. Because I found some java script BASIC CODE and would like to use the interrupt for BASIC IBM to add to the code right now it runs 2405 lines before error.
Was This Post Helpful? 0
  • +
  • -

#11 TRANERAECK  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 22-August 12

Re: How do I access interrupts in Visual Basic

Posted 22 August 2012 - 05:36 AM

View PostNayana, on 05 February 2008 - 02:58 AM, said:

Reading at the port address will give you the data byte (inside an integer). So that only goes up to &H80.

If you read at the port address + 1, then you will get an integer containing the byte of the status data.

ENDED my reply to soon; you could also try a quickbasic program to access the interrupt or gwbasic and save the numerics or registry figures to a file then use vb to run that program and attach any readings in the file to your code. It sounds kind of cheesy and it is a double program but it would work. I believe the inp out commands work fine in NT. I use it for &H3C0 for the screen and in assembly the interruopts work fine I use flat assembler there for my x86 windows xp. It says that info in system info. I have no trouble using interrupts.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1