<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'><div dir='ltr'>
Hi Jim.<BR>
I have tried to develop a X73 Manager for a Blood Pressure Monitor with BT HDP and Java, but&nbsp;nowadays the Java binding doesn't support the datatype "File Descriptor".&nbsp;<BR>
&nbsp;<BR>
A file descriptor is needed because is the way in&nbsp;which the device sends data to the manager. It is defined in the "health API" doc of bluez, the <SPAN lang=ES-MODERN>org.bluez.HealthChannel interface has the method "<SPAN lang=ES-MODERN>fd Acquire()" (fd: file descriptor).</SPAN></SPAN><BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN></SPAN></SPAN>&nbsp;<BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN>The Java binding's author (Matthew Johnson <A href="mailto:dbus@matthew.ath.cx">dbus@matthew.ath.cx</A>) said to me that&nbsp;he&nbsp;cannot to incorporate that datatype at the moment. I tried it, but it isn't easy...</SPAN></SPAN><BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN></SPAN></SPAN>&nbsp;<BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN>Anyway, related to your code I see a few things:</SPAN></SPAN><BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN>- You have to work with a dBus connection for the current Session, no with the dBus system... way? I don't know. I just know that the Bluetooth HDP only creates the HealthManager in the&nbsp;dBus Session, not in the&nbsp;dBus System...</SPAN></SPAN><BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN>- You don't need to get the remote object for the dBus connection! </SPAN></SPAN><BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN></SPAN></SPAN>&nbsp;<BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN>This is my code and&nbsp;it works, I hope it is useful for you:</SPAN></SPAN><BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN></SPAN></SPAN>&nbsp;<BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN>Cheers,</SPAN></SPAN><BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN>Santiago</SPAN></SPAN><BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN></SPAN></SPAN>&nbsp;<BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN>-------------</SPAN></SPAN><BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN></SPAN></SPAN>&nbsp;<BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN>&nbsp;<BR><STRONG>//Getting a DBus connection<BR></STRONG>try {<BR>&nbsp;dbusConn = DBusConnection.getConnection(<STRONG>DBusConnection.SESSION</STRONG>);<BR>} catch (DBusException e) {&nbsp;&nbsp;&nbsp;<BR>&nbsp;throw new BusinessRuleException(BusinessRuleError.ERROR_CONNECTION_DBUS, errorBundle.getString(Integer.toString(BusinessRuleError.ERROR_CONNECTION_DBUS)));<BR>}<BR>if(dbusConn == null)<BR>{<BR>&nbsp;throw new BusinessRuleException(BusinessRuleError.ERROR_CONNECTION_DBUS, errorBundle.getString(Integer.toString(BusinessRuleError.ERROR_CONNECTION_DBUS)));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>}<BR>&nbsp;&nbsp;</SPAN></SPAN><BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN><STRONG>//Getting the HealthManager object<BR></STRONG>try {<BR>&nbsp;bluezHealthManager = dbusConn.getRemoteObject("org.bluez", "/org/bluez", org.bluez.HealthManager.class);<BR>} catch (DBusException e) {<BR>&nbsp;throw new BusinessRuleException(BusinessRuleError.ERROR_HEALTHMANAGER_BLUEZ, errorBundle.getString(Integer.toString(BusinessRuleError.ERROR_HEALTHMANAGER_BLUEZ)));<BR>}<BR>if(bluezHealthManager == null)<BR>{<BR>&nbsp;throw new BusinessRuleException(BusinessRuleError.ERROR_HEALTHMANAGER_BLUEZ, errorBundle.getString(Integer.toString(BusinessRuleError.ERROR_HEALTHMANAGER_BLUEZ)));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>}<BR>&nbsp;&nbsp;<BR><STRONG>//Registering the X73 Manager for a Blood Pressure Monitor in dBus<BR></STRONG></SPAN></SPAN><SPAN lang=ES-MODERN><SPAN lang=ES-MODERN>Map&lt;String, Variant&gt; dictionary = new HashMap&lt;String, Variant&gt;();</SPAN></SPAN><BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN></SPAN></SPAN>&nbsp;<BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN>UInt16 managerType = new UInt16(0x1007);&nbsp;<BR></SPAN></SPAN><SPAN lang=ES-MODERN><SPAN lang=ES-MODERN>dictionary.put("DataType", new Variant(managerType));&nbsp;<BR>dictionary.put("Role",new Variant(strRole));<BR>dictionary.put("Description",new Variant(strDescription));<BR>dictionary.put("ChannelType",new Variant(strChannelType));<BR>&nbsp;&nbsp;<BR>Path managerPath = null;<BR>managerPath = bluezHealthManager.CreateApplication(dictionary);<BR>if(managerPath == null)<BR>{<BR>&nbsp;throw new BusinessRuleException(BusinessRuleError.ERROR_REGISTER_X73MANAGER_DBUS, errorBundle.getString(Integer.toString(BusinessRuleError.ERROR_REGISTER_X73MANAGER_DBUS)));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>}</SPAN></SPAN><BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN></SPAN></SPAN>&nbsp;<BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN></SPAN></SPAN>&nbsp;<BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN></SPAN></SPAN>&nbsp;<BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN><STRONG>The HealthManager interface in Java is defined as:</STRONG></SPAN></SPAN><BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN></SPAN></SPAN>&nbsp;<BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN>package org.bluez;</SPAN></SPAN><BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN>import java.util.Map;</SPAN></SPAN><BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN><BR>import org.freedesktop.dbus.DBusInterface;<BR>import org.freedesktop.dbus.Path;<BR>import org.freedesktop.dbus.Variant;</SPAN></SPAN><BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN></SPAN></SPAN>&nbsp;<BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN>public interface HealthManager extends DBusInterface<BR>{</SPAN></SPAN><BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN>&nbsp; public Path CreateApplication(Map&lt;String,Variant&gt; dic);<BR>&nbsp; public void DestroyApplication(Path o);</SPAN></SPAN><BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN>}</SPAN></SPAN><BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN><BR></SPAN></SPAN>&nbsp;<BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN></SPAN></SPAN>&nbsp;<BR>
---------------<BR>
<BR>&nbsp;<BR>
<DIV>
&gt; Date: Thu, 14 Jul 2011 17:21:46 -0400<BR>&gt; From: james.connors@oracle.com<BR>&gt; To: dbus@lists.freedesktop.org<BR>&gt; Subject: dbus-java for Bluetooth HDP<BR>&gt; <BR>&gt; Hello,<BR>&gt; <BR>&gt; I'm trying to use dbus-java to communicate with a bluetooth Heathcare <BR>&gt; Device Profile (HDP) cpmpliant pulse oxymiter. There has been some work <BR>&gt; demonstrating this capability with the Python dbus binding, but next to <BR>&gt; nothing on the Java front from what I see. Not being a Python <BR>&gt; aficionado, trying to map the Python stuff over to Java isn't working <BR>&gt; out too well. The example below attempts to make a remote invocation <BR>&gt; on a method called CreateApplication() as specified by the following <BR>&gt; interface:<BR>&gt; <BR>&gt; package org.bluez;<BR>&gt; import java.util.Map;<BR>&gt; import org.freedesktop.dbus.DBusInterface;<BR>&gt; import org.freedesktop.dbus.Variant;<BR>&gt; <BR>&gt; public interface HealthManager extends DBusInterface<BR>&gt; {<BR>&gt; public DBusInterface CreateApplication(Map&lt;String,Variant&gt; a);<BR>&gt; public void DestroyApplication(DBusInterface a);<BR>&gt; }<BR>&gt; <BR>&gt; The simple application below throws a DBusExecution exception when <BR>&gt; reaching the CreateApplication() method call:<BR>&gt; <BR>&gt; package testhdp;<BR>&gt; <BR>&gt; import java.util.Map;<BR>&gt; import java.util.HashMap;<BR>&gt; import org.freedesktop.DBus;<BR>&gt; import org.freedesktop.dbus.DBusConnection;<BR>&gt; import org.freedesktop.dbus.DBusInterface;<BR>&gt; import org.freedesktop.dbus.Variant;<BR>&gt; import org.freedesktop.dbus.UInt16;<BR>&gt; import org.bluez.Manager;<BR>&gt; import org.bluez.HealthManager;<BR>&gt; import org.freedesktop.DBus.Introspectable;<BR>&gt; <BR>&gt; class TestHDP {<BR>&gt; <BR>&gt; public static void main(String[] args) throws<BR>&gt; org.freedesktop.dbus.exceptions.DBusException {<BR>&gt; <BR>&gt; DBusConnection conn =<BR>&gt; DBusConnection.getConnection(DBusConnection.SYSTEM);<BR>&gt; <BR>&gt; DBus dbus = conn.getRemoteObject(<BR>&gt; "org.freedesktop.DBus", "/org/freedesktop/DBus", <BR>&gt; DBus.class);<BR>&gt; <BR>&gt; String ORG_BLUEZ = "org.bluez";<BR>&gt; System.out.print("Searching dbus.ListNames() return for " +<BR>&gt; "\"" + ORG_BLUEZ + "\": ");<BR>&gt; String[] names = dbus.ListNames();<BR>&gt; boolean bluezFound = false;<BR>&gt; for (String name: names)<BR>&gt; if (name.equals(ORG_BLUEZ)) {<BR>&gt; bluezFound = true;<BR>&gt; break;<BR>&gt; }<BR>&gt; if (bluezFound)<BR>&gt; System.out.println(ORG_BLUEZ + " found.");<BR>&gt; else<BR>&gt; System.out.println(ORG_BLUEZ + " not found.");<BR>&gt; <BR>&gt; Manager m = (Manager) conn.getRemoteObject("org.bluez", "/",<BR>&gt; Manager.class);<BR>&gt; System.out.println(m.toString());<BR>&gt; Map&lt;String, Variant&gt; props = m.GetProperties();<BR>&gt; <BR>&gt; HealthManager hm = (HealthManager) conn.getRemoteObject(<BR>&gt; "org.bluez", "/org/bluez", HealthManager.class);<BR>&gt; System.out.println(hm.toString());<BR>&gt; <BR>&gt; Map&lt;String, Variant&gt; config = new HashMap&lt;String, Variant&gt;();<BR>&gt; config.put("DataType", new Variant&lt;UInt16&gt;(new UInt16(0x1004)));<BR>&gt; config.put("Role", new Variant&lt;String&gt;("Sink"));<BR>&gt; config.put("Description", new Variant&lt;String&gt;("Oximeter Sink"));<BR>&gt; <BR>&gt; DBusInterface app = hm.CreateApplication(config);<BR>&gt; <BR>&gt; conn.disconnect();<BR>&gt; }<BR>&gt; }<BR>&gt; <BR>&gt; Output is as follows:<BR>&gt; <BR>&gt; Searching dbus.ListNames() return for "org.bluez": org.bluez found.<BR>&gt; org.bluez:/:interface org.bluez.Manager<BR>&gt; org.bluez:/org/bluez:interface org.bluez.HealthManager<BR>&gt; Exception in thread "main" <BR>&gt; org.freedesktop.dbus.exceptions.DBusExecutionException: Wrong return <BR>&gt; type (failed to de-serialize correct types: Failed to create proxy <BR>&gt; object for /org/bluez/health_app_30 exported by :1.51. Reason: Could not <BR>&gt; find an interface to cast to )<BR>&gt; at org.freedesktop.dbus.RemoteInvocationHandler.convertRV(Unknown <BR>&gt; Source)<BR>&gt; at <BR>&gt; org.freedesktop.dbus.RemoteInvocationHandler.executeRemoteMethod(Unknown <BR>&gt; Source)<BR>&gt; at org.freedesktop.dbus.RemoteInvocationHandler.invoke(Unknown Source)<BR>&gt; at $Proxy2.CreateApplication(Unknown Source)<BR>&gt; at testhdp.TestHDP.main(TestHDP.java:66)<BR>&gt; <BR>&gt; <BR>&gt; <BR>&gt; Any guidance would be greatly appreciated.<BR>&gt; <BR>&gt; Thanks,<BR>&gt; Jim Connors<BR>&gt; <BR>&gt; _______________________________________________<BR>&gt; dbus mailing list<BR>&gt; dbus@lists.freedesktop.org<BR>&gt; http://lists.freedesktop.org/mailman/listinfo/dbus<BR></DIV>                                               </div></body>
</html>