Ano Ano Posted November 30, 2011 Report Share Posted November 30, 2011 Hello, Is it possible write a Labview code to turn on and off LED's via the serial port (9-pin) of a PC? Thank you in advance, Quote Link to comment
Roderic Posted November 30, 2011 Report Share Posted November 30, 2011 yes I guess so... Quote Link to comment
ShaunR Posted November 30, 2011 Report Share Posted November 30, 2011 Yup, but you only get 4 (DCD, DTR, RI and RTS). You also need a 4k7 resistor in line to limit the current (supply, according to spec, is +-15V by the way-so choose an appropriate LED, although most motherboard manufacturers run off of +-12V). Quote Link to comment
Saverio Posted November 30, 2011 Report Share Posted November 30, 2011 Of course, the next obvious question will be: "how do I control those lines from LabVIEW?". Answer: Look at the shipping examples. Help -> Find Examples. Then search for "serial". Then open the example "Troubleshooting Serial Line Monitor". Quote Link to comment
hooovahh Posted November 30, 2011 Report Share Posted November 30, 2011 I'd also be curious to know if someone has examples on how to essentially take over the serial port manually. I found this knowledge base that looks like it may help you but I've never done it personally. http://digital.ni.com/public.nsf/allkb/1ECEFAA7AD52994986256966005356EA Quote Link to comment
Saverio Posted November 30, 2011 Report Share Posted November 30, 2011 Did you look at the serial port example that I pointed out? Or do you mean something else when you say "take over the serial port manually"? Quote Link to comment
asbo Posted November 30, 2011 Report Share Posted November 30, 2011 Perhaps he means every line, not just DTR and RTS. Quote Link to comment
Saverio Posted November 30, 2011 Report Share Posted November 30, 2011 Unfortunately, VISA doesn't let you toggle the RX and TX lines, as these are controlled by whatever UART is used. Quote Link to comment
Ano Ano Posted December 1, 2011 Author Report Share Posted December 1, 2011 WOW Thank you for all these replies! Can Labview control the LED's via the PC parallel port (old printer port)? Quote Link to comment
ShaunR Posted December 1, 2011 Report Share Posted December 1, 2011 Can Labview control the LED's via the PC parallel port (old printer port)? Much better than serial (8 bit bi-directional, i.e digital inputs OR outputs ). My favourite low cost digital IO. Fantastic for foot-switches and system monitoring and essentially free. Unfortunately, not many PCs come with them nowadays. http://digital.ni.com/public.nsf/allkb/B937AC4D8664E37886257206000551CB There are also a couple of examples in the "Example" finder. You have to check whether your motherboard already has pull-up resistors (most do, some don't). Then you can connect 5V LEDs directly or just short them to ground (if using as digital in). Note that logic is reversed since you sink to ground THROUGH the IO line to light an LED. I always stick a transistor in there too to be on the safe-side, since if you get it wrong...you blow the port. It also inverts the logic so I don't get confused (happens regularly). http://www.beyondlogic.org/spp/parallel.htm 2 Quote Link to comment
Saverio Posted December 1, 2011 Report Share Posted December 1, 2011 (edited) Then you can connect 5V LEDs directly or just short them to ground (if using as digital in). This would actually need to be checked. If a computer comes with a parallel port it's likely to be 3.3V, not 5V. I know the old Dells we still have in the lab are 3.3V parallel ports. In the end, it's probably better to go with an off-the-shelf cheap USB-based digital I/O module. There's tons of these on the market. Edited December 1, 2011 by Saverio Quote Link to comment
ShaunR Posted December 1, 2011 Report Share Posted December 1, 2011 (edited) This would actually need to be checked. If a computer comes with a parallel port it's likely to be 3.3V, not 5V. I know the old Dells we still have in the lab are 3.3V parallel ports. Why is 3,3v a problem? In the end, it's probably better to go with an off-the-shelf cheap USB-based digital I/O module. There's tons of these on the market. Chicken Seriously though. This is kindergarten stuff. But if you've never used a screwdriver as a chisel, then maybe it's better to just throw money at it. Not one of mine by the way Edited December 1, 2011 by ShaunR Quote Link to comment
Saverio Posted December 1, 2011 Report Share Posted December 1, 2011 Why is 3,3v a problem? I didn't say it was a problem. I said it needed to be checked. You would need a different resistor value and what's considered "high" would be different. Chicken Seriously though. This is kindergarten stuff. But if you've never used a screwdriver as a chisel, then maybe it's better to just throw money at it. And when your motherboard gets damaged because you connected something improperly, or did not properly ground, or did not properly account for potential overvoltages or voltage spikes, then we'll see what's cheaper: buying a new computer or buying a cheap digital I/O module. P.S. I always use a screwdriver as a hammer. Quote Link to comment
ShaunR Posted December 1, 2011 Report Share Posted December 1, 2011 (edited) I didn't say it was a problem. I said it needed to be checked. You would need a different resistor value and what's considered "high" would be different. Parallel ports are TTL compliant. So that means anything between 2.7v and 5v is considered "high" (conversely 0-0.5v is low). A diode only needs a forward voltage of about 2v so it's not a problem. The resistor isn't there as a potential divider. It's there to limit the current so you don't fry the port and/or the LED. For this purpose, the lower the voltage, the less current->good thing! A 4k7 resistor (470 with pull-ups if you want to be ultra safe) will give you about 1ma@5v with no pull-ups, or, if you like 0.7ma@3.3. If you find its not bright enough then a 1K will give you 5/3ma but I wouldn't go any lower without buffering. But it's not hard. You can forget the maths. A 10k pot and an ammeter will give you the perfect values for your port. Just twiddle it (the technical term) until you get the brightness you want whilst keeping an eye on the current. You can then measure it and find a preferred value for when you "productionise" it You'll be wanting to drive LCD displays in no time 3.5 Using the Parallel Port of the Computer (click on "more" to expand the article) And when your motherboard gets damaged because you connected something improperly, or did not properly ground, or did not properly account for potential overvoltages or voltage spikes, then we'll see what's cheaper: buying a new computer or buying a cheap digital I/O module. P.S. I always use a screwdriver as a hammer. You'll only blow the port. If you never use it, you won't miss it Edited December 1, 2011 by ShaunR Quote Link to comment
Ano Ano Posted December 8, 2011 Author Report Share Posted December 8, 2011 Much better than serial Indeed it is! I got the parallel port working (for the serial port I could only control one LED). I had to go to bios to tell it to use only the EPP for the parallel port (LPT1) http://imageshack.us/photo/my-images/267/parallelport.jpg/ The problem though is that when I boot/start the PC, the port automatically turns on all LEDs. How can I "tell" the PC to keep the LEDs "off" until I use them in Labview?? Quote Link to comment
Tim_S Posted December 8, 2011 Report Share Posted December 8, 2011 (edited) The problem though is that when I boot/start the PC, the port automatically turns on all LEDs. How can I "tell" the PC to keep the LEDs "off" until I use them in Labview?? That's a classic problem; [low cost] DIO cards have a tendency to set their outputs high when initialized by software. I've solved it previously by having one of the outputs go to a on after delay relay which turned on control power to the rest of the outputs. Not a great solution (relying on the problem to solve the problem), but we needed something cheap and immediate. EDIT: Hit post and realized you can have a switch that turns on "control power", which is power to anything that can move. The outputs of the parallel port can't drive much, so you'll need a transistor, relay or the like if you're driving something more than a LED. Edited December 8, 2011 by Tim_S Quote Link to comment
Ano Ano Posted December 8, 2011 Author Report Share Posted December 8, 2011 The problem is that when the computer starts, it turns on by default the LED without me running the Labview software. How can I change this? Quote Link to comment
Tim_S Posted December 8, 2011 Report Share Posted December 8, 2011 The problem is that when the computer starts, it turns on by default the LED without me running the Labview software. How can I change this? You don't; the pull-up resistors keep the level high until told otherwise. You invert the output instead. 1 Quote Link to comment
Ano Ano Posted December 9, 2011 Author Report Share Posted December 9, 2011 You don't; the pull-up resistors keep the level high until told otherwise. You invert the output instead. Invert the output in Labview? Can I invert it via the motherboard/bios? Quote Link to comment
Tim_S Posted December 9, 2011 Report Share Posted December 9, 2011 You can't invert through the motherboard or BIOS. There is no setting LabVIEW can get to which will have the parallel port data bits go low instead of high on power up. I was referring to treating the output as inverted signal. Quote Link to comment
Ano Ano Posted December 9, 2011 Author Report Share Posted December 9, 2011 Hello, I built an application that turns off the LED and then auto-closes. I edited the registry so that it runs this application during startup. The problem is that the PC starts, the application opens and closes, but it does not switch off the LEDs. I think its because the drivers (NI? Win7?) may not load in time. Any advice/idea on how to tweek this and make it work? Quote Link to comment
asbo Posted December 9, 2011 Report Share Posted December 9, 2011 Do you have error handling to diagnose what's happening? If a program needs drivers, the OS should load them automatically, preventing the application from executing before they're ready. Quote Link to comment
Ano Ano Posted December 12, 2011 Author Report Share Posted December 12, 2011 Do you have error handling to diagnose what's happening? If a program needs drivers, the OS should load them automatically, preventing the application from executing before they're ready. I am using as base code the "Out Port8.vi" (see http://imageshack.us/photo/my-images/708/lptoff.jpg/). Top part works when the driver is found. Bottom part is vice versa. I placed a small delay to give the OS some time to seek drivers and varied the time from 500 to 5000 and it did not matter much as it cannot located the drivers. as a .vi the program works perfect. as an .exe it does not. Why does it have hard time locating the drivers? Quote Link to comment
Ano Ano Posted December 12, 2011 Author Report Share Posted December 12, 2011 Hello, It seems that the error that Labview produces is "−4850" which states that: "LabVIEW does not support this device driver on Windows Vista or later." This is strange though as the program works as a .vi but does not work as an .exe I am running LV2010.1 & Win 7 Is there a solution for this driver issue? Quote Link to comment
Saverio Posted December 12, 2011 Report Share Posted December 12, 2011 A warning about those VIs: Vista and Windows 7 impose more strict security on direct access to hardware. If you want to manipulate the parallel port, use VISA. There's an example that ships with LabVIEW. That said, the likely reason is that the required DLL is not being copied to you application's data folder. This is not surprising, given that those VIs shouldn't be used in the first place. See here: http://digital.ni.com/public.nsf/allkb/496CD7613F331EA4862571E200633507 2 Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.