• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 300
  • Last Modified:

dll to read from lpt or serial

we have a device with a switch, this device will be connected to a PC from lpt or Com port. when the switch on it sends an electrical signal indicating that, and when it is off it will send a signals indecating that too,
i need to read these signals in vb.net programe,do i need special dll files, and if so where can find them,and how can i use them in vb.net .
any help please
0
jamal99
Asked:
jamal99
  • 5
  • 4
1 Solution
 
softplusCommented:
If you're using the serial port (COM), you can just use the vb6 MsComm32.ocx.
Otherwise, take a look at the following links:
Serial: http://www.codeworks.it/net/VBNetRs232.htm
Parallel: http://www.experts-exchange.com/Programming/Programming_Languages/Q_20818873.html
0
 
jamal99Author Commented:
thanx softplus , but i dint know how  to do it yet,
i did download the inpout32.dll.i dont know if it is useful.

but i need hel on how to include it in my application and how to let it read bytes from the port(com or lpt).


in fact i am a web developer, i dont know much about windows applications and api.
0
 
softplusCommented:
How far have you gotten? Which port are you trying to use first? What kind of data are you expecting from the port? :)
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
jamal99Author Commented:
not so far
i still cant include the dll in the project
please give me simple steps
just to include it and read when i want
0
 
softplusCommented:
OK, I assume you want to use the parallel port  first (from the inpout32.dll)? If so, I would throw the inpout32.dll away and use the io.dll from here: http://www.geekhideout.com/iodll.shtml
Then in your vb.net you will want to define your dll as follows in a seperate module file:
    Public Declare Sub PortOut Lib "IO.DLL" (ByVal Port As Short, ByVal Data As Byte)
    Public Declare Sub PortWordOut Lib "IO.DLL" (ByVal Port As Short, ByVal Data As Short)
    Public Declare Sub PortDWordOut Lib "IO.DLL" (ByVal Port As Short, ByVal Data As Integer)
    Public Declare Function PortIn Lib "IO.DLL" (ByVal Port As Short) As Byte
    Public Declare Function PortWordIn Lib "IO.DLL" (ByVal Port As Short) As Short
    Public Declare Function PortDWordIn Lib "IO.DLL" (ByVal Port As Short) As Integer
    Public Declare Sub SetPortBit Lib "IO.DLL" (ByVal Port As Short, ByVal Bit As Byte)
    Public Declare Sub ClrPortBit Lib "IO.DLL" (ByVal Port As Short, ByVal Bit As Byte)
    Public Declare Sub NotPortBit Lib "IO.DLL" (ByVal Port As Short, ByVal Bit As Byte)
    Public Declare Function GetPortBit Lib "IO.DLL" (ByVal Port As Short, ByVal Bit As Byte) As Boolean
    Public Declare Function RightPortShift Lib "IO.DLL" (ByVal Port As Short, ByVal Value As Boolean) As Boolean
    Public Declare Function LeftPortShift Lib "IO.DLL" (ByVal Port As Short, ByVal Value As Boolean) As Boolean
    Public Declare Function IsDriverInstalled Lib "IO.DLL" () As Boolean

Now you can access these functions directly, i.e. to get a byte of data from the port:
bytData = PortIn( (intPortNo) ) ' where intPortNo = the parallel port number

Note, I can't test this as I don't have anything that will send me data on LPT-Ports :)
0
 
jamal99Author Commented:
i will try ,and thanx alot but do i need to add a reference to the dll file?
0
 
softplusCommented:
no, you don't need to add a reference, as the functions are specifically declared for the DLL. The DLL needs to be in the path, possibly in the same directory as the exe-file. :)
0
 
jamal99Author Commented:
hello softplus , just on e more question.
how could i know the lpt port number, i maybe put a lpt switch so i can use the printer. so i dont know if this will causes a problem.???
0
 
jamal99Author Commented:
dear softplus ,
at last, the application works fine after doing some electical circuits , but the problem is that it works fine on some computers and only the (PortOut) on other computers,
do i need to do some configurations on the LPT port, or do i need to change som BIOS configurations, please advice so i let it work on these compters
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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