Solved

port output in VB

Posted on 2000-03-02
16
311 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
  • 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now