Home AMX User Forum AMX General Discussion
Options

Hex Represented as Ascii

Hi All,
I know this issue was discussed on several threads before, I could not find an answer.
I'm writing a module to control "Domintell" lighting system through TCP/IP.
Everything worked great until I tried to handle the feedback from a dimming module and tried to send a value from a level event.
The problem is it sends/receives the commands/feedback as Ascii letters that represent Hex:
Feedback Example:
DIM F12D 0 0 0 064 0 0 0
The "64" represents 64 hex = 100 decimal on the 5th dimmer channel
The problem is that regular hextoi doesn’t work. As far as I know, hextoi will convert each char to the equivalent hex value. But here I have 2 char's that represent 1 hex value.
Same for trying to send a level event, because it is an integer, trying to convert it with itohex will give me the wrong value.
I tried this with the level event :
iTensVal = level.value
iTensVal = (iTensVal/10)
iOnesVal = level.value
iOnesVal = (iOnesVal % 10)
send_string dvDomintell,"' DIM000F12-3%',itoa(iTensVal), itoa(iOnesVal),'D',$0D"
But it didn’t work correctly.
Any ideas?

Thank you,
Ronen

Comments

  • Options
    a_riot42a_riot42 Posts: 1,624
    I think you are mistaken about hextoi as it will convert a string not just a single character. From the docs:

    Num = HEXTOI('126EC') // Num = 75500

    Paul
  • Options
    HedbergHedberg Posts: 671
    And going the other way, itohex() should work. itohex() returns a string. itohex(100) should, for example, give you '64'.
  • Options
    This isn't the only way to do this, but this should work.

    char datastring[100];
    char hexstring[10];
    integer hexvalue;

    // example: datastring = 'DIM F12D 0 0 0 064 0 0 0'
    remove_string(datastring,' ',1) // datastring = 'F12D 0 0 0 064 0 0 0'
    remove_string(datastring,' ',1) // datastring = '0 0 0 064 0 0 0'
    remove_string(datastring,' ',1) // datastring = '0 0 064 0 0 0'
    remove_string(datastring,' ',1) // datastring = '0 064 0 0 0'
    remove_string(datastring,' ',1) // datastring = '064 0 0 0'
    hexstring = remove_string(datastring,' ',1) // hexstring = '064 '
    hexvalue = hextoi(hexstring) // hexvalue = 100
  • Options
    RonenKatz wrote: »
    Feedback Example:
    DIM F12D 0 0 0 064 0 0 0

    Looking at this string, the HEXTOI function probably saw the D in DIM as the value that was to be converted to an integer. If you removed all the extraneous parts of the feedback that you didn't need, for example everything before the 064, the HEXTOI function should work correctly.
Sign In or Register to comment.