Discussion:
Controlling relay board via printer cable
(too old to reply)
gwilbob
2008-08-01 15:40:19 UTC
Permalink
Hello all, Please bear with me as I am an absolute beginner with LabVIEW, but want to learn.My boss has asked me to try and write a program to control a PC relay driver board, which is here: http://www.quasarelectronics.com/3074.htmAccording to the user manual "you can write your own programs in any language to output a byte to the printer port and the bits which are high will turn on the corresponding relay. The overlay on the PCB shows which bit in the output byte turns that particular relay on. For example, output 00010001, or 11 in hex turns on relays 1 & 5. Each relay number is also marked on the overlay for easy reference." Do I need a printer driver, do I need a DLL?Could anybody show me where I should start, or lead me through some way? To me the problem sounds like it might be relatively easy, but too much for meany help would be greatly appreciatedthanks, Gwilym
JoeLabView
2008-08-01 15:40:21 UTC
Permalink
This is quite easy actually.  I've done this type of relay control in the past... works well..
Do I need a printer driver, do I need a DLL?
No.  All you need is your PC and the Labview Development System.  You may have to change some settings in the PC's BIOS.  I'll look for the post I wrote on this.
Could anybody show me where I should start, or lead me through some way?
Yes.  Open LabVIEW
Under the Help menu, select >Find Examples
Do a search on "Parallel Port"  There are two examples that will be useful.  You will need to set the addres of your port, which you can find in the Control Panel > System >  Hardware Tab > Device Manager
Look under COM & LPT Port, and open the properties for the LPT port.  The resource address should be there.  Mine is : 0378
Follow the instructions in the example.  You can experiment a little and wtach how it controls the relays.
In the meantime, I will look for the thread & a document that discusses this subject.
R
JoeLabView
2008-08-01 16:10:05 UTC
Permalink
Have a look at <a href="http://forums.ni.com/ni/board/message?board.id=170&amp;view=by_date_ascending&amp;message.id=96484#M96484" target="_blank">this thread.</a>
And <a href="http://forums.ni.com/ni/board/message?board.id=170&amp;view=by_date_ascending&amp;message.id=96480#M96480" target="_blank">this post.</a>
which has a .pdf document called: General Information on Parallel Ports.pdf
Let me know how it goes.
R Message Edited by JoeLabView on 08-01-2008 11:41 AM
gwilbob
2008-08-01 16:40:18 UTC
Permalink
I'm afraid that the .pdf is at far too high a level for me, but I'm looking at the second example and trying to understand it by deleting things and seeing what happens. thanks for such a quick response!
gwilbob
2008-08-06 15:10:11 UTC
Permalink
It's been working really well and I've been having a lot of fun, but I've come upon a problem that none of the tutorials I find seem to solve, probably because it is so basic that its obvious: I can't tunnel out of a For Loop.I'm using a modified version of the "parallel read and write" example and am trying to send to the out port for a user selected number of cycles, then go on to send a different set of signals to the port. I thought that I could use a For Loop to control how many times, and then put a Sequence Structure around all of that to cover what happens after the For Loop has run its course.Eventually I'm aiming towards having a button that allows the user to just insert or put on the end another frame in said Sequence Structure should they wish to have more sets of cycles.Could anybody put me right in my misunderstanding and put me back on track (again)?thanks in advance!Gwilp.s. Our lab only has LabVIEW 7.1, is this a problem?Message Edited by gwilbob on 08-06-2008 10:00 AM


gwilsworkingwell.vi:
http://forums.ni.com/attachments/ni/170/347100/1/gwilsworkingwell.vi
gwilbob
2008-08-08 13:40:06 UTC
Permalink
I've looked at quite a few of the tutorial, but I can't solve what I imagine is a simple: how to do something for a specified time or number of cycles, then do something else for a different specified time or number of cycles, for example flash the boolean LED. Is there a simple way of doing this that I've missed?I've tried to do it by using two different For loops and local variables, but the local variable only gets sent and the beginning and end of the looping.Sorry about this continued pestering, but I do seem to be getting somewhere, even if it doesn't look like it externally...thanks!
smercurio_fc
2008-08-06 15:40:08 UTC
Permalink
You actually are tunneling out. The problem is that a for-loop will automatically try to auto-index on input and outputs. On outputs it will try to generate an array, which is what is happening on your "outbound" tunnels. If you have the Context Help window open and put the wiring tool on the wire it will tell you the problem. For the numeric wire you want to disable auto-indexing. To do so, right-click on the tunnel and select the "Disable Indexing". For the error wire you actually want that to be a shift register so the error is passed around each iteration so that if an error occurs in one iteration it doesn't get lost. Auto-indexing and shift registers are explained in the LabVIEW Help and in the tutorials. I didn't completely understand what you were describing with sequence frames and buttons.
JoeLabView
2008-08-06 17:10:09 UTC
Permalink
To learn more about LabVIEW, I suggest you try looking at some of <a href="http://wiki.lavag.org/LabVIEW_tutorial#External_Links" target="_blank"> these tutorials</a>.
smercurio_fc
2008-08-08 14:40:09 UTC
Permalink
There is no need to use a local variable to do that. Do you have a background in text-based languages? I ask because most people who have done text-based programming and start out programming in LabVIEW immediately start using local variables thinking that LabVIEW works the same way as text-based languages. A front panel control can be set to blink by simply setting the blinking property. The blinking rate is set in the LabVIEW options:<img src="Loading Image..."> If you want to use a different blinking rate use a shift register in a loop:<img src="Loading Image..."> Message Edited by smercurio_fc on 08-08-2008 09:35 AM


Example_VI_BD6.png:
http://forums.ni.com/attachments/ni/170/347878/1/Example_VI_BD6.png


Example2_VI_BD.png:
http://forums.ni.com/attachments/ni/170/347878/2/Example2_VI_BD.png
gwilbob
2008-08-08 15:10:10 UTC
Permalink
Yes, I only have experience from a small amount of text-based programming, you guessed correctly! Either way, the blinking is not the important bit, it's just a test output.Doing something for a period of time,&nbsp; then doing something else is what I can't get a hold of. Can you help with that one?thanks again!Gwilym
smercurio_fc
2008-08-08 15:40:07 UTC
Permalink
Well, the question is a bit vague so I will have to provide a general answer. There's a number of ways to do this depending on what you're doing inside the loop that you want to run for a certain length of time. One simple way to do it is to use the Elapsed Time VI. The attached example shows how to blink one LED at one rate for 3 seconds, and then a second LED at a different rate for 3 seconds.


blink.vi:
http://forums.ni.com/attachments/ni/170/347905/1/blink.vi
gwilbob
2008-08-08 16:10:06 UTC
Permalink
Do you think that you could save that as a LabVIEW 7.1, please? thanks for the reply!
gwilbob
2008-08-12 16:40:18 UTC
Permalink
My program is progressing extremely well, and I'm learning a lot, but I've got stuck again: If I have 3 different tasks each inside its own While Loop (as per the example kindly provided above), I'd like to run one and then the second and then third, but sometimes I'd like to miss out the second. I tried to make a control using two Boolean Ands in the style that your stairs lights are connected, but whatever I do it sends a signal out (true or false) which triggers both loops.I want it to send on the signal received to one of the loops, and do nothing to the other.This sounds awfully complicated to describe!Can anybody help? I'd imagine that this is quite a quick fix if you have the knowledge...thanks!Gwilym
JoeLabView
2008-08-12 16:40:22 UTC
Permalink
It sounds like you need a State Machine architecture.
Do a search on "State Machine".&nbsp; There are plenty of examples within this forum.
R
gwilbob
2008-08-13 11:40:23 UTC
Permalink
Code as requested. The selector.vi doesn't do what I want- all I need is like the example below, I think!I would have each of the instances as separate subVIs, but since there are switches inside the loops LabVIEW says making them into subVIs will alter the functionality.I'll look at State Machines now, thanks for the tipoff!&nbsp;&nbsp;<img src="Loading Image..." border="0" alt="What I d really like" title="What I d really like" width="252" height="46" align="left"> Message Edited by gwilbob on 08-13-2008 06:17 AM


eitheror.PNG:
http://forums.ni.com/ni/attachments/ni/170/348921/1/eitheror.PNG


works.vi:
http://forums.ni.com/ni/attachments/ni/170/348921/2/works.vi


selector.vi:
http://forums.ni.com/ni/attachments/ni/170/348921/3/selector.vi
smercurio_fc
2008-08-08 16:10:07 UTC
Permalink
Here you go...


blink_7.1.vi:
http://forums.ni.com/attachments/ni/170/347915/1/blink_7.1.vi
smercurio_fc
2008-08-12 16:40:20 UTC
Permalink
You may be getting to the point where you would want to use a <a href="http://zone.ni.com/devzone/cda/tut/p/id/3024" target="_blank">state machine</a>. It sounds like your logic is a little messed up. Please post your code if possible or at the very least a screenshot (in PNG format, not BMP).
smercurio_fc
2008-08-13 14:40:06 UTC
Permalink
Ummm... Your code is a mess. Really. Each of your loops appears to be identical. This means subVI. Since you want to have the loop stop from the front panel control you can pass a reference of the &quot;Stop&quot; button to the subVI so it can read its value. And I couldn't follow your Boolean logic at all.
Continue reading on narkive:
Loading...