Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2883
  • Last Modified:

How do I read/write the parallel port in VB 2005 Express?

Hi,
I am trying to write a program in VB 2005 Express that will read and write to a parallel port.  I have found several links on the internet that recommend using inpout32.dll, including one link that provides a complete tutorial to write a program (http://www.codeproject.com/useritems/Inpout32_read.asp).  But when I create and run a program an exception error occurs whenever a function in the dll is called.  The error is "SEHException was unhandled","External component has thrown an exception".  The details indicate that the error code is -2147467259.  I am running in debug mode in VB.  I have moved the dll around to several locations, including c:\windows\system32, the same folder that contains the executable for VB, and every folder and subfolder within the project folder.  I am running Windows XP Home Edition.  Can you help me to find a way to read and write to the parallel port in VB 2005 Express?
0
wamlink
Asked:
wamlink
  • 5
  • 2
1 Solution
 
coopzzCommented:
Couple of things to look out for..
Make sure your paralle port is set the the correct mode (I think it said EPP or SPP in the Article) so in bios you need to check that it's set to it.
When I did some things in vb6 for IO to the port I had to place the dll in the vb 6 running folder (as in the folder that Visual Basic was running from) but when it was completely complied as long as it was in the same folder it would work (as in no Visual Studio).
But for the hell of it if i get time, I'll give this a go when I get home.
0
 
chmdznrCommented:
try this link:
"How to access serial and parallel ports by using Visual Basic .NET"
http://support.microsoft.com/kb/823179 

and also:
"VB.Net Reading Parallel Port Under Windows XP/2000"
http://www.experts-exchange.com/Programming/Programming_Languages/Q_20818873.html
0
 
wamlinkAuthor Commented:
>>Make sure your paralle port is set the the correct mode
In the article, this person uses ECP.  I looked in device manager for my setting and read that mine is also ECP.
>>When I did some things in vb6 for IO to the port I had to place the dll in the vb 6 running folder (as in the folder that Visual Basic was running from)
One place that I moved the dll into was the same folder that contains the executable for VB.  I don't think that the program has a problem finding the dll because if I change the alias to something other than out32, then the error that I get aludes to the fact that this namespace cannot be found (I can't remember the exact error.  If it helps, I'll run it again when I return home today to my PC).
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
wamlinkAuthor Commented:
>>try this link:
"How to access serial and parallel ports by using Visual Basic .NET"
http://support.microsoft.com/kb/823179 
Since I am using VB 2005 Express, I clicked on the link to "For a Microsoft Visual Studio 2005 version of this article, see 904795 (http://support.microsoft.com/kb/904795/). " that is on this page.  Unfortunately, this page only describes the way to access the serial ports.  On this page they also give this clause "Note You cannot use the Microsoft .NET Framework classes to directly access other types of ports, such as parallel ports or USB ports."  ???  To me it sounds like Microsoft is saying that they don't have a solution to access the parallel port in VB 2005.

>>and also:
"VB.Net Reading Parallel Port Under Windows XP/2000"
http://www.experts-exchange.com/Programming/Programming_Languages/Q_20818873.html
I will try these tonight.
0
 
wamlinkAuthor Commented:
chmdznr, by following your second link I have come across winio.dll.  When using it, I don't get the exception, but I still have an issue:  Both functions that I'm using (InitializeWinIo() and SetPortVal(...) ) always return false.  SetPortVal does not seem to change the port values either.  Also, it's not clear to me how the data types in the parameters of SetPortVal and GetPortVal map to the data types for Visual Basic 2005.
0
 
wamlinkAuthor Commented:
OK this is what I have found so far ... winio.dll requires winio.sys in order to function, and this sys file *must* be placed in the same folder that contains the program executable.

Here are my declarations:

Option Explicit On

    Declare Function InitializeWinIOFunc Lib "winio.dll" Alias "InitializeWinIo" () As Byte
    Declare Function GetPortValFunc Lib "winio.dll" Alias "GetPortVal" (ByVal wPortAddr As UInt16, ByRef pdwPortVal As UInt32, ByVal bSize As Byte) As Byte
    Declare Function SetPortValFunc Lib "winio.dll" Alias "SetPortVal" (ByVal wPortAddr As UInt16, ByVal dwPortVal As UInt32, ByVal bSize As Byte) As Byte
    Declare Sub ShutdownWinIoFunc Lib "winio.dll" Alias "ShutdownWinIo" ()

These seem to work: whatever I write to the port I can also read back.
- I still need to check the port pins with a multimeter to verify that they're changing levels.
- So far I've only tried reading/writing address 378.
0
 
chmdznrCommented:
please inform us if you have succeded
0
 
wamlinkAuthor Commented:
chmdznr,
I have succeded after following the advice on one of your suggested links.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now