<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";
color:black;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0cm;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New";
color:black;}
tt
{mso-style-priority:99;
font-family:"Courier New";}
span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:Consolas;
color:black;}
span.EmailStyle21
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.Section1
{page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body bgcolor=white lang=EN-GB link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Morning Steve,<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>That stuff looks mighty promising, I did play around with the
toString() function yesterday but couldn’t get the damned thing working. The
syntax has me a little muddled, perhaps you can help out on this by taking a
look at my code.<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;
font-family:"Courier New";color:windowtext'>#!/usr/bin/python<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;
font-family:"Courier New";color:windowtext'>import dbus<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;
font-family:"Courier New";color:windowtext'><o:p> </o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;
font-family:"Courier New";color:windowtext'>bus = dbus.SystemBus()<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;
font-family:"Courier New";color:windowtext'>obj = bus.get_object('org.bluez',
'/org/bluez')<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;
font-family:"Courier New";color:windowtext'>obj = bus.get_object('org.bluez',
'/org/bluez/hci0')<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;
font-family:"Courier New";color:windowtext'>adapter = dbus.Interface(obj,
'org.bluez.Adapter')<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;
font-family:"Courier New";color:windowtext'><o:p> </o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;
font-family:"Courier New";color:windowtext'># Search For Obex Push Protocol<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;
font-family:"Courier New";color:windowtext'>result =
adapter.GetRemoteServiceHandles('00:17:B0:A0:E7:09', 'opp')<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;
font-family:"Courier New";color:windowtext'><o:p> </o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:9.0pt;
font-family:"Courier New";color:windowtext'>result2 = adapter.GetRemoteServiceRecord('00:17:B0:A0:E7:09',
result[0])<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Now ‘result2’ is basically that byte array, Unfortunately the
API doesn’t give any more information other than that the function returns a
array{byte} so I can’t really shed any more light on that however if I can just
get it to output all the elements from that array then I will know which one it
is I’m looking for.<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>I tried to implement your suggestions below as they look pretty
safe, but I couldn’t get it to work, my syntax is pretty confused as I’m so new
to the language. Like I say, there is only one element of the array I’m interested
in, I just need to see them all before I know which it is.<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Thanks again Steve,<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Rob<o:p></o:p></span></p>
<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<div>
<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'>
<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
"Tahoma","sans-serif";color:windowtext'>From:</span></b><span lang=EN-US
style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext'>
Steven Howe [mailto:howe.steven@gmail.com] <br>
<b>Sent:</b> 19 April 2007 16:51<br>
<b>To:</b> Robert Rawlins - Think Blue<br>
<b>Cc:</b> python-list@python.org<br>
<b>Subject:</b> Re: Byte-Array to String<o:p></o:p></span></p>
</div>
</div>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>Robert Rawlins - Think Blue wrote: <o:p></o:p></p>
<pre>Hello Guys,<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> <o:p></o:p></pre><pre><o:p> </o:p></pre><pre>I have a byte array passed to me by dbus and I'm looking to convert it into<o:p></o:p></pre><pre>a string? Is that possible? Sorry for seeming like a putts with these<o:p></o:p></pre><pre>questions, I'm not used to all these complex data types :-D<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> <o:p></o:p></pre><pre><o:p> </o:p></pre><pre>The byte array looks something like this when printed to screen.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> <o:p></o:p></pre><pre><o:p> </o:p></pre><pre>dbus.Array([dbus.Byte(54), dbus.Byte(0), dbus.Byte(24), dbus.Byte(9),<o:p></o:p></pre><pre>dbus.Byte(0), dbus.Byte(0), dbus.Byte(10), dbus.Byte(0), dbu<o:p></o:p></pre><pre>s.Byte(0), dbus.Byte(0), dbus.Byte(0), dbus.Byte(9), dbus.Byte(0),<o:p></o:p></pre><pre>dbus.Byte(1), dbus.Byte(53), dbus.Byte(3), dbus.Byte(25), dbus.<o:p></o:p></pre><pre>Byte(16), dbus.Byte(0), dbus.Byte(9), dbus.Byte(2), dbus.Byte(0),<o:p></o:p></pre><pre>dbus.Byte(53), dbus.Byte(3), dbus.Byte(9), dbus.Byte(1), dbus.By<o:p></o:p></pre><pre>te(1)], signature=dbus.Signature('y'))<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> <o:p></o:p></pre><pre><o:p> </o:p></pre><pre>Thanks again,<o:p></o:p></pre><pre><o:p> </o:p></pre><pre> <o:p></o:p></pre><pre><o:p> </o:p></pre><pre>Rob<o:p></o:p></pre><pre><tt
id=l2h-1375><b><o:p> </o:p></b></tt></pre>
<p class=MsoNormal>When reading about array, I wondered what the hell it was
good for. Now I see. It's a tool to build objects <br>
to pass to the Operating System or other applications. Something like ctypes.
The OS might store data from left to right, or right to left, or not use IEEE
standards (which VMS certainly doesn't). So the data you give/get from the
system call must be massaged by the application before it's usable.<br>
<br>
python/lib/module-array.html (5.14 array -- Efficient arrays of numeric values)<br>
<tt id=l2h-1375><b><span style='font-size:10.0pt'>array.tostring</span></b></tt>(
)<br>
<i>Convert the array to an array of machine values and return the string
representation (the same sequence of bytes that would be written to a file by
the tofile() method.)</i><br>
<br>
I wonder if this is the method you are looking for. <br>
So you have an object dbus.Array, which, obviously is from a call to the dbus
(another application's data) that contains 28 byte arrays. I would assume you
know which you want, say the first one.<o:p></o:p></p>
<p class=MsoNormal>myDbusString01 = dbus.Array[0].tostring() <o:p></o:p></p>
<p class=MsoNormal>or to get the lot:<o:p></o:p></p>
<p class=MsoNormal>myDbusStrings = [] #create a new empty list<br>
for array in dbus.Array:<br>
myDbusStrings.append( array.tostring() )<o:p></o:p></p>
<p class=MsoNormal>At this point you should have the array converted. But you
will still need a reference as to what you have. The call to the dbus should
have some documentation abut what it's returning. <br>
Also I'd expect the second example to be very bad programming, as some of the
array elements are probably not going to be characters. They could be integers,
floats or booleans. So creating a dictionary to handle specific array element
handling is probably a better, less error prone, method of attack.<br>
<br>
Not have the contents and defination of your dbus.array handy, I can't test
this, but the approach seems reasonable.<br>
<br>
Steven Howe<o:p></o:p></p>
</div>
</body>
</html>