Transmitting Data over a Parallel Port

matt.cechner

New member
Joined
Aug 20, 2006
Messages
2
Programming Experience
Beginner
Hello, I am trying to convert some C# code I found for transmitting data over a parallel port to VB .net for part of an application I am developing for a university project. The original C# code works fine on my computer, but I seem to be having trouble linking the component parts of the code together.

My code is shown below (with the original Acknowledgement to the author of the C# code). I have not included the C# code because it is too long, but it can be found at The Code Project.

VB.NET:
'* -----------------------------------------------------------------
'* 
'* LED initialization code written by Levent S. 
'* E-mail: ls@izdir.com
'* 
'* This code is provided without implied warranty so the author is
'* not responsible about damages by the use of the code.
'* 
'* You can use this code for any purpose even in any commercial 
'* distributions by referencing my name. 
'* 
'* ! Don't remove or alter this notice in any distribution !
'* 
'* -----------------------------------------------------------------*/

Imports System
Imports System.Runtime.InteropServices

Public Class ParallelPort

    <DllImport("inpout32.dll", EntryPoint:="Out32")> _
     Public Shared Function Output _
          (ByVal adress As Integer, ByVal value As Integer)
    End Function

End Class

VB.NET:
Public Class Remote_Control
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
    ' Code not shown here

#Region " Variables "
    Dim address As Int16 = 888    ' Port Address
    Dim value As Int16 = 0        ' Ouput Value
#End Region

    Protected Overrides Sub OnPaint(ByVal paintEvent As PaintEventArgs)
        reset_LEDs()
    End Sub

    Private Sub reset_LEDs()
        value = 0
        ParallelPort.Output(address, value)
    End Sub

    Private Sub Data1_CheckBox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Data1_CheckBox.CheckedChanged
        If Data1_CheckBox.Checked Then
            value += Math.Pow(2, 0)
        Else
            value -= Math.Pow(2, 0)
        End If
        PllPort.Output(address, value)
    End Sub

    ' 7 more CheckChanged methods to make 
    ' up the 8 data bits on the parallel port
End Class
 
I haven't had a chance to check this out completley but the pinvoke call isn't quite right....

VB.NET:
<DllImport("inpout32.dll", EntryPoint:="Out32")> _
 Public Shared Sub Output(ByVal adress As Integer, ByVal value As Integer)
 End Sub
 
Back
Top