Page 1 of 1

Output, send Hex to port

Posted: Thu Oct 11, 2012 2:47 pm
by Dirk-Jan
Hello everyone,

I am sending udp data from my pc to the E-blocks internet board.
The data that I am sending is formatted in Hexadecimal. So 01 mean 1 and ff means 255.
Now I want to output this to a E-Blocks LED board, but I don't know how to do this.
I tried to put it into a string and use this in a output block (I know that FC can output hex to a port) but it won't accept a string only a byte.
Is there maybe some easy to to achieve this or should I try to code something up in a C block?

Thank you.

Re: Output, send Hex to port

Posted: Thu Oct 11, 2012 3:05 pm
by Enamul
Hello,
I am not quite sure whether I understood your problem or not..I have attached here a program in which I have shown three possible data format for output..Binary, Hex or Decimal

Re: Output, send Hex to port

Posted: Thu Oct 11, 2012 3:41 pm
by Dirk-Jan
Well the issue is that I am receiving something through a macro which will write it to a string variable.
Now I want to output this string variable to a port just like you did with 0xFF to port B but now it has to use the string.
And the output block's don't accept a string as a variable.

Re: Output, send Hex to port

Posted: Thu Oct 11, 2012 3:52 pm
by Enamul
Output can accept string..like..

Code: Select all

DATA[0]
it won't accept a string only a byte.
That's true byte is 8-bit so you can send to port maximum 8-bit. What is the length of your string and how you want to see them in LED? you can show byte-by-byte with some intermediate delay..although LCD is best for this..as you can see whole string at a time.

Re: Output, send Hex to port

Posted: Thu Oct 11, 2012 4:00 pm
by Dirk-Jan
The data I have to work with is hexadecimal and goes from 01 to FF.
In total I have 8 leds and want them to switch on or off with the hex data.
So basicly if I send 01 only the first led will go on with 02 the second etc.
If I send 03 I want the first 2 leds to go on all the way until FF.

I already tried to use DATA[0] but It didn't matter what kind of value DATA had.
Only the 1, 5 and 6 led would go on. So it seems like it sended 49 in bytes.

Re: Output, send Hex to port

Posted: Thu Oct 11, 2012 4:12 pm
by Enamul
I already tried to use DATA[0] but It didn't matter what kind of value DATA had.
Only the 1, 5 and 6 led would go on. So it seems like it sended 49 in bytes.
I understand what you mean..Just clear me one thing..I might help you in designing the code. When LED 1,5 and 6 turn ON and it seems to you it sent 49..what actually you sent 1?

Re: Output, send Hex to port

Posted: Thu Oct 11, 2012 4:16 pm
by Dirk-Jan
For that example I used test[0], I think it shouldn't be that hard though I just need to output FF or any other hex value to let the leds switch On or Off

Re: Output, send Hex to port

Posted: Thu Oct 11, 2012 4:17 pm
by Enamul
If so, just do following..If DATA[0] is your string byte..

Code: Select all

DATA[0]=DATA[0]-'0'
In that case DATA[0]= 49-'0' = 49-48 = 1
Send that DATA[0] to PORT so only first LED will turn ON.
If you send 2 it's ASCII will be 50..DATA[0]= 50-48 = 2. So only 2nd LED will turn ON

Re: Output, send Hex to port

Posted: Thu Oct 11, 2012 4:40 pm
by Dirk-Jan
Thanks you! I think I am able to manage it now!

Re: Output, send Hex to port

Posted: Thu Oct 11, 2012 4:50 pm
by Enamul
Glad to know that. You are welcome :)