y3ss

Hi Guys,

Anybody know how to read/write data from/to Parallel ports i'm using VB2005 with .Net Frameworks.

Thanks A lot for any help

y3ss-THQ



Re: Visual Basic Language Read/write Parallel Port

Spidermans_DarkSide - MSP, VSIP

y3ss wrote:

Hi Guys,

Anybody know how to read/write data from/to Parallel ports i'm using VB2005 with .Net Frameworks.

Thanks A lot for any help

y3ss-THQ

Hi,

I helped someone on another forum site to do just that but using VB6 on http://www.programmmersheaven.com

If i can find my post and convert the project, i will post the code here.

He was then able to connect the eight data lines through relays to switch electrical devices on and off as the end user wanted to set each bit high or low to turn each relay on or off respectively.

The code could be easily changed to write out any byte values through the parallel port.

The thread in question i have just found again at >>

http://www.programmersheaven.com/mb/basic/334560/334616/ReadMessage.aspx S=B20000#334616

My userName on that forum site is DrMarten

Regards,

S_DS






Re: Visual Basic Language Read/write Parallel Port

Spidermans_DarkSide - MSP, VSIP

Hi,

Here is the same project but converted for VB.Net but i could not find the file inpout32.dll in the C:\WINDOWS\system32\

folder in Win XP.

Maybe it is now the input.dll file

It uses 10 buttons and a textbox and it should turn the 8 data lines high / low with the first eight buttons.

Regards,

S_DS

___________________________

Public Class Form1

Dim LEDs As Integer

Dim motor1 As Boolean

Dim motor2 As Boolean

Dim motor3 As Boolean

Dim motor4 As Boolean

Dim motor5 As Boolean

Dim motor6 As Boolean

Dim motor7 As Boolean

Dim motor8 As Boolean

Dim Port1 As Integer

Private Declare Function Inp Lib "inpout32.dll" Alias "Inp32" (ByVal PortAddress As Integer) As Integer

'The next two lines should be one line of code in your code window.>>

Private Declare Sub Out Lib "inpout32.dll" Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Integer)

Private Sub DisplayText()

'Limit the value to within a BYTE value.

If LEDs > 255 Then LEDs = 255

'Show value sent to the PARALLEL port in TEXTBOX1.

TextBox1.Text = LEDs.ToString

'Send the VALUE held in variable LEDs

Out(Port1, LEDs)

End Sub

'The next two lines should be one line of code in your code window.>>

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

'Turn motor1 off.

If motor1 = True Then

LEDs = LEDs - 1

motor1 = False

Else

'Turn motor1 on.

LEDs = LEDs + 1

motor1 = True

End If

DisplayText()

End Sub

'The next two lines should be one line of code in your code window.>>

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

'Turn motor2 off.

If motor2 = True Then

LEDs = LEDs - 2

motor2 = False

Else

'Turn motor2 on.

LEDs = LEDs + 2

motor2 = True

End If

DisplayText()

End Sub

'The next two lines should be one line of code in your code window.>>

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

'Turn motor3 off.

If motor3 = True Then

LEDs = LEDs - 4

motor3 = False

Else

'Turn motor3 on.

LEDs = LEDs + 4

motor3 = True

End If

DisplayText()

End Sub

'The next two lines should be one line of code in your code window.>>

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

'Turn motor4 off.

If motor4 = True Then

LEDs = LEDs - 8

motor4 = False

Else

'Turn motor4 on.

LEDs = LEDs + 8

motor4 = True

End If

DisplayText()

End Sub

'The next two lines should be one line of code in your code window.>>

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

'Turn motor5 off.

If motor5 = True Then

LEDs = LEDs - 16

motor5 = False

Else

'Turn motor5 on.

LEDs = LEDs + 16

motor5 = True

End If

DisplayText()

End Sub

'The next two lines should be one line of code in your code window.>>

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

'Turn motor6 off.

If motor6 = True Then

LEDs = LEDs - 32

motor6 = False

Else

'Turn motor6 on.

LEDs = LEDs + 32

motor6 = True

End If

DisplayText()

End Sub

'The next two lines should be one line of code in your code window.>>

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click

'Turn motor7 off.

If motor7 = True Then

LEDs = LEDs - 64

motor7 = False

Else

'Turn motor7 on.

LEDs = LEDs + 64

motor7 = True

End If

DisplayText()

End Sub

'The next two lines should be one line of code in your code window.>>

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click

'Turn motor8 off.

If motor8 = True Then

LEDs = LEDs - 128

motor8 = False

Else

'Turn motor8 on.

LEDs = LEDs + 128

motor8 = True

End If

DisplayText()

End Sub

'Turn all the Motors/LEDs ON.

'The next two lines should be one line of code in your code window.>>

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click

LEDs = 255

DisplayText()

End Sub

'Turn ALL the Motors/LEDs OFF.

'The next two lines should be one line of code in your code window.>>

Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click

LEDs = 0

DisplayText()

End Sub

End Class

Regards,

S_DS






Re: Visual Basic Language Read/write Parallel Port

y3ss

Hi S_DS,

Thanks a lot for your reply, i will try it later. What i need to do is to access parallel port and read every byte received. It should be similar method rite i'll let you know what i found. Thanks again.

y3ss-THQ





Re: Visual Basic Language Read/write Parallel Port

y3ss

Hi S_DS,

1 more question, as the purpose i want to access parallel port is to trace the data send between a PC and Printer, is it the same method as what you implemented in previous project so using Inp32, it will only read 1 byte rite then how to check the receive buffer

In serial port, you need to open the port before you can use it, and when you open a port, the port will be owned by your application and will not be able to used by others, is it the same to parallel port

Thanks a lot,

y3ss-THQ





Re: Visual Basic Language Read/write Parallel Port

Spidermans_DarkSide - MSP, VSIP

y3ss wrote:

Hi S_DS,

4 more questions, as the purpose i want to access parallel port is to trace the data send between a PC and Printer, is it the same method as what you implemented in previous project Almost except use Inp or the Alias of Inp32 to get any of the input.

So using Inp32, it will only read 1 byte rite Yes, i guess so.

Then how to check the receive buffer Sorry i can't test it myself as i don't have a parallel port printer anymore, so i can't answer this one, unless i borrow a parallel port printer.

I don't know where my parallel lead has gone either.

In serial port, you need to open the port before you can use it, and when you open a port, the port will be owned by your application and will not be able to used by others, is it the same to parallel port

I think both ports have a busy line which is set high by the printer, or at least the parallel port has, from what i remember.

I would interested to know how you get on with this as i currently have no way of testing the DLL file, so i am not sure if you could intercept the bytes sent and received to your printer using a VB.Net application. I can't see why not though.

This may need to be done using a background worker or to fast enough ( maybe ), such a program may need to be written in C, C# or C++ and then compiled as a native executable file or written in assembly language. I just don't know on this question, once again sorry.

I have posted the possible means to get you started, maybe someone else in these forums can help you further, anyone else please

Thanks a lot,

y3ss-THQ

Hi,

I have just downloaded inpout32.dll from >>

http://www.dll-files.com/dllindex/dll-files.shtml inpout32

Click on the link labelled as Click here to go to the download of inpout32.dll on that page or this page.

Then put a copy of it in your C:\windows\system32\ folder once you unzip it.

Regards,

S_DS






Re: Visual Basic Language Read/write Parallel Port

Spidermans_DarkSide - MSP, VSIP

y3ss wrote:

Hi S_DS,

Thanks a lot for your reply, i will try it later. What i need to do is to access parallel port and read every byte received. It should be similar method rite i'll let you know what i found. Thanks again.

y3ss-THQ

Hi,

Calling Out will send bytes out through the port.

Calling Inp will read bytes in.

I now use a printer on one of my computers USB ports so i have no way of testing the DLL as I don't have any external parallel port hardware anymore, sorry.

Regards,

S_DS






Re: Visual Basic Language Read/write Parallel Port

Spidermans_DarkSide - MSP, VSIP

Hi,

Keep an eye on this thread i have started for you.>>

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1856230&SiteID=1&mode=1

Another thought, look at the bytes of a print file if you want to see what is sent to the printer then send the output to a file instead, before you print it.

The print file will be different from the original text or picture file or whatever as there will be embedded printer command bytes within the file. Some applications / programs allow you to do this.

Regards,

S_DS






Re: Visual Basic Language Read/write Parallel Port

Spidermans_DarkSide - MSP, VSIP

Hi,


See also>>

http://support.microsoft.com/default.aspx/kb/823179

Thanks to Bruno Yu - MSFT for the above link in this thread.>>

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1630926&SiteID=1

Regards,

S_DS






Re: Visual Basic Language Read/write Parallel Port

y3ss

Hi S_DS,

I'm not intercep the data sent to/from printer. What i do is i have a normal cable which connect a PC with a printer, then at the middle of the cable, i create a branch that connect to another PC. so all the data sent by PC or Printer will also be sent to this PC. Now i want to create a program for this PC to trace all the data. I did the same things to serial port and they work quite well.

Thanks,

y3ss





Re: Visual Basic Language Read/write Parallel Port

Spidermans_DarkSide - MSP, VSIP

y3ss wrote:

Hi S_DS,

I'm not intercep the data sent to/from printer. What i do is i have a normal cable which connect a PC with a printer, then at the middle of the cable, i create a branch that connect to another PC. so all the data sent by PC or Printer will also be sent to this PC. Now i want to create a program for this PC to trace all the data. I did the same things to serial port and they work quite well.

Thanks,

y3ss

Hi,

Wow what a setup!!

It is still one way of intercepting or interrogating the data, but doing it that way your 2nd PC is just on "listen" mode so it is like you listening in to a converstion.

Is this a project where you are just curious what goes on between a PC and a printer, or are you trying to resolve a printer problem

Regards,

S_DS






Re: Visual Basic Language Read/write Parallel Port

y3ss

Hi S_DS,

This is a project. I need to build a tool for my laptop that able to trace all the data sent by host (bank system) to/from printer. The purpose is to make sure that our printer could adapt and work with bank system. So i need to trace all the raw data sent by bank system. Yes, my tool will only act as listener.

Regards,

y3ss-THQ