Reading and Writing From USB and RS-232

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to read from and write to USB and RS-232 ports in a new project I'm
working on. I was thinking about using C#, but I'm not sure if there's a way
to do this in that language. If not, any suggestions on what to use? (ie.
Visual C++, Visual Basic, etc). Thanks for any feedback.
 
Hello, JRB!

I can help you with RS-232 (it is COM port right?)

C# cannot help you directly C++ (VC++, perhaps) can!
But some smart people have already done that for you...
All you have to do is download the libraries from websites
provided and use my wrapper class (or create your own)
and then try doing whatever you intended to do...

I have 2 libraries to access any port by its address
(according to description of the authors or the libraries,
see below)
It worked well on my printer port (as long as you specify
port address correctly, which you can get from
System Information or Device Manager...)
Goto www.google.ca and search for 'inpout32.dll' and 'io.dll'
(filesizes are 32K and 45K respectively)

The documentation for inpout32.zip can be found at:
http://www.lvr.com

The documentation for IO.DLL can be found at:
http://www.geekhideout.com/iodll.shtml


Make sure to read the documentation first as one of the versions
of inpout32.dll works only with Win32, 16 bit requires a different
driver.
I think, io.dll worked on both 16 and 32 bit platforms...
Anyway, read the documentation and download the file or files.
Documentation contains all information you need to know, and I didn't
change the method names for IO.DLL... (that helps, eih?)
Here is wrapper class for C# that I've created for both libraries
(if you decide to use only one library, remove the code for the other,
otherwise, it won't compile. And, btw, the .dll file has to be in the same
folder as you compiled program executable - not the sourcecode(!),
in most cases it is \bin\Debug\)
______________________________________________________________________
using System;
using System.Runtime.InteropServices;

namespace PortInterop
{
public class InpOut32
{
[DllImport("inpout32.dll", EntryPoint="Inp32")]
public static extern byte Input(int PortAddress);

[DllImport("inpout32.dll", EntryPoint="Out32")]
public static extern void Output(int PortAddress, int Value);
}

public class IO
{
[DllImport("io.dll")]
public static extern void PortOut(int Port, char Data);

[DllImport("io.dll")]
public static extern void PortWordOut(int Port, int Data);

[DllImport("io.dll")]
public static extern void PortDWordOut(int Port, int Data);

[DllImport("io.dll")]
public static extern char PortIn(int Port);

[DllImport("io.dll")]
public static extern int PortWordIn(int Port);

[DllImport("io.dll")]
public static extern int PortDWordIn(int Port);

[DllImport("io.dll")]
public static extern void SetPortBit(int Port, char Bit);

[DllImport("io.dll")]
public static extern void ClrPortBit(int Port, char Bit);

[DllImport("io.dll")]
public static extern void NotPortBit(int Port, char Bit);

[DllImport("io.dll")]
public static extern int GetPortBit(int Port, char Bit);

[DllImport("io.dll")]
public static extern int RightPortShift(int Port, int Val);

[DllImport("io.dll")]
public static extern int LeftPortShift(int Port, int Val);

[DllImport("io.dll")]
public static extern int IsDriverInstalled();
}
}
______________________________________________________________________

You would probably have to worry about USB yourself
One of those libraries (or even both) might actually work
with USB as well.
Please let us know the result, as I am planning to do
something with USB later in the near future...

Thanks.

You wrote on Sun, 12 Sep 2004 16:45:02 -0700:

J> I need to read from and write to USB and RS-232 ports in a new project
J> I'm working on. I was thinking about using C#, but I'm not sure if
J> there's a way to do this in that language. If not, any suggestions on
J> what to use? (ie. Visual C++, Visual Basic, etc). Thanks for any
J> feedback.


With best regards, Nurchi BECHED.
 
Hello, JRB!

I can help you with RS-232 (it is COM port right?)

C# cannot help you directly C++ (VC++, perhaps) can!
But some smart people have already done that for you...
All you have to do is download the libraries from websites
provided and use my wrapper class (or create your own)
and then try doing whatever you intended to do...

I have 2 libraries to access any port by its address
(according to description of the authors or the libraries,
see below)
It worked well on my printer port (as long as you specify
port address correctly, which you can get from
System Information or Device Manager...)
Goto www.google.ca and search for 'inpout32.dll' and 'io.dll'
(filesizes are 32K and 45K respectively)

The documentation for inpout32.zip can be found at:
http://www.lvr.com

The documentation for IO.DLL can be found at:
http://www.geekhideout.com/iodll.shtml

Make sure to read the documentation first as one of the versions
of inpout32.dll works only with Win32, 16 bit requires a different
driver.
I think, io.dll worked on both 16 and 32 bit platforms...
Anyway, read the documentation and download the file or files.
Documentation contains all information you need to know, and I didn't
change the method names for IO.DLL... (that helps, eih?)
Here is wrapper class for C# that I've created for both libraries
(if you decide to use only one library, remove the code for the other,
otherwise, it won't compile. And, btw, the .dll file has to be in the same
folder as you compiled program executable - not the sourcecode(!),
in most cases it is \bin\Debug\)
______________________________________________________________________
using System;
using System.Runtime.InteropServices;

namespace PortInterop
{
public class InpOut32
{
[DllImport("inpout32.dll", EntryPoint="Inp32")]
public static extern byte Input(int PortAddress);

[DllImport("inpout32.dll", EntryPoint="Out32")]
public static extern void Output(int PortAddress, int Value);
}

public class IO
{
[DllImport("io.dll")]
public static extern void PortOut(int Port, char Data);

[DllImport("io.dll")]
public static extern void PortWordOut(int Port, int Data);

[DllImport("io.dll")]
public static extern void PortDWordOut(int Port, int Data);

[DllImport("io.dll")]
public static extern char PortIn(int Port);

[DllImport("io.dll")]
public static extern int PortWordIn(int Port);

[DllImport("io.dll")]
public static extern int PortDWordIn(int Port);

[DllImport("io.dll")]
public static extern void SetPortBit(int Port, char Bit);

[DllImport("io.dll")]
public static extern void ClrPortBit(int Port, char Bit);

[DllImport("io.dll")]
public static extern void NotPortBit(int Port, char Bit);

[DllImport("io.dll")]
public static extern int GetPortBit(int Port, char Bit);

[DllImport("io.dll")]
public static extern int RightPortShift(int Port, int Val);

[DllImport("io.dll")]
public static extern int LeftPortShift(int Port, int Val);

[DllImport("io.dll")]
public static extern int IsDriverInstalled();
}
}
______________________________________________________________________

You would probably have to worry about USB yourself
One of those libraries (or even both) might actually work
with USB as well.
Please let us know the result, as I am planning to do
something with USB later in the near future...

Thanks.

You wrote on Sun, 12 Sep 2004 16:45:02 -0700:

J> I need to read from and write to USB and RS-232 ports in a new
project
I'm working on. I was thinking about using C#, but I'm not sure if
there's a way to do this in that language. If not, any suggestions on
what to use? (ie. Visual C++, Visual Basic, etc). Thanks for any
feedback.


With best regards, Nurchi BECHED.
 
Hello, JRB!

I can help you with RS-232 (it is COM port right?)

C# cannot help you directly C++ (VC++, perhaps) can!
But some smart people have already done that for you...
All you have to do is download the libraries from websites
provided and use my wrapper class (or create your own)
and then try doing whatever you intended to do...

I have 2 libraries to access any port by its address
(according to description of the authors or the libraries,
see below)
It worked well on my printer port (as long as you specify
port address correctly, which you can get from
System Information or Device Manager...)
Goto www.google.ca and search for 'inpout32.dll' and 'io.dll'
(filesizes are 32K and 45K respectively)

The documentation for inpout32.zip can be found at:
http://www.lvr.com

The documentation for IO.DLL can be found at:
http://www.geekhideout.com/iodll.shtml

Make sure to read the documentation first as one of the versions
of inpout32.dll works only with Win32, 16 bit requires a different
driver.
I think, io.dll worked on both 16 and 32 bit platforms...
Anyway, read the documentation and download the file or files.
Documentation contains all information you need to know, and I didn't
change the method names for IO.DLL... (that helps, eih?)
Here is wrapper class for C# that I've created for both libraries
(if you decide to use only one library, remove the code for the other,
otherwise, it won't compile. And, btw, the .dll file has to be in the same
folder as you compiled program executable - not the sourcecode(!),
in most cases it is \bin\Debug\)
______________________________________________________________________
using System;
using System.Runtime.InteropServices;

namespace PortInterop
{
public class InpOut32
{
[DllImport("inpout32.dll", EntryPoint="Inp32")]
public static extern byte Input(int PortAddress);

[DllImport("inpout32.dll", EntryPoint="Out32")]
public static extern void Output(int PortAddress, int Value);
}

public class IO
{
[DllImport("io.dll")]
public static extern void PortOut(int Port, char Data);

[DllImport("io.dll")]
public static extern void PortWordOut(int Port, int Data);

[DllImport("io.dll")]
public static extern void PortDWordOut(int Port, int Data);

[DllImport("io.dll")]
public static extern char PortIn(int Port);

[DllImport("io.dll")]
public static extern int PortWordIn(int Port);

[DllImport("io.dll")]
public static extern int PortDWordIn(int Port);

[DllImport("io.dll")]
public static extern void SetPortBit(int Port, char Bit);

[DllImport("io.dll")]
public static extern void ClrPortBit(int Port, char Bit);

[DllImport("io.dll")]
public static extern void NotPortBit(int Port, char Bit);

[DllImport("io.dll")]
public static extern int GetPortBit(int Port, char Bit);

[DllImport("io.dll")]
public static extern int RightPortShift(int Port, int Val);

[DllImport("io.dll")]
public static extern int LeftPortShift(int Port, int Val);

[DllImport("io.dll")]
public static extern int IsDriverInstalled();
}
}
______________________________________________________________________

You would probably have to worry about USB yourself
One of those libraries (or even both) might actually work
with USB as well.
Please let us know the result, as I am planning to do
something with USB later in the near future...

Thanks.

You wrote on Sun, 12 Sep 2004 16:45:02 -0700:

J> I need to read from and write to USB and RS-232 ports in a new
project
I'm working on. I was thinking about using C#, but I'm not sure if
there's a way to do this in that language. If not, any suggestions on
what to use? (ie. Visual C++, Visual Basic, etc). Thanks for any
feedback.


With best regards, Nurchi BECHED.
 
Back
Top