tcp ip external code

This is a discussion on tcp ip external code within the labview forums in Programming Languages category; Hello forum. Currently I'm trying to establish a TCP/IP connection between a server and client, in which the client has to be a labview written VI. The server and client communicates via a certain protocol. Can someone "translate' this protocol to Labview?   Description of the communication protocol - 1. Introduction The communication between Client and Server application is based on request ? response rule. Client application side requests and server side responses to it. Request is sent by the Client to the Server side. Type of request (and the response as well) is recognized by command number (field Command ...

Go Back   Application Development Forum > Programming Languages > labview

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 07-16-2008, 04:40 AM
Guilly
Guest
 
Default tcp ip external code

Hello forum. Currently I'm trying to establish a TCP/IP connection between a server and client, in which the client has to be a labview written VI. The server and client communicates via a certain protocol. Can someone "translate' this protocol to Labview?
 

Description of the communication protocol

- 1. Introduction

The communication between Client and Server application is based on request ? response rule. Client application side requests and server side responses to it.
Request is sent by the Client to the Server side. Type of request (and the response as well) is recognized by command number (field Command in the sent structure). Next, depending on type of request, Server responses to client by sending requested data.

- 2. General frame structure

The frame structure is like shown below:
FRAME = HEADER + DATA
Header consists of following fields:

- ? Type of command (public ushort Command) ? describes type of request (or response)

- ? Size of whole data package (header + data) (public int Lenght)

- ? Number of the next sent frame (public ushort CommandNo)

[ StructLayout( LayoutKind.Sequential, Pack = 1)]
public struct Header
{
public ushort Command;
public int Lenght;
public ushort CommandNo;
}

- 3. Command types and numbers

Command types and numbers are shown below:

- a) Commands sent by Client application



- ? LAN_CODE_GET_GPS_INFORMATION = 0x0005 ? requests to calculate and send new position

- ? INTERNAL_CODE1 = 0x0007 ? reserved

- ? INTERNAL_CODE2 = 0x0008 ? reserved


- b) Commands sent by Server application



- ? LAN_CODE_GPS_INFORMATION = 0x0006 ? sends calculated position

- ? INTERNAL_CODE3 = 0x0009 ? reserved

/// <summary>
/// Commands sent between client and server.
/// </summary>
public enum Commands
{
LAN_CODE_GET_GPS_INFORMATION = 0x0005,
LAN_CODE_GPS_INFORMATION = 0x0006,
INTERNAL_CODE4 = 0x0007,
INTERNAL_CODE5 = 0x0008,
INTERNAL_CODE6 = 0x0009,
}

- 4. Detail description of the commands


- 4.1 Requests

- 4.1.1 Calculate and send new position request

This request is sent by the client in order to calculate and send new position on the track by the server. Server reacts on it by sending calculated data in response described in 4.2.2 paragraph.

- a) Header

ushort Command = LAN_CODE_GET_GPS_INFORMATION = 0x0005
int Length = sizeof(Header)
ushort CommandNo ? unknown value (next message number)

- b) Data

No additional data.


- 4.2 Responses



- 4.2.1 Sending calculated GPS position with additional data

This response is reaction to "Calculate and send new position" request (paragprah 4.1.1). The position (and additional data) is sent in packed GPSInfo structure.

- a) Header

ushort Command = LAN_CODE_GPS_INFORMATION = 0x0006
int Length = sizeof(Header) + sizeof(GPSInfo)
ushort CommandNo ? unknown value (next message number)

- b) Data

Data is sent binary in structure shown below packed to byte array.
/// <summary>
/// Structure containing calculated data with additional info.
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct GPSInfo
{
/// <summary>
/// Calculated position.
/// </summary>
public PositionSt Position;
/// <summary>
/// Section id, on which train is.
/// </summary>
public int IdSection;
/// <summary>
/// USISID, on which train is.
/// </summary>
public double USISID;
/// <summary>
/// Actual mileage (in section).
/// </summary>
public double SectionMileage;
/// <summary>
/// Begin mileage of the section.
/// </summary>
public double SectionBeginMileage;
/// <summary>
/// End mileage of the section.
/// </summary>
public double SectionEndMileage;
/// <summary>
/// Mileage from odometer.
/// </summary>
public double OdometerMileage;
/// <summary&gt
Reply With Quote
  #2  
Old 07-16-2008, 06:40 AM
MikeS81
Guest
 
Default Re: tcp ip external code

Hi Guilly,
what do you expect from us? Do you want to learn how to do this, or do you want a ready "client"?
Mike
Reply With Quote
  #3  
Old 07-29-2008, 12:10 PM
Guilly
Guest
 
Default Re: tcp ip external code

Well if you could help me on my way...that would be nice :-)
Reply With Quote
  #4  
Old 07-29-2008, 12:10 PM
smercurio_fc
Guest
 
Default Re: tcp ip external code

Unfortunately, these forums are not a software development service. If you want to know how to do TCP/IP communication in LabVIEW, your best bet is to go through the LabVIEW tutorials first, and then look at the TCP/IP examples that ship with LabVIEW. The protocol you posted is quite specific, and while it would not be difficult to do, it's not something that someone is likely willing to do for free. :smileywink: You mentioned that the client "has to be a labview written VI". Why is this the case? Does this mean you have experience in other programming languages so you would know how to do this in that other language?
Reply With Quote
  #5  
Old 07-29-2008, 12:10 PM
F. Schubert
Guest
 
Default Re: tcp ip external code

You have to use the TCP functions of LabView to send and receive strings. As you write the client, your program is opening the connection (TCP open). The format of the strings you send and receive is defined in the document you posted. You can use the int to char function (don't have the correct name in mind) to convert the commands (given in hex code). Felix
Reply With Quote
  #6  
Old 07-29-2008, 12:40 PM
Guilly
Guest
 
Default Re: tcp ip external code

Thanks for the responses everyone...let me be more specific: I just need to know how I can send the message in the types defined by the communication protocol with the use of Labview. Yes, I have experience in other languages but that is not the point or else I wouldn't be here:smileytongue:. So instead of accusing me taking the easy ride, is there someone who can help me out?
 
Thanks in advance
Reply With Quote
  #7  
Old 07-29-2008, 01:40 PM
JoeLabView
Guest
 
Default Re: tcp ip external code

You can look under the Help Menu and select > Find Examples and do a search on TCP IP.  You should find some examples of LV code.
Have a look at the following threads.  I will try to place some that are either relevant, or contain examples of code, or issues that you may see as you write the code.
THis one has an example:&nbsp; <a href="http://forums.ni.com/ni/board/message?board.id=170&amp;message.id=79711&amp;quer y.id=147925" target="_blank">http://forums.ni.com/ni/board/message?board.id=170&amp;message.id=79711&amp;quer y.id=147925</a>
Here is an article: <a href="http://zone.ni.com/devzone/cda/tut/p/id/4579" target="_blank">http://zone.ni.com/devzone/cda/tut/p/id/4579</a>
TCP Architecture (multiple clients) : <a href="http://zone.ni.com/devzone/cda/tut/p/id/3982" target="_blank">http://zone.ni.com/devzone/cda/tut/p/id/3982</a>
That should get you started.&nbsp; Look at the examples, and then build your application.&nbsp; You can then continue to ask questions in this thread if you need more help.
R
Reply With Quote
  #8  
Old 07-29-2008, 01:40 PM
smercurio_fc
Guest
 
Default Re: tcp ip external code

Guilly wrote:


So instead of accusing me taking the easy ride, is there someone who can help me out? For the record, nobody is accusing you of "taking the easy ride". Your post just seemed like many others that have been seen before where people are asking others to do their work (or homework) for them. So, before getting defensive, take the advice that has already been given, like going through the LabVIEW tutorials, as it seems you are asking about how to code in LabVIEW, and looking at the examples that already ship with LabVIEW. This will allow you to ask more specific questions that can be better answered. :smileywink:
Reply With Quote
  #9  
Old 07-29-2008, 02:40 PM
Kevin Price
Guest
 
Default Re: tcp ip external code

Some more very general info, not so much the TCP itself, but how to deal with those data structures.
&nbsp;
The TCP interface in LabVIEW takes strings.&nbsp; So you'll have to convert the packets into&nbsp;the right kind of data structure.
&nbsp;
1. You'll probably want to define LabVIEW datatypes corresponding to the various structs defined in the header.&nbsp; A LabVIEW cluster is the element that is most like a struct.
2. As you populate the cluster with native datatypes, be careful to use the correct ones.&nbsp; When you drop a numeric control, LabVIEW treats it as a double by default.&nbsp; You can then right click and change the representation to the right kind.&nbsp; Be careful about the size of your integers too!&nbsp; You'll need to know whether a ushort means 16 or 32 bits for example.
3. The memory layout order for a LabVIEW cluster is not necessarily the same as the visual order.&nbsp; You'll need to right-click the cluster border in order to define the correct order of all the items within the cluster.
4.&nbsp;Back on the cluster border, right-click and choose Advanced-&gt;Customize...&nbsp; This brings up the custom control editor.&nbsp; Make your custom data type into a typedef.
5. The LabVIEW function Unflatten from String is probably the best way to convert the received TCP string into the typedef'ed cluster's datatype.
&nbsp;
6. For debug and troubleshooting of this conversion, be sure you have a way for your server to send a known non-default struct so you can validate what you receive and interpret.
&nbsp;
-Kevin P.
Reply With Quote
  #10  
Old 07-29-2008, 07:10 PM
JoeLabView
Guest
 
Default Re: tcp ip external code

To learn more about LabVIEW, I suggest you try looking at some of <a href="http://wiki.lavag.org/LabVIEW_tutorial#External_Links" target="_blank"> these tutorials</a>. Message Edited by JoeLabView on 07-29-2008 06:50 PM
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 09:02 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.