Skip to first unread message

Paulo Benetti

unread,
Mar 10, 2016, 3:11:07 PM3/10/16
to MIT App Inventor Forum
Hello guys,

I am developing an app to make the capture of data from a central alarm.
I need to send the data to HEX but so far had no success.
The communication specifications are: baud 2400 / data size 8 / no parity.

Ex. I send 6-byte hex (A5 DD 02 20 03 ED) and central returns
Hex 19 bytes (00 00 00 00 00 00 FF FF FF FF ...)

Can anyone help me with this.

Thank you very much.

Abraham Getzler

unread,
Mar 10, 2016, 6:43:06 PM3/10/16
to MIT App Inventor Forum
If you drag in a Web component in the Designer, that will give you access to conversion blocks you can use without going out to the Web.

See attached for a hexify routine that will create any hex string you want, and a sample call that will create a Byte Order Marker (BOM) of x'FEFF'.

There is also a block that can reverse this, called URIEncode (decode?).

ABG



hexify.aia
hexify.png
BOM.png

Paulo Benetti

unread,
Mar 11, 2016, 12:49:45 PM3/11/16
to MIT App Inventor Forum
Hi ABG

i'm test your blocks and some number hex is okay.

When the number hex is betwin 00 - 7F, the conversion is right and the bluetooth send the conversion has no problem,

 but when the number hex is betwin 80 - FF the conversion is wrong. note the picture attached.

Imagem inline 1

What's the problem?

Thanks and regards,

Paulo
BLOCKS.PNG
convert.PNG

Abraham Getzler

unread,
Mar 11, 2016, 1:06:35 PM3/11/16
to MIT App Inventor Forum
First, a word about my BOM and stripBOM procedures.

They were included by me as an example of how a call to hexify() looks like,
but they are not appropriate to your problem.

They are intended for use only to preprocess a file coming from Excel with
two specific hex bytes in front.  

Remove them.


Second, about the wierdness when you pass 7F ...

This is probably about UTF-8 encoding, which is the default on the Bluetooth client.
Google UTF-8 for explanation as how and why it works.

Your receiving device (unavailable to me) is probably set differently in its encoding strategy.

ABG

Paulo Benetti

unread,
Mar 11, 2016, 2:09:44 PM3/11/16
to MIT App Inventor Forum
Ok, the problem is the signed number

a value is 8bits but is -127~127.

How i sent unsigned number with bluetooth, you know?

Abraham Getzler

unread,
Mar 11, 2016, 2:45:53 PM3/11/16
to MIT App Inventor Forum
http://ai2.appinventor.mit.edu/reference/components/connectivity.html#BluetoothClient

How about 

BTClient1.SendBytes(create list(0,0,...,255,255)) ?

ABG

Abraham Getzler

unread,
Mar 11, 2016, 3:02:51 PM3/11/16
to MIT App Inventor Forum
Have you tried BTClient.SendBytes?
See attached.
I'm not sure this will work.
Let us know?

ABG

sendBytes.png
Reply all
Reply to author
Forward
0 new messages