Home AMX User Forum AMX Technical Discussion

Barco Hex Conversion

Hi all,

I'm working with a Barco projector and struggling with lamp hours feedback. The commands manual states that the lamp hours figure is returned from the projector in the following fashion:

Start, Projector Address, Command[0], Data[0], Data[1], Data[2], Data[3], Checksum, Stop

which respectively is:

$FE,$01,$64,$00,$00,$00,$64,$C9,$FF

So data bits are:
$00,
$00,
$00,
$64

the formula to calculate lamp hours in hours is '$00 * 256^3 + $00 * 256^2 + $00 * 256 + $64'

How do I convert the hex values into a more readable data format, int or long for example?

Thanks,
Nick

Comments

  • BigsquatchBigsquatch Posts: 216
    Here's what I have (not tested yet):
    hours = (768 * ATOI(cData[1])) + (512 * ATOI(cData[2])) + (256 * ATOI(cData[3])) + ATOI(cData[4])
    
  • This isn't Netlinx code (it's Cue), but it gets the lamp hours from a Barco projector H250.

    You'll need to replace 'result(x)' with your data bytes, but the multipliers should be correct.

    lampRunTime = (result(11) * 16777216) + (result(12) * 65536) + (result(13) * 256) + result(14)
  • BigsquatchBigsquatch Posts: 216
    Doh! I need to fix my code then. Darned exponents.

    Also I should have pointed out that in my example I have removed the 1st 3 bytes of the string, that is why I am starting at byte 1 instead of 4.

    Edit: The time is reported in hours isn't it? (when using $64 to resuest lamp hours) I can't imagine the lamp hours on a projector ever getting above 1 million let alone 16 mil.
  • AuserAuser Posts: 506
    It's a bit moot here, but there's generally a (large) performance gain to be had by avoiding such multiplication and using left shift (ie. <<) instead.

    Based on what has been posted previously, the following should work for you (brackets for clarity):
    define_function long ParseLampHours(char cData[])
    {
      stack_var  long  lLampHours
      lLampHours = ((cData[1] << 24) + (cData[2] << 16) + (cData[3] << 8) + (cData[4]))
      return lLampHours
    }
    
  • PhreaKPhreaK Posts: 966
    Auser wrote: »
    It's a bit moot here, but there's generally a (large) performance gain to be had by avoiding such multiplication and using left shift (ie. <<) instead.

    Based on what has been posted previously, the following should work for you (brackets for clarity):
    define_function long ParseLampHours(char cData[])
    {
      stack_var  long  lLampHours
      lLampHours = ((cData[1] << 24) + (cData[2] << 16) + (cData[3] << 8) + (cData[4]))
      return lLampHours
    }
    

    +1 on that. You're speaking to a computer so speak like a computer.
  • Jorde_VJorde_V Posts: 393
    PhreaK wrote: »
    +1 on that. You're speaking to a computer so speak like a computer.

    I've been speaking in a voice-generated-voice to the computer for the past few hours, but I can't say it's made any difference.

    Jokes aside, I agree. If you're tryin to converse with someone/-thing the most accessible way to do so is in their native language. Only if you can't should you look at other ways. (Say Java)

    Doing it that way makes your program run faster and more efficient as well.
  • papadoukpapadouk Posts: 58
    this is also a possible way to do it:

    //Converting Auser's function
    define_function long ParseLampHours(char cData[])
    {
    stack_var long lLampHours
    STRING_TO_VARIABLE(lLampHours,"$E3,cData",1)
    return lLampHours
    }
Sign In or Register to comment.