LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

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. 1. Introduction
  2. 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.

    1. 2. General frame structure
    2. The frame structure is like shown below:

      FRAME = HEADER + DATA

      Header consists of following fields:

      1. ï‚· Type of command (
      public ushort Command) – describes type of request (or response)
    3. ï‚· Size of whole data package (header + data) (
    4. public int Lenght)
    5. ï‚· Number of the next sent frame (
    6. public ushort CommandNo)

      [

      StructLayout(LayoutKind.Sequential, Pack = 1)]

      public struct

      Header

      {

      public ushort

      Command;

      public int

      Lenght;

      public ushort

      CommandNo;

      }

      1. 3. Command types and numbers
      2. Command types and numbers are shown below:

        1. a) Commands sent by Client application
          1. ï‚·
        LAN_CODE_GET_GPS_INFORMATION = 0x0005 – requests to calculate and send new position
      3. ï‚·
      4. INTERNAL_CODE1 = 0x0007 – reserved
      5. ï‚·
      6. INTERNAL_CODE2 = 0x0008 – reserved
        1. b) Commands sent by Server application
          1. ï‚·
        LAN_CODE_GPS_INFORMATION = 0x0006 – sends calculated position
      7. ï‚·
      8. 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,

        }

        1. 4. Detail description of the commands
          1. 4.1 Requests
          2. 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.

        1. a) Header

        ushort Command = LAN_CODE_GET_GPS_INFORMATION = 0x0005

        int Length = sizeof(Header)

        ushort CommandNo – unknown value (next message number)

        1. b) Data

        No additional data.

          1. 4.2 Responses
          1. 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.

        1. a) Header

        ushort Command = LAN_CODE_GPS_INFORMATION = 0x0006

        int Length = sizeof(Header) + sizeof(GPSInfo)

        ushort CommandNo – unknown value (next message number)

        1. 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>

        /// Structure describing batteries status of the GPS.

        /// </summary>

        public BatteriesSt Batteries;

        /// <summary>

        /// Actual time.

        /// </summary>

        public double DateTimeInfo;

        /// <summary>

        /// Actual speed.

        /// </summary>

        public double Speed;

        /// <summary>

        /// Defines if navigation needs choosing leg by the user.

        /// </summary>

        public int NeedChoosing;

        /// <summary>

        /// Defines if sent position is unknown (when we don’t know on which leg we are)

        /// </summary>

        public int PositionUnknown;

        /// <summary>

        /// Number of the first leg.

        /// </summary>

        public double Leg1;

        /// <summary>

        /// Number of the second leg.

        /// </summary>

        public double Leg2;

        /// <summary>

        /// Defines if section, on which we are is properly defined in database.

        /// </summary>

        public int WrongObject;

        /// <summary>

        /// Defines ‘virtual’ mileage of the non-properly defined section.

        /// </summary>

        public int WrongMileage;

        /// <summary>

        /// Non calculated raw gps position.

        /// </summary>

        public PositionSt RawGPSPosition;

        }

        [StructLayout(LayoutKind.Sequential, Pack = 1)]

        public struct BatteriesSt

        {

        /// <summary>

        /// Percentage of batteries load.

        /// </summary>

        public double Percentage;

        /// <summary>

        /// Voltage of the batteries.

        /// </summary>

        public double Voltage;

        }

        [StructLayout(LayoutKind.Sequential, Pack = 1)]

        public struct PositionSt

        {

        public double X;

        public double Y;

        public double Z;

        }

        0 Kudos
        Message 1 of 10
        (3,520 Views)

        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

        0 Kudos
        Message 2 of 10
        (3,500 Views)
        Well if you could help me on my way...that would be nice 🙂
        0 Kudos
        Message 3 of 10
        (3,437 Views)
        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. Smiley Wink

        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?
        0 Kudos
        Message 4 of 10
        (3,429 Views)
        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
        0 Kudos
        Message 5 of 10
        (3,424 Views)
        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 hereSmiley Tongue. So instead of accusing me taking the easy ride, is there someone who can help me out?
         
        Thanks in advance
        0 Kudos
        Message 6 of 10
        (3,418 Views)

        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:  http://forums.ni.com/ni/board/message?board.id=170&message.id=79711&query.id=147925

        Here is an article: http://zone.ni.com/devzone/cda/tut/p/id/4579

        TCP Architecture (multiple clients) : http://zone.ni.com/devzone/cda/tut/p/id/3982

        That should get you started.  Look at the examples, and then build your application.  You can then continue to ask questions in this thread if you need more help.

        R

        0 Kudos
        Message 7 of 10
        (3,396 Views)

        @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. Smiley Wink
        0 Kudos
        Message 8 of 10
        (3,389 Views)
        Some more very general info, not so much the TCP itself, but how to deal with those data structures.
         
        The TCP interface in LabVIEW takes strings.  So you'll have to convert the packets into the right kind of data structure.
         
        1. You'll probably want to define LabVIEW datatypes corresponding to the various structs defined in the header.  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.  When you drop a numeric control, LabVIEW treats it as a double by default.  You can then right click and change the representation to the right kind.  Be careful about the size of your integers too!  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.  You'll need to right-click the cluster border in order to define the correct order of all the items within the cluster.
        4. Back on the cluster border, right-click and choose Advanced->Customize...  This brings up the custom control editor.  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.
         
        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.
         
        -Kevin P.
        ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
        0 Kudos
        Message 9 of 10
        (3,376 Views)
        To learn more about LabVIEW, I suggest you try looking at some of these tutorials.


        Message Edited by JoeLabView on 07-29-2008 06:50 PM
        0 Kudos
        Message 10 of 10
        (3,363 Views)