Measurement Application Questions

Discussion in 'C-Bus Serial Protocols' started by pspeirs, May 16, 2016.

  1. pspeirs

    pspeirs

    Joined:
    Nov 23, 2013
    Messages:
    185
    Likes Received:
    10
    Location:
    Sydney
    Hi All,

    I'm after an opinion on transmitting a value via the measurement application.

    I have an analogue input that is scaled from 0 - 12V. So, to send a voltage with say 1.699V with 3 decimal points I would need to multiply the value x 1000 and then scale it so the receiving app reads it as 1.699V.

    Can I assume that I should do this initial calculation internally then should the user select a different multiplication value that this should then be calculated separately.

    so, should I have a 1-1024 ADC value of say 145

    V = 145 * (12/1024) = 1.699 V
    Since I can't transmit 1.699 V I would multiply and use the scaling as follows:

    1.699 * 1000 = 1699
    Transmit 1699 in high and low bytes
    Transmit a multiplier of 0xFD
    Received as 1.699V


    Then there is the question of handling different unit types, or should that not really matter.


    Hope that makes sense.



    Regs,
    Paul
     
    pspeirs, May 16, 2016
    #1
  2. pspeirs

    NickD Moderator

    Joined:
    Nov 1, 2004
    Messages:
    1,420
    Likes Received:
    62
    Location:
    Adelaide
    Assuming you are using the C-Bus module to send the message, this is the function you use :

    Code:
    /****************************************************************************
     * This function sends a Measurement Application message.
     *   channel is the measurement channel number
     *   mantissa is the numeric value of the measured parameter.
     *   exponent is the multiplier (power of ten)
     *   units is the units of the measured parameter
     ****************************************************************************/
    extern dec_DLL void cbus_measurement_vf_send_data(int8u network,
                                                      int8u device_id,
                                                      int8u channel,
                                                      int32s mantissa,
                                                      int8s exponent,
                                                      cbus_measurement_et_unit_type units);
    To convert a real number to the mantissa/exponent format needed by this function, this is the (C) code we use in the CTouch :

    Code:
      int32s i_mantissa;
      int8s i_exponent;
      
      float f_temp;
    
      /* Convert float value to mantissa + exponent */
      
      i_exponent = 0;
      
      /* First, check if it fits in a 16 bit signed integer as-is */
      if ((modff(f_value, &f_temp) == 0) && 
          ((f_value <= 32767) && f_value >= -32768))
        {
          i_mantissa = (int32s)f_temp;
        }
      else
        {
          if (f_value < 0)
            {
              f_value = -f_value;
              i_mantissa = -1;
            }
          else
            {
              i_mantissa = 1;
            }
        
          while (f_value < 32767)
            {
              f_value = f_value * 10;
              i_exponent--;
            }
    
          while (f_value > 32767)
            {
              f_value = f_value / 10;
              i_exponent++;
            }
    
          i_mantissa = i_mantissa * (int32s)f_value;
        }
      
    
    Hope this helps.
     
    NickD, May 18, 2016
    #2
  3. pspeirs

    pspeirs

    Joined:
    Nov 23, 2013
    Messages:
    185
    Likes Received:
    10
    Location:
    Sydney
    Hi there,

    Yes, that will point me in the right direction, appreciate the assistance. It was more getting my head around the logic of workig out the scaling factor to apply.

    I'll need to translate the commands to my flavour of C however that will give me something to do on my daily train ride to work.

    Time for the next post :)


    Regards,
    Paul
     
    pspeirs, May 23, 2016
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.