Ethernet communication Labview Communication protocol used in this project is TCP\IP. Robot is the client and the external PC is server. Setting Up A Server So a server is created on external system using labview. All the required VI’s are present in function palette under Data Communication->protocols>tcp\ip. First client sends a signal to server to start the communication and the server replies with a data packet which in our case is a XML string. Therefore “TCP Listen.vi” is used which waits for an incoming signal. Input Port:6008 Net address: String to IP. vi present TCP\IP palette.
Output Connection ID: Unique ID and is used in subsequent blocks. Remote Address: IP of the client(Robot).
Following is the communication flowchart:
As it is evident from the flowchart that after receiving the request from client data is sent to robot therefore we will use “TCP write.vi “ .
Input Connection ID: From TCP listen .vi Data In: Data to be written which is contents of file “ExternalData.xml”
Output Connection ID:Used in subsequent VI’s Bytes Written: No. Of bytes transferred to client.
After This robot replies with a XML string and “TCP Read.vi” is used for receiving the data packet.
Input Connection ID: From TCP Write .vi Bytes to read: No. Of bytes to be read 340 in this case . Use hit an trial method to figure out no. Of bytes.
Output Connection ID: Used in subsequent VI’s Data Out: Received Data .
Three main parts covered are:
2. Joystick interface with labview. 3. Setting up a server in labview . These 2 are integrated together for faithful communication.
It is the image of main VI Outer while loop runs continuously ,waiting for an incoming connection and after receiving the request the inner loop is executed. Contents of file ExternalData.xml are read using Read from text file.vi and is sent to robot using TCPwrite.vi. Robot sends a data packet and it is received using TCPread.vi. To send new data errorout of TCPread.vi is used.It is a cluster of 3 elements and one of them is a Boolean. When there is no error its value is false . A case structure is used and it has two cases either false or true. Errorout of TCP read.vi is connected to its input after inversion using not gate. Whenever server reads the data successfully it calls the structure and subvi is called.
Instead of using the received data for current coordinates content of ExternalData.Xml is used which has the last sent coordinates using Read from text file.vi(6) Read from text file.vi Input Output File(use dialog):Path of Text:Contents of the file externaldata.xml on the hard drive After reading the data we use Matchpattern.vi(1) to get the positon of values of X,Y,Z in the file. Match pattern.vi Input Output String: Connected to output of (6). Offset past match:Offset of the coordinates in the file. Regular string:String just before the value of coordinates. Different match pattern.vi is used for each coordinate. Offset is used to extract the values of coordinates using String subset.vi(2). String subset.vi Input Output String: Contents of Substring: Value of coordinate. externaldata.xml Offset: Connected to match pattern Length: Length of string to be extracted. Coordinates from String subset is the form of string and is converted to an integer using Frac/Exp string to number vi(3). These coordinates are added to the increment value obtained from joystick. New coordinate values are converted to string using Number to fractional string VI(5).
Number to fractional string VI Input Number: Input number
Output F-Format string: Coordinates in form of string.
Width: Number of digits needed to represent the number .Value is 7 Precision: Number of digits after decimal point. Value is 2. Using Replace substring vi (4)the values of coordinates are updated in externaldata.xml. Replace Substring vi Input Output String: content of ExternalData.xml Result string :complete string after replacing substring . Substring: Connected to (5). Offset: connected to match pattern vi. Length: length of substring. Three replace substring vi’s are used , the output of first vi will be the input of second and output of second will be the input of 3RD and output of 3RD will be the final string which is written in file EXternalData.xml . After the increment is calculated by moving the joystick ,button 2 is pressed which terminates the while loop and data is written to externaldata.xml using write to text file VI(7). Write to text file.vi Input File(use dialog):Path of externaldata.xml on the hard drive Text:Connected to output of 3RD
Replace substring vi. After the file is written, inner loop of main vi starts to execute and contents of updated externaldata.xml is sent to robot. This process continues and there is continuous exchange of XML strings between external pc and robot. All the string related VI’s are present in function palette under programming->string. VI’s related to text files are present in function palette under programming->File I\O. For any queries related to labview use Google or post the problem on official labview forum and someone will definitely reply to the query.
For complete project details visit ->ayushdewan.wordpress.com