Jump to content

Hardware

From LabVIEW Wiki
Revision as of 23:50, 17 March 2007 by MichaelAivaliotis (talk | contribs) (New page: == Access the IO ports under NT/2K == Unfortunately, or some would say fortunately, you cannot access the port's (using IN PORT and OUT PORT) directly under operating systems suh as Window...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Access the IO ports under NT/2K

Unfortunately, or some would say fortunately, you cannot access the port's (using IN PORT and OUT PORT) directly under operating systems suh as Windows NT and Windows 2000. To access the port's under these operating systems (and others like them) you need to download the AccessHW patch from NI's web site. Simply navigate to ni.com and enter "accesshw" in the search engine on the main page.

Printing to a line printer

You can use a line printer wuth LabVIEW, but you need to add a line to your LabVIEW ini file first. Although this is a perfectly valid solution to this problem you should read the excellent advice about this critical INI file in the section entitled "Should I play with the undocumented LabVIEW settings?".

First add the following as a single complete line: serialDevices="COM1;COM2;COM3;COM4;COM5;COM6;COM7;COM8; COM9;\\.\COM10;LPT1;LPT2;LPT3;LPT4" using a simple text editor such as NOTEPAD.

Second, you need to access the printer just as you would a normal serial device. In other words you must initialise the port (port 10 for LPT1) with the Serial Port Init VI and use the Serial Port Write VI to send the string to be printed direct to the printer. Note that this will pause your program execution until the printing is completed. To avoid this feature you will need to setup a separate process and pass the strings to be printed via a queue or global.

If you want access to the line printer in a built application, then the same rules for other LabVIEW ini file settings should be followed (see "How do I include ini settings in my built application?").

Find a single character in a serial input stream.

One method is to read all the bytes at the port. In a loop determine the number of bytes at the port using the "Bytes at Port.vi", passing the number of bytes to the "Serial Port Read.vi". Search the string returned using the "Split String.vi" or the "Scan String For Tokens.vi". If the character is not present, concatenate the read string with the data passed from the previous read (via a shift register) and continue to concatenate the string until the character is detected. If the character is present split the string at this point, passing the complete string to the processing VI, while passing the remainder of the split string back to the shift register to be concatenated with the next loop iteration (so there is no loss of data).

Using a Modem to Send Data

A modem can easily be accessed from LabVIEW using the standard serial port VI's. This is a fairly simple task using the Serial Driver Init VI directed to the port the modem's hooked to and send out the modem command strings like:

"ATZ" - reset the modem "ATFOO" where FOO is whatever special modem commands you want to send "ATDT19005551111" to dial 1-900-555-1111

After this just clear a string and sit in a loop building a string with whatever comes in the serial port until you get a CR character. Then search the string for the substring, "CONNECT" (if attempting to access another modem). If that's not in there, then repeat the process until either that happens or you get a timeout.

Once the modems are synced, the data can be sent after flattening it to string type. Make sure that packets of data are sent and if there are integrity issues then perhaps a CRC checksum should be included in each packet. If you want to disconnect then send out an "ATH1" to command to hang the modem up and finally close the serial port.

One fequently asked question is whether a WAV file can be played after initiating a dial out with a modem. No definitive answer has been posted, but it appears you would dial out as above. Instead of a CONNECT string response from the other modem, you could look at the return string which should contain the "RING" string when the modem is in verbose mode and dialing out. Once the RING string is not detected (or there are no other error messages) then it may be reasonable to suggest that someone/something has answered. How to play the WAV file is still an unanswered question apart from the inelegant method of then initiating playing the file out the soundcard lineout into the MIC of the modem.

Don't forget to send out a CRLF combination after every string you send out. In other words strings would look something like: ATZ/r/n. Furthermore, there needs to be a wait of at least 400mS for the "OK" return string after initializing the modem with "ATZ" before attempting to dial with the "ATDT" string.

There are also commercial toolkits available and there is an article in the LabVIEW Technical Resource (LTR, Vol 5(1)) that deals with sending messages to a pager, but involves modem initialization and control aspects that would be useful in setting up modem communications.

Using a modem to send an audio message