Hex Represented as Ascii
RonenKatz
Posts: 6
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
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
0
Comments
Num = HEXTOI('126EC') // Num = 75500
Paul
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
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.