Does anyone know how to send bytes out the parralel or serial ports in VB? I looked through MSDN but couldn’t find it. IANAProgrammer, so please be gentle.
I found out how to send bytes to/from the serial port using the communications control, but I still can’t find anything about the Parralel port.
I did some research on this a little while back as part of a robot project that I really should dust off and finish.
VB doesn’t have native port addressing functionality, you have to add it in, fortunately there are a whole bunch of DLLs and controls out there to make this possible.
Here is a good place to start, but Googling on *Parallel programming Visual Basic should get you loads of alternatives.
Also, (please don’t take this the wrong way - I wouldn’t normally pick at spelling, but…) it’s parallel - the misspelling might be what is hampering your searches.
You can do rudimentary port access by treating them like a file:
open "LPT1:" for output as #1
print #1, "..."
close (1)
You can use both LPT and COM ports, and you can read as well as write, but you’re fairly limited since this doesn’t give you low-level control.
Sigh - oh for the good old days of real BASIC
Open “LPT1:” for output as #1
Print #1,“any damn thing you want”
Close #1
Doesn’t Work in Visual Basic.
Yes it does. I just tried it in VB5 and VB6 and it works fine.
I haven’t tried it in Visual-Fred, but I guess I wouldn’t be surprised if they broke this too. Granted, I haven’t used this construct in years and I’d recommend using lower-level port controls. But I used to use this file-handle method a lot in the old days prototyping data acquisition and control software, and that code still works in newer versions.
hmm… Locks up every time for me. Im using VB6.0 and it locks up in debug mode and also if I make and run the EXE.
And I’m running the Win2K OS.
Just tested the exact example code above on VB6, Win2K and it works fine. Of course, I had to manually form feed the printer to get the paper out, but I got my three dots.
Are you trying to send data to a printer or some other device BioHazard?
Some Other Device. All I need to do is send Hex bytes out the PPort.
OK, this is what I found:
http://www.paraport.net/
Does anyone know how to use a C/C++ DLL in a VB app? Links please unless someone wants to walk me through it.
Piece of cake. All you have to do is tell VB what each routine in the DLL that you want to invoke looks like using a ‘Declare’ statement, and then you just invoke it as if it’s a normal subroutine.
Your copy of Visual Basic probably came with something called the “API Viewer” which you can use to collect system templates to do this sort of thing. As a (silly) example, suppose you want to have your VB application invoke the “Sleep()” function that’s in the “kernel32.dll” library.
Somewhere in the beginning of you VB module, include the line:
Declare Sub Sleep Lib “kernel32” Alias “Sleep” (ByVal dwMilliseconds As Long)
And then invoke it with the statement:
Sleep(100) ’ to sleep 100 milliseconds
Thank you, Ill report back when I have it done, but I have to switch tasks for a while.
Well, I haven’t been able to get the API viewer to work, it seems like it can only look at text files and DB files.
I looked at the C headers that comes with it and it defines and uses a bunch of structs, so I doubt if the DLL is VB friendly. Im going to look into writing a VB-Friendly OCX using C++ that encapsulates the DLL. YES this is WAY over my head but im going to try anyway. If you never hear from me again, it means my head exploded.
Im also going to look into a couple other VB packages that support para IO in WinNT etc.
Any suggestions?