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

port output in VB

Is it possible, using VB, to output a byte to a port address.

We've got a piece of hardware which controls a relay, this hardware sits on base address &h0300 - All we want to do is the equivalent of.

OUT 0300,255

or

OUT 0300,0

Is there an API function call I can call from within VB ??
0
smegghead
Asked:
smegghead
  • 4
  • 3
  • 2
  • +5
1 Solution
 
pjknibbsCommented:
Unfortunately the Win32 API is designed to be machine-independent, which means there's no API which does what you want. In addition, accessing hardware directly like this isn't allowed under Windows NT, although you might get away with it for a while under Win9x.

I think you'd have to write your own Windows driver for the hardware in question, and that's definitely outside the realm of Visual BASIC!
0
 
PBuckCommented:
One day while I was cruising the Internet looking For parallel output inFormation, I Found this site with a Few Freeware and shareware controls.

I have not had a chance to try any oF these, but it looks like it might be right down your alley.

http://www.lvr.com/parport.htm

*At the bottom oF this page "Programming" are the controls.

**Don't mind my F's - my lower case F is not working today ... dang it!

I hope this link will help you out.  Good luck!
0
 
mcriderCommented:
smegghead,

If you can get your hands on a copy of Microsoft's GWBasic, you can use it to do what you want...  It has the OUT command, and it works just like you want.


Cheers!
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Erick37Commented:
Use the _outp command from a c DLL:

//~~~C DLL~~~
#include <windows.h>
#include <conio.h>

int CALLBACK LibMain (HANDLE hInstance, WORD wDataSeg,
                                WORD wHeapSize, LPSTR lpszCmdLine)
{
      return 1;
}

void __stdcall PortOut(unsigned short cPort, char cValue)
{
      _outp(cPort, cValue);
}

'~~~~Call it from VB~~~~
Option Explicit

Private Declare Sub PortOut Lib "dlltest" _
    (ByVal cPort As Integer, ByVal cValue As Byte)

Private Sub Command1_Click()
    Call PortOut(300, 128)
End Sub
0
 
Erick37Commented:
Make that:

Call PortOut(&H300, 128)
0
 
rovermCommented:
Using the API 'CreateFile' it can be done!
Still researching.....

D'Mzzl!
RoverM
0
 
smeggheadAuthor Commented:
Ok,

I'm SURE I added a comment here this morning.... I must have closed the window without sumbitting..

Basically, I asked if the 'c' function will work under WinNT. I tried yesterday with some delphi code which includede assembly language to output to the port.

I've also looked at the web-site PBuck suggested.. It looks like that probably has what I want, although I've not got it working yet !!

Smeg.
0
 
smeggheadAuthor Commented:
PS. The delphi code came up with an error saying 'priveleged instruction'.

I've also tried it using 'qbasic' is this the same as the suggested 'gwbasic' ?? With Qbasic, the command OUT &H0300,&HFF doesn't error, but doesn't perform the desired effect either.
0
 
pjknibbsCommented:
Accessing I/O ports from user mode under NT is not permitted, which is why you're getting "privileged instruction" errors. I suspect the QBasic OUT() instructions are being routed to a virtual machine and never getting anywhere near the *physical* ports. I don't think you can do what you want without going into kernel mode.
0
 
Ask_EDCommented:
Hi,

Direct from their documentation:
NTPort Library is also an ideal replacement of old BASIC IN or OUT statement.

Try:
http://www.zealsoftstudio.com/ntport/

NTPort Library provides support for Windows 95/98 and Windows NT. Cost $ 30 USD

Hope this helps
ED
0
 
Erick37Commented:
From:
http://msdn.microsoft.com/library/backgrnd/html/msdn_realtime.htm

Q. Does Windows NT support direct I/O and memory access?

A. In general, Windows NT does not allow an application direct access to I/O ports. If this is needed, a driver needs to be
written.
0
 
wayrethCommented:
Hi,

I've used MMPort in the past to access I/O's directly.  This works under NT.  The site says that it's NT only but I think I may have had it running under 9x before...  Unfortunately it doesn't come with a VB Header file, but you could probably derive this from the VC++ header file.

It's available at

http://sunst50.einev.ch/references/mondada/mmp/
0
 
wayrethCommented:
Also,

http://www.lvr.com/parport.htm

has many utilites for parallel port / I/O access.
0
 
smeggheadAuthor Commented:
Thanks PBuck, that did the trick.. I used something called DirectIO.

Thanks also to everyone else for their comments.
0
 
PBuckCommented:
Super!  I am glad that you got it working.  Now I know who to go to when I need to use that control.  :-)
0
 
smeggheadAuthor Commented:
I'll expect a 100 pointer !!!
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.

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