Example Code

TCP Client Custom Step in TestStand

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • Teststand

Code and Documents

Attachment

Description

Overview

This example provides custom step types that allow you to utilize TCP client side communication directly from TestStand.

 

Description

TCP is a client-server protocol widely used to exchange data over the network or internet. Many National Instruments products provide TCP communication capabilities, including LabVIEW, LabWindows/CVI, and Measurement Studio.

 

The TCP step types are an example of custom steps that integrate TestStand with TCP communication. This example provides a set of custom step types that you may insert into TestStand sequences to perform basic TCP client operations (Connect, Read, Write, and Disconnect) without the need for external code modules. The image below shows these steps types in use in a TestStand sequence.

 

TCPsteps.png

 

The Step types use a DLL developed in CVI to implement this functionality. The source files used to create this DLL is included with this example. If you need to perform more sophisticated TCP tasks, you can use the TCP/IP built-in functions available in LabVIEW or LabWindows/CVI to develop your required code.

 

Hardware and Software Requirements

TCP Custom Step_NIVerified.zip

TestStand 4.1.1 or Compatible

 

TCP Custom Step Legacy_NIVerified.zip

TestStand 4.1 and Previous

 

TCP Custom Step - TS 2017.zip

TestStand 2017 or compatible

CVI 2013 SP2 or compatible (to edit and build the source code).

 

Steps to Implement or Execute Code

TCP Custom Step_NIVerified.zip

  1. Download and extract all files in TCP Custom Step_NIVerified.zip to <TestStand Public>/Components/StepTypes/TCP
  2. Copy NI_TCPTypes.ini from <TestStand Public>/Components/StepTypes/TCP to <TestStand Public>/Components/TypePalettes
  3. Copy TCP.ico from <TestStand Public>/Components/StepTypes/TCP to <TestStand Public>/Components/Icons

TCP Custom Step Legacy_NIVerified.zip

  1. Download and extract all files in TCP Custom Step Legacy_NIVerified.zip to <TestStand>/Components/User/StepTypes/TCP
  2. Copy the NI_TCPTypes.ini from <TestStand>/Components/User/StepTypes/TCP to <TestStand>/Cfg/TypePalettes
  3. Copy the TCP.ico from <TestStand Folder>/Components/User/StepTypes/TCP to <TestStand>/Components/User/Icons

 After installing the step types, you will see a new folder in the insertion palette, containing four new step types:

 

1_20121127170451.png

 

Note: To use the step types, you must have an active TCP server application to connect to. If you do not have a TCP server application, use the TCP_server_example.exe server, located in the TCP Custom Step_NIVerified.zip attachment.

 

To see how the steps function, open the example sequence file, TCP Step Types Example.seq, and complete the following steps:

  1. Configure the TCP server to use port 10000 (or any available port). In the example server, this is specified upon launch.
  2. Ensure that the TCP connect step in the example file is using the same port as the server. To configure the step, right click it, then selecting Edit TCPConnect.
  3. Run the sequence using Execute»Test UUTs. You will be prompted to sent a message to the server. confirm that the message is written successfully in the server application
  4. The sequence will now wait for a message to be sent from the server. Type some text and confirm that it is displayed in the sequence file.
  5. Verify that the server recognizes that the connection has been closed after the disconnect step executes

 

Additional Information or References

TCP Connect Step

This step opens a connection to a TCP server. The following parameters can be configured by right clicking the step, then selecting Edit TCPConnect.

  • TCP Handle (Numeric): Numeric type variable used to store a handle to the TCP connection created by this step. This handle is used in all subsequent TCP steps.
  • Port: Specifies the Port number to establish a connection. A TCP server must be listening to this port for the connection to succeed
  • Server Name or IP Address(String): String data type that specifies the server IP address to connect. Use "localhost" to connect to a server on the current machine
  • Timeout (ms): Specifies how many milliseconds to wait before generating a timeout error.

 

TCP Write Step

This step writes string data to the TCP server. The following parameters can be configured by right clicking the step, then selecting Edit TCPWrite:

  • TCP Handle (Numeric): Numeric type variable used to define the current TCP connection. This handle is created using the TCP Connect Step.
  • Data (String): String data type that specifies the string to be sent to the TCP Server. You can directly specify the string to be sent or use TestStand string variables in this field.
  • Timeout (ms): Specifies how many milliseconds to wait before generating a timeout error.

 

TCP Read Step

This step waits for the TCP server to send a message. The following parameters can be configured by right clicking the step, then selecting Edit TCPRead:

  • TCP Handle (Numeric): Numeric type variable used to define the current TCP connection. This handle is created using the TCP Connect Step.
  • Data (String): String data type used to store the data read from the TCP Server.
  • Byte Count: Specifies the maximum number of bytes to read from the TCP Server.
  • Timeout (ms): Specifies how many milliseconds to wait before generating a timeout error.

 

TCP Disconnect Step

Closes a connection to a TCP Server. The following parameters can be configured by right clicking the step, then selecting Edit TCPDisconnect.

  • TCP Handle (Numeric): Numeric type variable used to define the current TCP connection. This handle is created using the TCP Connect Step.

 

The step types in this example demonstrate many of the recommended methods for custom step type development. For more information on custom step type best practices, refer to the Best Practices for Custom Step Type Development document (part of the NI TestStand Advanced Architecture Series).

 

Configuration of step instances

Since the TCP step types require a number of user-configured parameters, each type has custom properties to store step related data. For example, the TCP Write step type contains the Step.Result.Data property to store the data to write. In addition, each of the step types implements an edit substep, making it easy for a user to configure the custom step properties from a dialog box. The dialog box is implemented in a DLL, which uses the TestStand API to set the TestStand properties based on the user's configuration.

 

Run-Time functionality

The actual TCP functionality is implemented using pre-step substeps, defined in the step type. This approach is recommended because step instances will update if you modify the substep code module. The alternate approach of using a custom default module for a step type does not have this feature.

 

Notifying TestStand of configuration changes

When using the TCP steps, you will notice that the sequence file will indicate that a change has been made (by displaying a "*" after the file name) if you change the properties of a custom step. In order for this behavior to occur, it is necessary to call the IncChangeCount method on the sequence file to notify TestStand that the sequence file has changed:

tsErrChk(TS_SeqFileIncChangeCount (hSeqFile, NULL));

It is important to call this method if the sequence file is modified outside of the TestStand User Interface.

 

TestStand Help: Best Practices for Custom Step Type Development

TestStand Help: NI TestStand Advanced Architecture Series

Example Program: NI TestStand Featured Examples

Mark M.
Applications Engineering
National Instruments

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
hmiraquesa
Member
Member
on

Hi Mark, 

 

Is there a chance that you have a 64Bit version of the TCPSteps.dll?

Greil
Member
Member
on

Buggy.

The function "TCPRead" returns more bytes than was sent by "TCP_server_example.exe".

 

e.g. Server sends "AAA", but TestStand 2017 received some extra random content.

Screenshot.png