Serial
This article may require cleanup to meet LabVIEW Wiki's quality standards. Please improve this article if you can. |
This article or section needs to be wikified to meet LabVIEW Wiki's quality standards. Please help improve this article with relevant internal links. |
This article or section needs to be updated. Some information on it may be out of date, and should not be relied on. Please improve this article if you can. |
Contents
Access the IO ports under NT/2K
Unfortunately, or some would say fortunately, you cannot access the ports (using IN PORT and OUT PORT) directly under operating systems such as Windows NT and Windows 2000. To access the ports 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 with 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 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 set up 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
To send an audio message by phone you need a voice modem. Unfortunately some of the commands required differ from one manufacturer to other. Thus a VI done for a specific modem might not work for another type.
To have a modem independant interface you could also use the Windows Telephony API (TAPI) on Windows systems. Unfortunately this would invlolve delving into DLL calls from within LabVIEW (not for the faint hearted). Indeed, some of the system calls required to get this to work are quite cryptic. However at least on Windows, the telephone line of a voice modem is configured as a Sound I/O device and LabVIEW recognizes it. Unfortunately, it does not seem to be possible to use Sound VIs to send/receive audio messages from LabVIEW to the telephone line (it would be GREAT!).
Below are the commands required for a Rockwell Semiconductor Systems series of modems. The instructions were pulled from the "AT Commands for RCV56ACx, RCV336ACx, RCV288ACx, and RCV144ACx Modems" Reference manual. Hopefully they will guide you through the requirements for your specific modem.
All the send commands should be preceded by "AT". The commands are shown as send (SND) and receive (RCV) pairs.
SND: #CLS=8 Configure the modem for Voice Mode (still ADPCM). RCV: OK The modem agrees, and is now set up for voice.
SND: #BDR=16 The DTE knows that compression requires a 38,400 bps speed, so it forces this as the new speed. RCV: OK This OK message is sent at 2400 bps, but the modem then switches to 38,400 bps.
SND: #VLS=0 This ensures that the telephone line is selected. RCV: OK The modem agrees.
SND: #VRA=45 The DTE allows 4.5 seconds for ringback to stop before assuming that the modem thinks that the remote has answered. RCV: OK The modem agrees with the DTE's assumption.
SND: DT6807 The DTE makes a telephone call, and the modem dials and goes through call progress. BUSY or NO DIALTONE can be detected, but in this example, the modem gets ringback. VCON This message is sent 4.5 seconds after the third ringback cadence is detected by the modem. The modem is in effect assuming that the remote telephone was answered on the third ring because no fourth ringback was detected before the #VRA time-out. The modem enters Online Voice Command Mode, and DTMF and answer tone detection is enabled. (Note that during this period, the modem might have detected answer tone from a data modem. In this case, the appropriate shielded code has to be sent prompting the DTE to pursue a data handshake.)
SND: #VTX The DTE has a message to send. RCV: CONNECT The modem says: "send it."
SND: The DTE sends the message: "Hi Dave. Your mother called." RCV: Procedure complete. VCON DTMF still active.
SND: H The DTE has completed its forwarding task.
is the audio data stream of the message to send. 1,2,4 and 8 bits "compression" (read resolution) are supported. This example is for 4 bits compression , if the message data has 8 bit resolution, you packed the 4 MSbits of every two bytes in a single byte and send it. (ASCII 8) is the escape code for shielded codes; you have to send it twice when encountered in the data stream. You end data stream with . 4 bits compression requires at least DTE (computer) connection at 38400 bps, 8 bits requires 115000 bps.
Dialing a Phone
Tone dialing is a combination of two tone frequencies output through your system's soundcard. Version 5.1 contains an example on how this is achieved in EXAMPLES\SOUND\SNDEXAMPLE.LLB\SIM PHONE.VI. The frequencies (Hz) to output are:
Number Hightone Lowtone 1 1209 697 2 1336 697 3 1477 697 4 1209 770 5 1336 770 6 1477 770 7 1209 852 8 1336 852 9 1477 852
- 1209 941
0 1336 941
- 1477 941
LabVIEW also allows direct access to the serial lines and can dial a modem using standard modem commands.