Solved

port output in VB

Posted on 2000-03-02
16
352 Views
Last Modified: 2008-02-01
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
Comment
Question by:smegghead
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +5
16 Comments
 
LVL 12

Expert Comment

by:pjknibbs
ID: 2576887
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
 
LVL 4

Accepted Solution

by:
PBuck earned 50 total points
ID: 2577118
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
 
LVL 14

Expert Comment

by:mcrider
ID: 2577135
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 32

Expert Comment

by:Erick37
ID: 2578085
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
 
LVL 32

Expert Comment

by:Erick37
ID: 2578125
Make that:

Call PortOut(&H300, 128)
0
 
LVL 12

Expert Comment

by:roverm
ID: 2579507
Using the API 'CreateFile' it can be done!
Still researching.....

D'Mzzl!
RoverM
0
 
LVL 10

Author Comment

by:smegghead
ID: 2579529
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
 
LVL 10

Author Comment

by:smegghead
ID: 2579535
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
 
LVL 12

Expert Comment

by:pjknibbs
ID: 2579560
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
 
LVL 1

Expert Comment

by:Ask_ED
ID: 2581873
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
 
LVL 32

Expert Comment

by:Erick37
ID: 2583472
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
 

Expert Comment

by:wayreth
ID: 2586023
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
 

Expert Comment

by:wayreth
ID: 2586025
Also,

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

has many utilites for parallel port / I/O access.
0
 
LVL 10

Author Comment

by:smegghead
ID: 2596613
Thanks PBuck, that did the trick.. I used something called DirectIO.

Thanks also to everyone else for their comments.
0
 
LVL 4

Expert Comment

by:PBuck
ID: 2596659
Super!  I am glad that you got it working.  Now I know who to go to when I need to use that control.  :-)
0
 
LVL 10

Author Comment

by:smegghead
ID: 2596776
I'll expect a 100 pointer !!!
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

736 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question