Solved

port output in VB

Posted on 2000-03-02
16
344 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Prevent checkbox click event occur while editing it in vb6 8 57
Access Object Property from VBA Module in Excel 2010 2 37
Problem to With line 4 64
Problem to line 23 55
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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 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…

808 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