Extract continuous information from telnet client

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I have an industrial sensor that via an Interface module provides raw values via telnet.



In order to connect to it:



 telnet 169.254.168.150 10001


I can only see garbage values from it.



Information



The information that I have is from the datasheet of the Interface module.



The sensor is an analog one, hence Status flag is not relevant.



Data format



I have some propreitary software from the company which visualizes the information of the sensor. This software also uses the above mentioned telnet protocol to obtain information. I cross checked it via WireShark. Packet size is 22 Bytes and in little-endian.



Wireshark Dump



I cannot programatically obtain the information as my SE Query and I am looking to obtain the value maybe store the incoming values directly somewhere (in DB or file).



Is there any way to extract this infomation via the Command Line?










share|improve this question

















  • 1




    The datasheet describes a format which has a lot longer than 22 bytes, so either you need to look at several packets, or the datasheet doesn't match the telnet format. Also note the MEAS field, which is nowhere to be seen. First thing I'd do is telnet 169.254.168.150 10001 | hexdump C (assuming Unixoid OS) and look at a lot more data instead of a single packet.
    – dirkt
    Nov 23 at 16:21










  • A simple Perl script could easily read and decode/unpack the data
    – waltinator
    Nov 24 at 3:05











  • @waltinator never used perl before. Mind guiding me to some blogs which can achieve the goal?
    – Shan-Desai
    Nov 26 at 12:03










  • @dirkt I have the output pasted for the command you mentioned. here is the pastebin, I can read the preamble however the I do not get any other information from the dump
    – Shan-Desai
    Nov 26 at 12:54










  • Blogs won't do it. Buy the "Programming Perl" book (by Larry Wall, published by O'Reilly & Co.). Or, write it in C. Bash is not suited to binary data manipulation.
    – waltinator
    Nov 26 at 14:26














up vote
0
down vote

favorite












I have an industrial sensor that via an Interface module provides raw values via telnet.



In order to connect to it:



 telnet 169.254.168.150 10001


I can only see garbage values from it.



Information



The information that I have is from the datasheet of the Interface module.



The sensor is an analog one, hence Status flag is not relevant.



Data format



I have some propreitary software from the company which visualizes the information of the sensor. This software also uses the above mentioned telnet protocol to obtain information. I cross checked it via WireShark. Packet size is 22 Bytes and in little-endian.



Wireshark Dump



I cannot programatically obtain the information as my SE Query and I am looking to obtain the value maybe store the incoming values directly somewhere (in DB or file).



Is there any way to extract this infomation via the Command Line?










share|improve this question

















  • 1




    The datasheet describes a format which has a lot longer than 22 bytes, so either you need to look at several packets, or the datasheet doesn't match the telnet format. Also note the MEAS field, which is nowhere to be seen. First thing I'd do is telnet 169.254.168.150 10001 | hexdump C (assuming Unixoid OS) and look at a lot more data instead of a single packet.
    – dirkt
    Nov 23 at 16:21










  • A simple Perl script could easily read and decode/unpack the data
    – waltinator
    Nov 24 at 3:05











  • @waltinator never used perl before. Mind guiding me to some blogs which can achieve the goal?
    – Shan-Desai
    Nov 26 at 12:03










  • @dirkt I have the output pasted for the command you mentioned. here is the pastebin, I can read the preamble however the I do not get any other information from the dump
    – Shan-Desai
    Nov 26 at 12:54










  • Blogs won't do it. Buy the "Programming Perl" book (by Larry Wall, published by O'Reilly & Co.). Or, write it in C. Bash is not suited to binary data manipulation.
    – waltinator
    Nov 26 at 14:26












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have an industrial sensor that via an Interface module provides raw values via telnet.



In order to connect to it:



 telnet 169.254.168.150 10001


I can only see garbage values from it.



Information



The information that I have is from the datasheet of the Interface module.



The sensor is an analog one, hence Status flag is not relevant.



Data format



I have some propreitary software from the company which visualizes the information of the sensor. This software also uses the above mentioned telnet protocol to obtain information. I cross checked it via WireShark. Packet size is 22 Bytes and in little-endian.



Wireshark Dump



I cannot programatically obtain the information as my SE Query and I am looking to obtain the value maybe store the incoming values directly somewhere (in DB or file).



Is there any way to extract this infomation via the Command Line?










share|improve this question













I have an industrial sensor that via an Interface module provides raw values via telnet.



In order to connect to it:



 telnet 169.254.168.150 10001


I can only see garbage values from it.



Information



The information that I have is from the datasheet of the Interface module.



The sensor is an analog one, hence Status flag is not relevant.



Data format



I have some propreitary software from the company which visualizes the information of the sensor. This software also uses the above mentioned telnet protocol to obtain information. I cross checked it via WireShark. Packet size is 22 Bytes and in little-endian.



Wireshark Dump



I cannot programatically obtain the information as my SE Query and I am looking to obtain the value maybe store the incoming values directly somewhere (in DB or file).



Is there any way to extract this infomation via the Command Line?







telnet






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 at 15:04









Shan-Desai

3621313




3621313







  • 1




    The datasheet describes a format which has a lot longer than 22 bytes, so either you need to look at several packets, or the datasheet doesn't match the telnet format. Also note the MEAS field, which is nowhere to be seen. First thing I'd do is telnet 169.254.168.150 10001 | hexdump C (assuming Unixoid OS) and look at a lot more data instead of a single packet.
    – dirkt
    Nov 23 at 16:21










  • A simple Perl script could easily read and decode/unpack the data
    – waltinator
    Nov 24 at 3:05











  • @waltinator never used perl before. Mind guiding me to some blogs which can achieve the goal?
    – Shan-Desai
    Nov 26 at 12:03










  • @dirkt I have the output pasted for the command you mentioned. here is the pastebin, I can read the preamble however the I do not get any other information from the dump
    – Shan-Desai
    Nov 26 at 12:54










  • Blogs won't do it. Buy the "Programming Perl" book (by Larry Wall, published by O'Reilly & Co.). Or, write it in C. Bash is not suited to binary data manipulation.
    – waltinator
    Nov 26 at 14:26












  • 1




    The datasheet describes a format which has a lot longer than 22 bytes, so either you need to look at several packets, or the datasheet doesn't match the telnet format. Also note the MEAS field, which is nowhere to be seen. First thing I'd do is telnet 169.254.168.150 10001 | hexdump C (assuming Unixoid OS) and look at a lot more data instead of a single packet.
    – dirkt
    Nov 23 at 16:21










  • A simple Perl script could easily read and decode/unpack the data
    – waltinator
    Nov 24 at 3:05











  • @waltinator never used perl before. Mind guiding me to some blogs which can achieve the goal?
    – Shan-Desai
    Nov 26 at 12:03










  • @dirkt I have the output pasted for the command you mentioned. here is the pastebin, I can read the preamble however the I do not get any other information from the dump
    – Shan-Desai
    Nov 26 at 12:54










  • Blogs won't do it. Buy the "Programming Perl" book (by Larry Wall, published by O'Reilly & Co.). Or, write it in C. Bash is not suited to binary data manipulation.
    – waltinator
    Nov 26 at 14:26







1




1




The datasheet describes a format which has a lot longer than 22 bytes, so either you need to look at several packets, or the datasheet doesn't match the telnet format. Also note the MEAS field, which is nowhere to be seen. First thing I'd do is telnet 169.254.168.150 10001 | hexdump C (assuming Unixoid OS) and look at a lot more data instead of a single packet.
– dirkt
Nov 23 at 16:21




The datasheet describes a format which has a lot longer than 22 bytes, so either you need to look at several packets, or the datasheet doesn't match the telnet format. Also note the MEAS field, which is nowhere to be seen. First thing I'd do is telnet 169.254.168.150 10001 | hexdump C (assuming Unixoid OS) and look at a lot more data instead of a single packet.
– dirkt
Nov 23 at 16:21












A simple Perl script could easily read and decode/unpack the data
– waltinator
Nov 24 at 3:05





A simple Perl script could easily read and decode/unpack the data
– waltinator
Nov 24 at 3:05













@waltinator never used perl before. Mind guiding me to some blogs which can achieve the goal?
– Shan-Desai
Nov 26 at 12:03




@waltinator never used perl before. Mind guiding me to some blogs which can achieve the goal?
– Shan-Desai
Nov 26 at 12:03












@dirkt I have the output pasted for the command you mentioned. here is the pastebin, I can read the preamble however the I do not get any other information from the dump
– Shan-Desai
Nov 26 at 12:54




@dirkt I have the output pasted for the command you mentioned. here is the pastebin, I can read the preamble however the I do not get any other information from the dump
– Shan-Desai
Nov 26 at 12:54












Blogs won't do it. Buy the "Programming Perl" book (by Larry Wall, published by O'Reilly & Co.). Or, write it in C. Bash is not suited to binary data manipulation.
– waltinator
Nov 26 at 14:26




Blogs won't do it. Buy the "Programming Perl" book (by Larry Wall, published by O'Reilly & Co.). Or, write it in C. Bash is not suited to binary data manipulation.
– waltinator
Nov 26 at 14:26










2 Answers
2






active

oldest

votes

















up vote
0
down vote













Extract from the pastebin:



00000050 2e 0a 53 41 45 4d 00 00 00 00 f6 04 00 00 15 00 |..SAEM..........|
00000060 00 00 00 00 00 00 00 00 00 00 0c 00 01 00 fa 94 |................|
00000070 00 00 8c 00 00 00 8c 00 00 00 0a 23 00 00 53 41 |...........#..SA|
00000080 45 4d 00 00 00 00 f6 04 00 00 15 00 00 00 00 00 |EM..............|


So this shows the information is all there, it's little endian, and you just have to read and parse them. Any tool you are confortable with will do; a C program, a perl program, anything you like. You may have to skip over the telnet output at the beginning, or use something else instead of telnet (e.g. nc, netcat, socat).



To demonstrate perl, to decode one packet, you'd do something like



cat ... | perl -nle "print join(':',unpack 'a4 (L2 Q L S2 l4)<')"


on the command line for the packet in the dump, and get as output



SAEM:0:1270:21:0:12:1:38138:140:140


This only works for the given number of channels (and the mask says that one of the four measurement values shouldn't be present, but it has a value; I don't understand that part).



If you get a variable number of channels depending on other information, you need smarter parsing.






share|improve this answer



























    up vote
    0
    down vote













    So apparently I thought the other way round. Since I was capturing data on Wireshark all the packets were tcp and only the initial few packets were of telnet (session initiation information).



    I decided to create a tcp socket using python and read the data of 22 bytes (size available from Wireshark Dump)



    and I used struct module to unpack the information. Interesting was to find out that the useful sensor information came always as the alternate TCP payload i.e. First packet had only information like preamble, article number, serial number etc. and the next payload had all the information Counter, Channel 1 value, Channel 2 value, Channel 3 value



    The information obtained here was in int32 which needs to converted to appropriate value using a formula mentioned in the module's instruction manual



    Code



    import socket
    import struct

    # CONSTANTS for Formula
    # ....

    # Create a TCP/IP socket
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    server_address = ('169.254.168.150', 10001)
    print('connecting to %s port %s' % server_address)
    sock.connect(server_address)


    def value_mm(raw_val):
    """ Formula for conversion """
    return (((raw_val - DRANGEMIN) * MEASRANGE) / (DRANGEMAX - DRANGEMIN) + OFFSET)


    if __name__ == '__main__':
    while True:
    Laser_Value = 0
    data = sock.recv(22)
    # First frame
    preamble, article, serial, x1, x2 = struct.unpack('<4sIIQH', data)

    # if this payload is not the preamble, it must be information payload
    if not preamble == b'SAEM':
    status, bpf, mValCounter, CH1, CH2, CH3 = struct.unpack('<hIIIII',data)
    #print(CH1, CH2, CH3)
    Laser_Value = CH3
    print(str(value_mm(Laser_Value)) + " mm")

    print('n')





    share|improve this answer




















      Your Answer








      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "106"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f483699%2fextract-continuous-information-from-telnet-client%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote













      Extract from the pastebin:



      00000050 2e 0a 53 41 45 4d 00 00 00 00 f6 04 00 00 15 00 |..SAEM..........|
      00000060 00 00 00 00 00 00 00 00 00 00 0c 00 01 00 fa 94 |................|
      00000070 00 00 8c 00 00 00 8c 00 00 00 0a 23 00 00 53 41 |...........#..SA|
      00000080 45 4d 00 00 00 00 f6 04 00 00 15 00 00 00 00 00 |EM..............|


      So this shows the information is all there, it's little endian, and you just have to read and parse them. Any tool you are confortable with will do; a C program, a perl program, anything you like. You may have to skip over the telnet output at the beginning, or use something else instead of telnet (e.g. nc, netcat, socat).



      To demonstrate perl, to decode one packet, you'd do something like



      cat ... | perl -nle "print join(':',unpack 'a4 (L2 Q L S2 l4)<')"


      on the command line for the packet in the dump, and get as output



      SAEM:0:1270:21:0:12:1:38138:140:140


      This only works for the given number of channels (and the mask says that one of the four measurement values shouldn't be present, but it has a value; I don't understand that part).



      If you get a variable number of channels depending on other information, you need smarter parsing.






      share|improve this answer
























        up vote
        0
        down vote













        Extract from the pastebin:



        00000050 2e 0a 53 41 45 4d 00 00 00 00 f6 04 00 00 15 00 |..SAEM..........|
        00000060 00 00 00 00 00 00 00 00 00 00 0c 00 01 00 fa 94 |................|
        00000070 00 00 8c 00 00 00 8c 00 00 00 0a 23 00 00 53 41 |...........#..SA|
        00000080 45 4d 00 00 00 00 f6 04 00 00 15 00 00 00 00 00 |EM..............|


        So this shows the information is all there, it's little endian, and you just have to read and parse them. Any tool you are confortable with will do; a C program, a perl program, anything you like. You may have to skip over the telnet output at the beginning, or use something else instead of telnet (e.g. nc, netcat, socat).



        To demonstrate perl, to decode one packet, you'd do something like



        cat ... | perl -nle "print join(':',unpack 'a4 (L2 Q L S2 l4)<')"


        on the command line for the packet in the dump, and get as output



        SAEM:0:1270:21:0:12:1:38138:140:140


        This only works for the given number of channels (and the mask says that one of the four measurement values shouldn't be present, but it has a value; I don't understand that part).



        If you get a variable number of channels depending on other information, you need smarter parsing.






        share|improve this answer






















          up vote
          0
          down vote










          up vote
          0
          down vote









          Extract from the pastebin:



          00000050 2e 0a 53 41 45 4d 00 00 00 00 f6 04 00 00 15 00 |..SAEM..........|
          00000060 00 00 00 00 00 00 00 00 00 00 0c 00 01 00 fa 94 |................|
          00000070 00 00 8c 00 00 00 8c 00 00 00 0a 23 00 00 53 41 |...........#..SA|
          00000080 45 4d 00 00 00 00 f6 04 00 00 15 00 00 00 00 00 |EM..............|


          So this shows the information is all there, it's little endian, and you just have to read and parse them. Any tool you are confortable with will do; a C program, a perl program, anything you like. You may have to skip over the telnet output at the beginning, or use something else instead of telnet (e.g. nc, netcat, socat).



          To demonstrate perl, to decode one packet, you'd do something like



          cat ... | perl -nle "print join(':',unpack 'a4 (L2 Q L S2 l4)<')"


          on the command line for the packet in the dump, and get as output



          SAEM:0:1270:21:0:12:1:38138:140:140


          This only works for the given number of channels (and the mask says that one of the four measurement values shouldn't be present, but it has a value; I don't understand that part).



          If you get a variable number of channels depending on other information, you need smarter parsing.






          share|improve this answer












          Extract from the pastebin:



          00000050 2e 0a 53 41 45 4d 00 00 00 00 f6 04 00 00 15 00 |..SAEM..........|
          00000060 00 00 00 00 00 00 00 00 00 00 0c 00 01 00 fa 94 |................|
          00000070 00 00 8c 00 00 00 8c 00 00 00 0a 23 00 00 53 41 |...........#..SA|
          00000080 45 4d 00 00 00 00 f6 04 00 00 15 00 00 00 00 00 |EM..............|


          So this shows the information is all there, it's little endian, and you just have to read and parse them. Any tool you are confortable with will do; a C program, a perl program, anything you like. You may have to skip over the telnet output at the beginning, or use something else instead of telnet (e.g. nc, netcat, socat).



          To demonstrate perl, to decode one packet, you'd do something like



          cat ... | perl -nle "print join(':',unpack 'a4 (L2 Q L S2 l4)<')"


          on the command line for the packet in the dump, and get as output



          SAEM:0:1270:21:0:12:1:38138:140:140


          This only works for the given number of channels (and the mask says that one of the four measurement values shouldn't be present, but it has a value; I don't understand that part).



          If you get a variable number of channels depending on other information, you need smarter parsing.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 26 at 14:49









          dirkt

          16.2k21335




          16.2k21335






















              up vote
              0
              down vote













              So apparently I thought the other way round. Since I was capturing data on Wireshark all the packets were tcp and only the initial few packets were of telnet (session initiation information).



              I decided to create a tcp socket using python and read the data of 22 bytes (size available from Wireshark Dump)



              and I used struct module to unpack the information. Interesting was to find out that the useful sensor information came always as the alternate TCP payload i.e. First packet had only information like preamble, article number, serial number etc. and the next payload had all the information Counter, Channel 1 value, Channel 2 value, Channel 3 value



              The information obtained here was in int32 which needs to converted to appropriate value using a formula mentioned in the module's instruction manual



              Code



              import socket
              import struct

              # CONSTANTS for Formula
              # ....

              # Create a TCP/IP socket
              sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

              server_address = ('169.254.168.150', 10001)
              print('connecting to %s port %s' % server_address)
              sock.connect(server_address)


              def value_mm(raw_val):
              """ Formula for conversion """
              return (((raw_val - DRANGEMIN) * MEASRANGE) / (DRANGEMAX - DRANGEMIN) + OFFSET)


              if __name__ == '__main__':
              while True:
              Laser_Value = 0
              data = sock.recv(22)
              # First frame
              preamble, article, serial, x1, x2 = struct.unpack('<4sIIQH', data)

              # if this payload is not the preamble, it must be information payload
              if not preamble == b'SAEM':
              status, bpf, mValCounter, CH1, CH2, CH3 = struct.unpack('<hIIIII',data)
              #print(CH1, CH2, CH3)
              Laser_Value = CH3
              print(str(value_mm(Laser_Value)) + " mm")

              print('n')





              share|improve this answer
























                up vote
                0
                down vote













                So apparently I thought the other way round. Since I was capturing data on Wireshark all the packets were tcp and only the initial few packets were of telnet (session initiation information).



                I decided to create a tcp socket using python and read the data of 22 bytes (size available from Wireshark Dump)



                and I used struct module to unpack the information. Interesting was to find out that the useful sensor information came always as the alternate TCP payload i.e. First packet had only information like preamble, article number, serial number etc. and the next payload had all the information Counter, Channel 1 value, Channel 2 value, Channel 3 value



                The information obtained here was in int32 which needs to converted to appropriate value using a formula mentioned in the module's instruction manual



                Code



                import socket
                import struct

                # CONSTANTS for Formula
                # ....

                # Create a TCP/IP socket
                sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

                server_address = ('169.254.168.150', 10001)
                print('connecting to %s port %s' % server_address)
                sock.connect(server_address)


                def value_mm(raw_val):
                """ Formula for conversion """
                return (((raw_val - DRANGEMIN) * MEASRANGE) / (DRANGEMAX - DRANGEMIN) + OFFSET)


                if __name__ == '__main__':
                while True:
                Laser_Value = 0
                data = sock.recv(22)
                # First frame
                preamble, article, serial, x1, x2 = struct.unpack('<4sIIQH', data)

                # if this payload is not the preamble, it must be information payload
                if not preamble == b'SAEM':
                status, bpf, mValCounter, CH1, CH2, CH3 = struct.unpack('<hIIIII',data)
                #print(CH1, CH2, CH3)
                Laser_Value = CH3
                print(str(value_mm(Laser_Value)) + " mm")

                print('n')





                share|improve this answer






















                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  So apparently I thought the other way round. Since I was capturing data on Wireshark all the packets were tcp and only the initial few packets were of telnet (session initiation information).



                  I decided to create a tcp socket using python and read the data of 22 bytes (size available from Wireshark Dump)



                  and I used struct module to unpack the information. Interesting was to find out that the useful sensor information came always as the alternate TCP payload i.e. First packet had only information like preamble, article number, serial number etc. and the next payload had all the information Counter, Channel 1 value, Channel 2 value, Channel 3 value



                  The information obtained here was in int32 which needs to converted to appropriate value using a formula mentioned in the module's instruction manual



                  Code



                  import socket
                  import struct

                  # CONSTANTS for Formula
                  # ....

                  # Create a TCP/IP socket
                  sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

                  server_address = ('169.254.168.150', 10001)
                  print('connecting to %s port %s' % server_address)
                  sock.connect(server_address)


                  def value_mm(raw_val):
                  """ Formula for conversion """
                  return (((raw_val - DRANGEMIN) * MEASRANGE) / (DRANGEMAX - DRANGEMIN) + OFFSET)


                  if __name__ == '__main__':
                  while True:
                  Laser_Value = 0
                  data = sock.recv(22)
                  # First frame
                  preamble, article, serial, x1, x2 = struct.unpack('<4sIIQH', data)

                  # if this payload is not the preamble, it must be information payload
                  if not preamble == b'SAEM':
                  status, bpf, mValCounter, CH1, CH2, CH3 = struct.unpack('<hIIIII',data)
                  #print(CH1, CH2, CH3)
                  Laser_Value = CH3
                  print(str(value_mm(Laser_Value)) + " mm")

                  print('n')





                  share|improve this answer












                  So apparently I thought the other way round. Since I was capturing data on Wireshark all the packets were tcp and only the initial few packets were of telnet (session initiation information).



                  I decided to create a tcp socket using python and read the data of 22 bytes (size available from Wireshark Dump)



                  and I used struct module to unpack the information. Interesting was to find out that the useful sensor information came always as the alternate TCP payload i.e. First packet had only information like preamble, article number, serial number etc. and the next payload had all the information Counter, Channel 1 value, Channel 2 value, Channel 3 value



                  The information obtained here was in int32 which needs to converted to appropriate value using a formula mentioned in the module's instruction manual



                  Code



                  import socket
                  import struct

                  # CONSTANTS for Formula
                  # ....

                  # Create a TCP/IP socket
                  sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

                  server_address = ('169.254.168.150', 10001)
                  print('connecting to %s port %s' % server_address)
                  sock.connect(server_address)


                  def value_mm(raw_val):
                  """ Formula for conversion """
                  return (((raw_val - DRANGEMIN) * MEASRANGE) / (DRANGEMAX - DRANGEMIN) + OFFSET)


                  if __name__ == '__main__':
                  while True:
                  Laser_Value = 0
                  data = sock.recv(22)
                  # First frame
                  preamble, article, serial, x1, x2 = struct.unpack('<4sIIQH', data)

                  # if this payload is not the preamble, it must be information payload
                  if not preamble == b'SAEM':
                  status, bpf, mValCounter, CH1, CH2, CH3 = struct.unpack('<hIIIII',data)
                  #print(CH1, CH2, CH3)
                  Laser_Value = CH3
                  print(str(value_mm(Laser_Value)) + " mm")

                  print('n')






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 26 at 15:41









                  Shan-Desai

                  3621313




                  3621313



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Unix & Linux Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f483699%2fextract-continuous-information-from-telnet-client%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown






                      Popular posts from this blog

                      How to check contact read email or not when send email to Individual?

                      Bahrain

                      Postfix configuration issue with fips on centos 7; mailgun relay