Answers.Body: <p>You need to reserve 1 byte for the speed in return and 4 bytes for the tacho in return. However, the tacho has to be 32-bit-aligned and so you will need 3 padding bytes after the speed:</p>
  
  <pre><code>unsigned char opOutput_Read[]
  {
      0x0A, 0x00,              // bytes in message
      0x00, 0x00,              // message counter
      DIRECT_COMMAND_REPLY,    // tt   = Direct command with reply
      0x08, 0x00,              // 8 values will be reserved
      0xA8,                    // opOutput_Read,
      GV0(0),                  // speed in return
      GV0(4)                   // tacho in return
  };
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-01T17:46:33.960Z
Answers.LastActivityDate: 2016-01-01T17:46:33.960Z
Answers.UserDisplayName: Marc Nieper-Wißkirchen
Answers.Body: <p>The TACHO parameter is 4 bytes (32 bits).</p>
  
  <pre><code>(Data32) *TACHO – Current output tacho count
  </code></pre>
  
  <p>However, you have only allocated it 2 bytes (16 bits)</p>
  
  <pre><code>GV2(1)                   // tacho in return
  </code></pre>
  
  <p>Try using <code>GV4</code> instead of <code>GV2</code>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-28T16:55:42.333Z
Answers.LastActivityDate: 2014-11-28T16:55:42.333Z
Answers.UserDisplayName: David Lechner
Answers.Body: <p>I've found answer here: <a href="http://topikachu.github.io/python-ev3/bytecodeexamples.html" rel="nofollow">http://topikachu.github.io/python-ev3/bytecodeexamples.html</a>. It can be done using direct command:</p>
  
  <pre><code>Instruction        opInput_Device (CMD, ...)
  Opcode             0x99
  Arguments          (Data8) CMD =&gt; Specific command parameter documented below
                     CMD:READY_SI = 0x1D
                     Arguments
                         (Data8) LAYER – Specify chain layer number [0-3]
                         (Data8) NO – Port number
                         (Data8) TYPE – Specify device type (0 = Don’t change type)
                         (Data8) MODE – Device mode [0-7] (-1 = Don’t change mode)                           
                         (Data8) VALUES – Number of return values
                     Returns (Depending on number of data samples requested in (VALUES))
                         (DataF) VALUE1 – First value received from sensor in the specified mode
  </code></pre>
  
  <p>so to read speed from port A the one should send:</p>
  
  <pre><code>unsigned char opInput_Device[] =
  {
      0x0D, 0x00,              //bbbb = bytes in message
      0x00, 0x00,              //mmmm = message counter
      DIRECT_COMMAND_REPLY,    //tt   = Direct command with reply
      0x04, 0x00,              //
      0x99, 0x1D,              //opInput_Device, READY_SI
      LC0(0),                  //Layer 0
      LC0(16),                 //16=PortA, 17=PortB, 18=PortC, 19=PortD
      LC0(0),                  //default type
      LC0(2),                  //mode 2
      LC0(1),                  //1 value will be returned
      0x60                     //local variable 0
  };
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-02T07:32:37.053Z
Answers.Text: For power values (first columns) I get responses:
    0 => 07000000 02000000 00,
    1 => 07000000 02000000 00,
    2 => 07000000 02000000 40,
    3 => 07000000 02000040 40,
    4 => 07000000 02000080 40,
    5 => 07000000 020000a0 40,
    6 => 07000000 020000c0 40,
    7 => 07000000 020000e0 40,
    8 => 07000000 02000000 41,
    9 => 07000000 02000010 41,
   10 => 07000000 02000020 41,
   11 => 07000000 02000030 41
  but I'm not able to interpret them.
Answers.UserDisplayName: user4053
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-01T20:10:14.297Z
Answers.LastActivityDate: 2014-12-01T21:28:39.273Z
Answers.LastEditDate: 2014-12-01T21:28:39.273Z
Answers.UserDisplayName: user4053
Body: <p>I'm trying to read current motor speed using direct command:</p>
  
  <pre><code>Instruction        opOutput_Read (LAYER, NO, *SPEED, *TACHO)
  Opcode             0xA8
  Arguments          (Data8) LAYER – Specify chain layer number [0 - 3]
                     (Data8) NO – Port number [0 - 3]
                     (Data8) *SPEED – Output speed level detected, [-100 - 100]
                     (Data32) *TACHO – Current output tacho count
  </code></pre>
  
  <p>When I'm sending something like this:</p>
  
  <pre><code>unsigned char opOutput_Read[]
  {
      0x0A, 0x00,              // bytes in message
      0x00, 0x00,              // message counter
      DIRECT_COMMAND_REPLY,    // tt   = Direct command with reply
      0x02, 0x00,              // 2 values will be returned
      0xA8,                    // opOutput_Read,
      GV0(0),                  // speed in return
      GV2(1)                   // tacho in return
  };
  </code></pre>
  
  <p>I'm getting DIRECT_REPLY_ERROR. What am I doing wrong?</p>
  
Tags: <ev3><programming>
Title: Reading current motor speed, opOutput_Read
UserDisplayName: user4053
ThreadText: # Reading current motor speed, opOutput_Read
  
  (Asked by: username_0 on 2014-11-28)
  
  I'm trying to read current motor speed using direct command:
  Instruction        opOutput_Read (LAYER, NO, *SPEED, *TACHO)
  Opcode             0xA8
  Arguments          (Data8) LAYER – Specify chain layer number [0 - 3]
                     (Data8) NO – Port number [0 - 3]
                     (Data8) *SPEED – Output speed level detected, [-100 - 100]
                     (Data32) *TACHO – Current output tacho count
  
  When I'm sending something like this:
  unsigned char opOutput_Read[]
  {
      0x0A, 0x00,              // bytes in message
      0x00, 0x00,              // message counter
      DIRECT_COMMAND_REPLY,    // tt   = Direct command with reply
      0x02, 0x00,              // 2 values will be returned
      0xA8,                    // opOutput_Read,
      GV0(0),                  // speed in return
      GV2(1)                   // tacho in return
  };
  
  I'm getting DIRECT_REPLY_ERROR. What am I doing wrong?
  
  **Tags:** ev3, programming
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2016-01-01. Score: 1
  
  You need to reserve 1 byte for the speed in return and 4 bytes for the tacho in return. However, the tacho has to be 32-bit-aligned and so you will need 3 padding bytes after the speed:
  unsigned char opOutput_Read[]
  {
      0x0A, 0x00,              // bytes in message
      0x00, 0x00,              // message counter
      DIRECT_COMMAND_REPLY,    // tt   = Direct command with reply
      0x08, 0x00,              // 8 values will be reserved
      0xA8,                    // opOutput_Read,
      GV0(0),                  // speed in return
      GV0(4)                   // tacho in return
  };
  
  
  ---
  
  ### Answer by username_2 on 2014-11-28. Score: 1
  
  The TACHO parameter is 4 bytes (32 bits).
  (Data32) *TACHO – Current output tacho count
  
  However, you have only allocated it 2 bytes (16 bits)
  GV2(1)                   // tacho in return
  
  Try using GV4 instead of GV2.
  
  
  ---
  
  ### Answer by username_0 on 2014-12-01. Score: 0
  
  I've found answer here: http://topikachu.github.io/python-ev3/bytecodeexamples.html. It can be done using direct command:
  Instruction        opInput_Device (CMD, ...)
  Opcode             0x99
  Arguments          (Data8) CMD => Specific command parameter documented below
                     CMD:READY_SI = 0x1D
                     Arguments
                         (Data8) LAYER – Specify chain layer number [0-3]
                         (Data8) NO – Port number
                         (Data8) TYPE – Specify device type (0 = Don’t change type)
                         (Data8) MODE – Device mode [0-7] (-1 = Don’t change mode)                           
                         (Data8) VALUES – Number of return values
                     Returns (Depending on number of data samples requested in (VALUES))
                         (DataF) VALUE1 – First value received from sensor in the specified mode
  
  so to read speed from port A the one should send:
  unsigned char opInput_Device[] =
  {
      0x0D, 0x00,              //bbbb = bytes in message
      0x00, 0x00,              //mmmm = message counter
      DIRECT_COMMAND_REPLY,    //tt   = Direct command with reply
      0x04, 0x00,              //
      0x99, 0x1D,              //opInput_Device, READY_SI
      LC0(0),                  //Layer 0
      LC0(16),                 //16=PortA, 17=PortB, 18=PortC, 19=PortD
      LC0(0),                  //default type
      LC0(2),                  //mode 2
      LC0(1),                  //1 value will be returned
      0x60                     //local variable 0
  };
  
  > **Comments:**
  > **username_0**: For power values (first columns) I get responses:   0 => 07000000 02000000 00,   1 => 07000000 02000000 00,   2 => 07000000 02000000 40,   3 => 07000000 02000040 40,   4 => 07000000 02000080 40,   5 => 07000000 020000a0 40,   6 => 07000000 020000c0 40,   7 => 07000000 020000e0 40,   8 => 07000000 02000000 41,   9 => 07000000 02000010 41,  10 => 07000000 02000020 41,  11 => 07000000 02000030 41 but I'm not able to interpret them.  
  
  ---
  
  