- RS232 communication with a microcontroller using LabVIEW VISA configure serial port Writing to the serial port Introduction There are many standards describing the connection between a PC and a microcontroller to exchange data (USB, RS232, GPIB.). The RS232 standard describes.
- Looking at LabVIEW's serial communication example (NI Example Finder»Hardware Input and Output»Serial»Simple Serial.vi), you will notice that it starts with a VISA Configure Serial Port node. This sets up both the termination character (which defaults to hex 0A ('linefeed')) and the timeout (defaults to 10 seconds).
May 19, 2009 I am trying to establish a serial communication between Labview 8.6 and Arduino Duemilanova board via USB. I read that USB is the same as RS-232 serial communication just that the USB has a built in USB/RS-232 adapter in it.
Java Project Tutorial - Make Login and Register Form Step by Step Using NetBeans And MySQL Database - Duration: 3:43:32. 1BestCsharp blog 4,643,318 views. Jul 22, 2014 For printing with serial communication and earlier versions of LabVIEW, see the link below. If the printer is connected to a local parallel port as LPT1 (or LPT2, etc.), you can use the Serial Port Write VI. For more information, see the Serial Port VIs chapter in your LabVIEW documentation.
1. Loopback Test to Verify Hardware Operation
Labview Serial Port Communication Example
There are three ways to verify the operation of the serial port: LabVIEW, HyperTerminal, and LabWindows/CVI. All perform a loopback test on the serial port by shorting out the Transfer and Receive pins on the cable connected to that port. Step 1 is the description for shorting the pins and is the first step to all three. The LabVIEW procedure is listed below, and both the HyperTerminal and LabWindows/CVI procedures are linked at the end of the page. Use the following procedure if you are using LabVIEW.
- Connect a cable to your serial port. The most common port is a 9-pin or 25-pin (DB-9 or DB-25) RS-232 port. On the cable, short lines 2 and 3. This connects the Transfer line coming out of the computer to the Receive line going in. Once shorted, the top row of the DB-9 cable should look like this: [1 2=3 4 5]. An easy way to short pins 2 and 3 is to use a paper clip. If you have a female RS-232 cable, bend the paper clip and stick the ends in the second and third hole. If you have a male cable, bend the paper clip in a way that you shorten the long loop to the same length as the short loop. Then you can clamp it on the two pins.
On an RS-485 port, voltages are referenced differentially. Therefore, short TXD+ and RXD+ together and then TXD- and RXD- together (pin 4 to 8 and pin 5 to 9 on a DB-9 cable; pin 1 to 5 and pin 2 to 4 on a Combicon connector). Make sure your software is configured in four-wire mode. - For HyperTerminal or LabWindows/CVI, follow the links at the end of the page.
- For LabVIEW, follow the link 'Loopback Test for Serial Port.' This takes you to the Loopback VI in the Example Program Database, which is a part of the Technical Support page. You need to unzip the file. This VI is written in LabVIEW 4.0.1 and will write a string of words out of the serial port and then read them back in. Before running the VI, make sure to set the port channel correctly. In LabVIEW, zero represents the first serial port. [PC: 0 = COM1, 1 = COM2,.. Mac: 0 = Modem, 1 = Printer,.. Sun: 0 = ttya, 1 = ttyb,..]
- If this works correctly and the string of words is read back in, the serial port hardware works. Most serial port communication problems are in the program and concern timing of read/writes calls or configuration of the serial port.
2. Common Problems
Most problems are in the program, not the hardware. Always use example programs as a reference point for ways to wire the diagram panel. Use the sample VIs shipped with LabVIEW under Help>>Search Examples or from the VIs located in the Examples Program Database linked at the end of the page.
Port Referencing: In LabVIEW, ports are numbered starting at zero. Therefore, port 0 in LabVIEW is COM 1 on a PC.
[PC: 0 = COM1, 1= COM2,.. Mac: 0 = Modem, 1 = Printer,.. Sun: 0 = ttya, 1 = ttyb,..]
Timing In Program, Hanging: Many times, a read operation is performed on a port that results in the Serial Port Read VI stopping and waiting or 'hanging.' One way this can happen is if a read operation is done to the port and the program specifies a certain number of bytes that the Serial Port Read VI should get. The Serial Port Read VI was told to get a designated number of bytes; if there are not that many bytes in the serial port receive buffer, it waits until more bytes are written to the serial port. If no more bytes are written to the serial port to complete the operation, the program hangs and waits indefinitely. This can be eliminated by using the Serial Read with TimeOut VI in Help>>Search Examples>>Serial Communication. Another method is to use the Bytes At Serial Port VI to check the port and see how many bytes are in the buffer. Wiring the result as the input for the number of bytes to read ensures that the read operation completes. Looking at the examples under serial communication in LabVIEW is an excellent starting point.
Timing In Program, Incomplete Transfer: A common problem is when a read operation is done on the serial port and it does not get the complete string of information expected. This may happen when you have a read operation happening before the write operation has time to complete. This could be resolved by using a Sequence structure or by using data flow dependency. Using a Sequence structure with the read after the write will make sure the data is completely written first. Using data flow requires a wire to be connected to the read VI after (downstream) the initial write VI.
Instrument's Termination Character: Serial communication can be very tricky when trying to communicate with devices, because the serial port will output exactly as programmed. This means you must know and program the exact sequence of code, including termination characters, to ensure the instrument operates properly. Common problems occur in not using the termination character required by the instrument or by leaving an extra space/character in the instruction string. There is a new standard for communicating with devices in LabVIEW called Virtual Instrument Software Architecture (VISA), a single interface library for controlling VXI, GPIB, RS-232, and other types of instruments. If you are having problems with serial I/O, VISA is a great way to help eliminate termination character errors and make your code reusable and interchangeable between devices in the future.
Port Referencing: In LabVIEW, ports are numbered starting at zero. Therefore, port 0 in LabVIEW is COM 1 on a PC.
[PC: 0 = COM1, 1= COM2,.. Mac: 0 = Modem, 1 = Printer,.. Sun: 0 = ttya, 1 = ttyb,..]
Timing In Program, Hanging: Many times, a read operation is performed on a port that results in the Serial Port Read VI stopping and waiting or 'hanging.' One way this can happen is if a read operation is done to the port and the program specifies a certain number of bytes that the Serial Port Read VI should get. The Serial Port Read VI was told to get a designated number of bytes; if there are not that many bytes in the serial port receive buffer, it waits until more bytes are written to the serial port. If no more bytes are written to the serial port to complete the operation, the program hangs and waits indefinitely. This can be eliminated by using the Serial Read with TimeOut VI in Help>>Search Examples>>Serial Communication. Another method is to use the Bytes At Serial Port VI to check the port and see how many bytes are in the buffer. Wiring the result as the input for the number of bytes to read ensures that the read operation completes. Looking at the examples under serial communication in LabVIEW is an excellent starting point.
Timing In Program, Incomplete Transfer: A common problem is when a read operation is done on the serial port and it does not get the complete string of information expected. This may happen when you have a read operation happening before the write operation has time to complete. This could be resolved by using a Sequence structure or by using data flow dependency. Using a Sequence structure with the read after the write will make sure the data is completely written first. Using data flow requires a wire to be connected to the read VI after (downstream) the initial write VI.
Instrument's Termination Character: Serial communication can be very tricky when trying to communicate with devices, because the serial port will output exactly as programmed. This means you must know and program the exact sequence of code, including termination characters, to ensure the instrument operates properly. Common problems occur in not using the termination character required by the instrument or by leaving an extra space/character in the instruction string. There is a new standard for communicating with devices in LabVIEW called Virtual Instrument Software Architecture (VISA), a single interface library for controlling VXI, GPIB, RS-232, and other types of instruments. If you are having problems with serial I/O, VISA is a great way to help eliminate termination character errors and make your code reusable and interchangeable between devices in the future.
3. Virtual Instrument Software Architecture (VISA)
VISA is a single interface library for controlling VXI, GPIB, RS-232, and other types of instruments on all LabVIEW platforms. VISA is a standard endorsed by the VXIplug&play Systems Alliance, which includes more than 35 of the largest instrumentation companies in the industry. The VISA standard unifies the industry to make software interpretable and reusable over time and regardless of instrument I/O operation. Linked below is a page to help with VISA questions. VISA VIs for LabVIEW 4.x are linked at the end of the page.
See Also:
Serial, GPIB, and VXI Communication with Measurement Studio VISA
VISA Examples for LabVIEW 4.1
4. Printing Reports & Error 37
LabVIEW 5.1 for Windows includes Report Generation VIs that allow you to send text to the printer. For an example of how to use the Report Generation VIs, select Help>>Search Examples>>Advanced>>Report Generation. For printing with serial communication and earlier versions of LabVIEW, see the link below.
If the printer is connected to a local parallel port as LPT1 (or LPT2, etc.), you can use the Serial Port Write VI. For more information, see the Serial Port VIs chapter in your LabVIEW documentation.
If the printer is a network printer, you cannot use the Serial Port Write VI; you must use other methods to print, such as one of the following:
Labview Serial Port Example
- Use Programmatic Printing of a subVI to programmatically print a string. Select Print VI When VI Completes Execution in VI Setup of the subVI.
- Use the System Exec VI to print a string programmatically by using Notepad.exe. The string to use in the System Exec VI could be: Notepad.exe /p c:junk.txt, where junk.txt is the name of an ASCII text file containing the text to be printed.
For problems with Error 37, follow the link below to check the settings in the labview.ini file.
See Also:
Error 37 and writing to the Parallel Port with LabVIEW
5. Modem Communication in LabVIEW
Companies in the Alliance Program support modem communication in LabVIEW very well. National Instruments recommends these companies because of their quality work.
See Also:
Alliance Program
6. User Support Newsgroups
The Developer Exchange newsgroups are Usenet newsgroups covering National Instruments products, as well as general fields of science and engineering. You can read, search, and post to the newsgroups to share solutions and find additional support from other users. Past questions and solutions are also stored at this site for search purposes.
7. Advanced Troubleshooting of COM Port Data
Advanced users who want to analyze the exact bits being transferred over the serial port to detect differences between programs (for example, LabVIEW vs. HyperTerminal) can use a program called Portmon. System Internals provides Portmon, and the company's Web site provides you advanced utilities, technical information, and source code related to Windows 9x and Windows NT/2K internals.
See Also:
System Internals for Portmon
Related Links:
Testing Serial Communication using HyperTerminal
Testing Serial Communication using CVI
Loopback Test for Serial Port
Using the VISA classes in Measurement Studio to Perform Serial Communication
Active2 years, 3 months ago
I am controlling a device over serial connection using LabVIEW (version 7.0). It is connected using USB, and is installed as a virtual serial port on the computer (running Windows XP). Every now and then my device crashes when my program sends a command, and it is unable to accept any more input (the device itself also stops working) until it has timed out.
I've looked at the serial port traffic using Portmon. Whenever the device crashes the serial driver sends the command I send using my program four times instead of just once, with an IOCTL_SERIAL_GET_COMMSTATUS command in between. I cannot see what this last command returns, but I assume something happens in the communication earlier on. I'm thinking my configuration of the port is not entirely right, but I have no idea how or why. I open and close the connection to my device every time I want to write something to it.
For completeness' sake: it has a baud rate of 9600, 8 bits, no parity, 1 stop bit, and no flow control. I'm aware that the correct settings of these parameters depend on the device, but the manufacturer has not supplied any recommended settings.
JuliusJulius
1 Answer
The driver is a DLL of some sort? If so, this is the most likely source of your problem, and you likely will need to contact the author of the driver. LabVIEW does have crashing bugs, but by far the most common source of crashes in simple communications apps is a buggy third-party DLL.
Cubase le download. It allows musician to compose and arrange the different type of music. Cubase 7 Free Download Full Version Crack new version has more upgraded features which make it higher than other. German companies ‘Steinberg’, who create Cubase 7 activation code, also give the bits of help to create and mix the music. Cubase 7 Free Download Full Version CrackCubase 7 activation code txt works on just 4 tables that highlight the editing of MIDI.
In other words, I doubt this is a LabVIEW problem at all and that you would have the same difficulty if you wrote a C program to talk to this driver. I only know what you've posted here about your system, but after many years of chasing down such issues, I would start with the device manufacturer/driver author.
If you have evidence to the contrary, please share.
srmsrm