PDA

View Full Version : Question about sending serial 2 digit HEX commands



penelopepug
- 2nd November 2013, 14:17
Hi!

Can someone please tell me how to send 2 digit hex values using a variable in the Serout2 command?

I am sending file playing commands to a serial MP3 module. There are only 12 tracks. The select case code I show works but I am sure I can achieve the same thing if I can specify the format of the variable "Demo" using Serout2 . Demo is a variable that contains decimal 1 to 12 and I want to send the equivalent of Serout2 MP3data,188,[$01], Serout2 MP3data,188,[$02], Serout2 MP3data,188,[$03], etc. I need 2 hex digits to be sent.

Will this "Serout2 MP3data,188,[Hex2 Demo]" give me the same results as my select case code or do I need to use this;

"Serout2 MP3data,188,[IHex2 Demo]"

I don't have the parts to test anything until Monday but the select case code I tested before.

Thanks for any advice.


The code below works;
'Select Case Demo
case 1
Serout2 MP3data,188,[$01]
case 2
Serout2 MP3data,188,[$02]
case 3
Serout2 MP3data,188,[$03]
case 4
Serout2 MP3data,188,[$04]
case 5
Serout2 MP3data,188,[$05]
case 6
Serout2 MP3data,188,[$06]
case 7
Serout2 MP3data,188,[$07]
case 8
Serout2 MP3data,188,[$08]
case 9
Serout2 MP3data,188,[$09]
case 10
Serout2 MP3data,188,[$0A]
case 11
Serout2 MP3data,188,[$0B]
case 12
Serout2 MP3data,188,[$0C]
end select

Darrel Taylor
- 2nd November 2013, 14:41
If that works, then so will this ...

Serout2 MP3data,188,[Demo]

Because your select case is sending Binary, not ASCII Hex.
The $ sign allows you to format your source code as Hex.

penelopepug
- 2nd November 2013, 19:50
Thanks for your reply Darrel.

So you are saying that "Serout2 MP3data,188,[Demo]" will achieve the same thing, but do I not need to specify the digits such as using Hex2 Demo?

Thanks.

Darrel Taylor
- 3rd November 2013, 17:57
I don't really know what your MP3 player is expecting.

I'm just going by your statement that the Select Case works.
And if that works, then so will the single SEROUT2 line without any HEX modifiers.