Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI
11 ratings:
 4.54 out of 5     Rate this Document

How Can I Use the ASCII Object in Lookout to Send Data to an external device?

Primary Software: Lookout
Primary Software Version: 5.0
Primary Software Fixed Version: N/A
Secondary Software: N/A

Problem: I would like to use Lookout to communicate to an external device through a serial port or ethernet. I know I need to use the ASCII object, but I don't understand how it works.

Solution: If you want to send and receive ASCII data from the serial port, you have to use the ASCII object. When sharing ASCII data over ethernet, you need to use the IPASCII object. If you want more information on the ASCII or IPASCII object, consult the reference manual or create a simple example using the tutorial below.

Follow these instructions to write a simple example using the ASCII object. By stepping through the process, you should get a good understanding of how the ASCII object works and how to program with it.

(Note: For example purposes, we will use the ASCII object for explanation. The only difference in the use of the ASCII object and the IPASCII object is the configuration of the parameters. After you have specified an IP address and a port for the external device, the IPASCII object in Lookout functions the same as the ASCII object.)

Before you open Lookout, connect a serial cable to one of your COM ports. In the example, COM1 is used. If you put your serial cable on a different COM port, then make sure to make the appropriate changes in your program. Take the other end of the cable and jump pins 2 and 3. To jump pins 2 and 3, use a paper clip to connect the two pins. A serial cable used with this configuration is called a loopback cable.

The following steps will work assuming that you do not have any other existing problems with your serial port. If you are not sure if you are having problems with your serial port, try to communicate with the port in Hyperterminal. Only one program at a time can access the serial port. So, if you check the port with Hyperterminal, make sure that Lookout is closed. Once you go into Lookout, make sure that no other program is trying to access the serial port.

We are going to send a number and a string to the serial port in this example. All of the objects are created assuming that the categorize box is not checked and the objects are then listed in alphabetical order.


  1. Open Lookout and create a new process.
  2. Go to Object ->Create -> Pot. Choose a minimum of 0, a max of 100, and a resolution of 1. When prompted, choose the digital entry display.
  3. Go to Object -> Create ->Text Entry. For the prompt, enter: Type a string.
  4. Go to Insert ->Text and type: Click here to enter a string. Place this text above your text entry box. This will let other users know about the text entry box.
  5. Go to Object ->Create-> Pushbutton. For the button text, enter Send.
  6. Go to Object ->Create-> ASCII. Make sure that the communication settings are ok. Again, if you are not sure, test these settings in Hyperterminal. The default settings are probably fine. Make sure that you place a check in the "Monitor Serial Port" box. Anytime you expect to receive data on the serial port (from another device, or in this case because we are using a loopback cable) you need to make sure that you tell Lookout to monitor that port looking for data.
  7. Go to Object ->Edit Connections. Select the ASCII object.
  8. In the connections box, choose the RequestFormat datamember. At this point, your connection should look like this ASCII1.RequestFormat =
  9. For the right hand side of the equation, type in "%d%s" Make sure you put this in quotation marks. By setting the RequestFormat to %d%s, you are telling Lookout that we are sending a decimal number followed by a string. You must specify both a RequestFormat and a ResponseFormat. This is the only way that Lookout knows the format of what you are sending/receiving from the serial port.
  10. Now, edit the connection of ResponseFormat to be ASCII1.ResponseFormat = "%d%s" With this connection, you are telling Lookout that you expect to receive a decimal number and a string. We are using a loopback cable, so our RequestFormat and ResponseFormat are equal. If we were not using a loopback cable, we might expect different formats. For example, you might send a serial device a string (RequestFormat = "%s"), but expect a number in return (ResponseFormat = "%d").
  11. At this point, you should still be in the Edit Connections window. Once we have set the ResponseFormat and the RequestFormat, Lookout knows what to expect. Since we told Lookout that we were sending a decimal number first, we need to edit the connection of the RQV1 member.
  12. Edit the connection of RQV1=Pot1
  13. Edit the connection of RQV2.txt = TextEntry1


** Why did we use RQV1 for the pot and RQV2.txt for the string?
When Lookout sends the data across the serial port, it sends whatever is in its RQV* members. RQV* is for numeric members. RQV*.txt is for string or text members and RQV*.logical is for logical members. If you set RQV1 = Pot1 and RQV1.txt = TextEntry1, you would have problems. Lookout sends its RQV* members in sequential order. If it had two members that were equal (RQV1 and RQV1.txt) it would not know which one to send first, and you would get unpredictable results.


  1. Edit the connection of ASCII1.Send = PB1 (or whatever you named your pushbutton).
  2. Make sure that you have all the proper connections and then click Quit to leave the Edit Connection Box.
  3. Go to Insert ->Expression and select ASCII1.Response. The Response member is what the device at the other end of the serial cable sees. Since we are using a loopback cable, our response is going to be the same as what we send.
  4. Go to Insert ->Text and type "Response String" Put this text over your response expression to label the response.
  5. Click CTRL-SPACEBAR to go into Run Mode. Change the value of your pot and your text entry field. Hit the Send button to send the response to your serial port. You should see the response in your Response Expression.


If you have problems getting your program to work, compare your lks file to the lks file attached below. You may need to confirm that your serial port is working properly.

Once you get this program working, try changing your RequestFormat and ResponseFormat strings. Try a "%d %s" (a space between %d and %s). See what happens if you change the RequestFormat string but not the ResponseFormat string (and vice versa).

If you have problems communicating with a serial device in the future, return to the loopback cable test to make sure you are sending the right data to the device.

Related Links:

Attachments:


aciiex.zip


Report Date: 11/02/1999
Last Updated: 01/05/2005
Document ID: 1R18NERM

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit