<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 nowadays the Java binding doesn't support the datatype "File Descriptor". <BR>
<BR>
A file descriptor is needed because is the way in 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> <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 he 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> <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 dBus Session, not in the 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> <BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN>This is my code and it works, I hope it is useful for you:</SPAN></SPAN><BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN></SPAN></SPAN> <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> <BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN>-------------</SPAN></SPAN><BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN></SPAN></SPAN> <BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN> <BR><STRONG>//Getting a DBus connection<BR></STRONG>try {<BR> dbusConn = DBusConnection.getConnection(<STRONG>DBusConnection.SESSION</STRONG>);<BR>} catch (DBusException e) { <BR> throw new BusinessRuleException(BusinessRuleError.ERROR_CONNECTION_DBUS, errorBundle.getString(Integer.toString(BusinessRuleError.ERROR_CONNECTION_DBUS)));<BR>}<BR>if(dbusConn == null)<BR>{<BR> throw new BusinessRuleException(BusinessRuleError.ERROR_CONNECTION_DBUS, errorBundle.getString(Integer.toString(BusinessRuleError.ERROR_CONNECTION_DBUS))); <BR>}<BR> </SPAN></SPAN><BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN><STRONG>//Getting the HealthManager object<BR></STRONG>try {<BR> bluezHealthManager = dbusConn.getRemoteObject("org.bluez", "/org/bluez", org.bluez.HealthManager.class);<BR>} catch (DBusException e) {<BR> throw new BusinessRuleException(BusinessRuleError.ERROR_HEALTHMANAGER_BLUEZ, errorBundle.getString(Integer.toString(BusinessRuleError.ERROR_HEALTHMANAGER_BLUEZ)));<BR>}<BR>if(bluezHealthManager == null)<BR>{<BR> throw new BusinessRuleException(BusinessRuleError.ERROR_HEALTHMANAGER_BLUEZ, errorBundle.getString(Integer.toString(BusinessRuleError.ERROR_HEALTHMANAGER_BLUEZ))); <BR>}<BR> <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<String, Variant> dictionary = new HashMap<String, Variant>();</SPAN></SPAN><BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN></SPAN></SPAN> <BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN>UInt16 managerType = new UInt16(0x1007); <BR></SPAN></SPAN><SPAN lang=ES-MODERN><SPAN lang=ES-MODERN>dictionary.put("DataType", new Variant(managerType)); <BR>dictionary.put("Role",new Variant(strRole));<BR>dictionary.put("Description",new Variant(strDescription));<BR>dictionary.put("ChannelType",new Variant(strChannelType));<BR> <BR>Path managerPath = null;<BR>managerPath = bluezHealthManager.CreateApplication(dictionary);<BR>if(managerPath == null)<BR>{<BR> throw new BusinessRuleException(BusinessRuleError.ERROR_REGISTER_X73MANAGER_DBUS, errorBundle.getString(Integer.toString(BusinessRuleError.ERROR_REGISTER_X73MANAGER_DBUS))); <BR>}</SPAN></SPAN><BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN></SPAN></SPAN> <BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN></SPAN></SPAN> <BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN></SPAN></SPAN> <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> <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> <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> public Path CreateApplication(Map<String,Variant> dic);<BR> 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> <BR>
<SPAN lang=ES-MODERN><SPAN lang=ES-MODERN></SPAN></SPAN> <BR>
---------------<BR>
<BR> <BR>
<DIV>
> Date: Thu, 14 Jul 2011 17:21:46 -0400<BR>> From: james.connors@oracle.com<BR>> To: dbus@lists.freedesktop.org<BR>> Subject: dbus-java for Bluetooth HDP<BR>> <BR>> Hello,<BR>> <BR>> I'm trying to use dbus-java to communicate with a bluetooth Heathcare <BR>> Device Profile (HDP) cpmpliant pulse oxymiter. There has been some work <BR>> demonstrating this capability with the Python dbus binding, but next to <BR>> nothing on the Java front from what I see. Not being a Python <BR>> aficionado, trying to map the Python stuff over to Java isn't working <BR>> out too well. The example below attempts to make a remote invocation <BR>> on a method called CreateApplication() as specified by the following <BR>> interface:<BR>> <BR>> package org.bluez;<BR>> import java.util.Map;<BR>> import org.freedesktop.dbus.DBusInterface;<BR>> import org.freedesktop.dbus.Variant;<BR>> <BR>> public interface HealthManager extends DBusInterface<BR>> {<BR>> public DBusInterface CreateApplication(Map<String,Variant> a);<BR>> public void DestroyApplication(DBusInterface a);<BR>> }<BR>> <BR>> The simple application below throws a DBusExecution exception when <BR>> reaching the CreateApplication() method call:<BR>> <BR>> package testhdp;<BR>> <BR>> import java.util.Map;<BR>> import java.util.HashMap;<BR>> import org.freedesktop.DBus;<BR>> import org.freedesktop.dbus.DBusConnection;<BR>> import org.freedesktop.dbus.DBusInterface;<BR>> import org.freedesktop.dbus.Variant;<BR>> import org.freedesktop.dbus.UInt16;<BR>> import org.bluez.Manager;<BR>> import org.bluez.HealthManager;<BR>> import org.freedesktop.DBus.Introspectable;<BR>> <BR>> class TestHDP {<BR>> <BR>> public static void main(String[] args) throws<BR>> org.freedesktop.dbus.exceptions.DBusException {<BR>> <BR>> DBusConnection conn =<BR>> DBusConnection.getConnection(DBusConnection.SYSTEM);<BR>> <BR>> DBus dbus = conn.getRemoteObject(<BR>> "org.freedesktop.DBus", "/org/freedesktop/DBus", <BR>> DBus.class);<BR>> <BR>> String ORG_BLUEZ = "org.bluez";<BR>> System.out.print("Searching dbus.ListNames() return for " +<BR>> "\"" + ORG_BLUEZ + "\": ");<BR>> String[] names = dbus.ListNames();<BR>> boolean bluezFound = false;<BR>> for (String name: names)<BR>> if (name.equals(ORG_BLUEZ)) {<BR>> bluezFound = true;<BR>> break;<BR>> }<BR>> if (bluezFound)<BR>> System.out.println(ORG_BLUEZ + " found.");<BR>> else<BR>> System.out.println(ORG_BLUEZ + " not found.");<BR>> <BR>> Manager m = (Manager) conn.getRemoteObject("org.bluez", "/",<BR>> Manager.class);<BR>> System.out.println(m.toString());<BR>> Map<String, Variant> props = m.GetProperties();<BR>> <BR>> HealthManager hm = (HealthManager) conn.getRemoteObject(<BR>> "org.bluez", "/org/bluez", HealthManager.class);<BR>> System.out.println(hm.toString());<BR>> <BR>> Map<String, Variant> config = new HashMap<String, Variant>();<BR>> config.put("DataType", new Variant<UInt16>(new UInt16(0x1004)));<BR>> config.put("Role", new Variant<String>("Sink"));<BR>> config.put("Description", new Variant<String>("Oximeter Sink"));<BR>> <BR>> DBusInterface app = hm.CreateApplication(config);<BR>> <BR>> conn.disconnect();<BR>> }<BR>> }<BR>> <BR>> Output is as follows:<BR>> <BR>> Searching dbus.ListNames() return for "org.bluez": org.bluez found.<BR>> org.bluez:/:interface org.bluez.Manager<BR>> org.bluez:/org/bluez:interface org.bluez.HealthManager<BR>> Exception in thread "main" <BR>> org.freedesktop.dbus.exceptions.DBusExecutionException: Wrong return <BR>> type (failed to de-serialize correct types: Failed to create proxy <BR>> object for /org/bluez/health_app_30 exported by :1.51. Reason: Could not <BR>> find an interface to cast to )<BR>> at org.freedesktop.dbus.RemoteInvocationHandler.convertRV(Unknown <BR>> Source)<BR>> at <BR>> org.freedesktop.dbus.RemoteInvocationHandler.executeRemoteMethod(Unknown <BR>> Source)<BR>> at org.freedesktop.dbus.RemoteInvocationHandler.invoke(Unknown Source)<BR>> at $Proxy2.CreateApplication(Unknown Source)<BR>> at testhdp.TestHDP.main(TestHDP.java:66)<BR>> <BR>> <BR>> <BR>> Any guidance would be greatly appreciated.<BR>> <BR>> Thanks,<BR>> Jim Connors<BR>> <BR>> _______________________________________________<BR>> dbus mailing list<BR>> dbus@lists.freedesktop.org<BR>> http://lists.freedesktop.org/mailman/listinfo/dbus<BR></DIV>                                            </div></body>
</html>