Menu

How to use the java api

2009-05-24
2013-05-28
  • Jan-Philipp Bolle

    Hi,

    i instaled the BCU SDK and conected my computer via FT1.2. If I start the daemon (eibd -i -u ft12:/dev/ttyS0) I can switch on a light (groupswrite  local:/tmp/eib  0/0/1 00).
    Also the monitor works (busmonitor1 local:/tmp/eib).
    Now I like to use the same functions via the java API.
    I used the source of the jar from http://www.auto.tuwien.ac.at/~mkoegler/eib/eibddemo-0.0.3.jar .

    Now I like to do the same in java what groupswrite and busmonitor1.

    Is there a example how to use the java api?
    Any Idea how to find out how to use the java api?

    regards Philipp

     
    • Martin Koegler

      Martin Koegler - 2009-05-24

      The Java API provides exactly the same functions as the C API:
      http://sourceforge.net/mailarchive/message.php?msg_id=20071009185442.GA6098%40auto.tuwien.ac.at

      The main difference is, that the EIBConnection is passed implicitly and that the pointers are replaced with helper classes. Please read section "EIBD front end" of "EIBD front end" in the bcusdk documentation

      For the receiving part, please don't use busmonitor/vbusmonitor. Please use a GroupSocket and/or the GroupCache.

      In C, the sending example programs are groupwrite/groupswrite or groupsocketwrite/groupsocketwrite. The receiving example programs are groupsocketlisten and groupcachereadsync.

      Groupswrite in Java would be:
      byte data[] = new byte[2];
      data[0] = 0;
      data[1] =0x80 | (value & 0x3f) ;
      EIBConnection c = new EIBConnection ("localhost");
      if (c.EIBOpenT_Group ((short) 0x1103, true)==-1)
      throw new IOException ("Fehler: "+c.getLastError ());
      if(c.EIBSendAPDU (data)==-1)
      throw new IOException ("Fehler: "+c.getLastError ());

      The equivalent groupsocket code:
      byte data[] = new byte[2];
      data[0] = 0;
      data[1] =0x80 | (value & 0x3f) ;
      EIBConnection c = new EIBConnection ("localhost");
      if(c.EIBOpen_GroupSocket(true)==-1)
      throw new IOException ("Fehler: "+c.getLastError ());
      if(c.EIBSendGroup (0x1103, data)==-1)
      throw new IOException ("Fehler: "+c.getLastError ());

      0x1103 is the binary group address. You split the group address string at the /, convert all three parts to ints and then combine the values:  (a & 0x01f) << 11) | ((b & 0x07) << 8) | ((c & 0xff)

      If you need to send data a data type bigger than 6 bit:
      byte data[] = new byte[2 + <size of datatype in bytes>];
      data[0] = 0;
      data[1] =0x80;
      data[2]=<first byte of datatype>;
      data[3]=<second byte of datatype>;
      ....

      Getting state via groupcache:
          Buffer b = new Buffer ();
          EIBAddr src = new EIBAddr ();
          EIBConnection c = new EIBConnection ("127.0.0.1");
           if(c.EIB_Cache_Enable ()==-1)
      throw new IOException ("Fehler: "+c.getLastError ());
          if(c.EIB_Cache_Read_Sync ((short) 0x1103, src, b)==-1)
      throw new IOException ("Fehler: "+c.getLastError ());

      0x1103 is the group address (see above). If the size of b.data is 2, b.data[1]&0x3f contain the requested value, else the bytes from b.data[2] to b.data[b.data.length-1]

      EIBConnection c = new EIBConnection ("localhost");
      if(c.EIBOpen_GroupSocket(false)==-1)
      throw new IOException ("Fehler: "+c.getLastError ());
      while(true)
      {
          Buffer b = new Buffer ();
          EIBAddr src = new EIBAddr ();
          EIBAddr dest = new EIBAddr ();
      if (EIBGetGroup_Src(b, src, dest)==-1)
      throw new IOException ("Fehler: "+c.getLastError ());
      if (b.data.length>=2 && b.data[0]==0 && (b.data[1] & 0xC0) != 0xC0)
      {
      if(b.data[1] & 0xC0) == 0)
      continue;
      System.out.println("Destination: "+dest.addr); // binary value of the group address, decoding is the reverse process as above.
      // b.data contains a payload similiar to the example above.
      }
      }

       
    • Jan-Philipp Bolle

      Thank you for the very fast response.
      Now I am able to control my lamp.

      The first try to receive some date with the code was not successful.
      I missed the age parameter in your example (EIB_Cache_Read_Sync call). I used 0 for the missing parameter.
      If I call EIB_Cache_Read_Sync I always get the error code 9.

      But before asking more questions I will read the chapter "EIBD front end" again. ;-)

      Regards Philipp

       
      • Martin Koegler

        Martin Koegler - 2009-05-25

        EIBConnection.java contains the constants for the error values:
          public static final int EINVAL = 1;
          public static final int ECONNRESET = 2;
          public static final int EBUSY = 3;
          public static final int EADDRINUSE = 4;
          public static final int ETIMEDOUT = 5;
          public static final int EADDRNOTAVAIL = 6;
          public static final int EIO = 7;
          public static final int EPERM = 8;
          public static final int ENOENT = 9;
          public static final int ENODEV = 10;

        ENODEV for EIB_Cache_Read_Sync means GroupCache not enabled (neither via EIBD API nor via EIBD parameter).

        ENOENT for EIB_Cache_Read_Sync means no data available for the group address.
        This means:
        - No telegrams for the group address transmitted since the group cache was enabled the first time
        and
        - Group address is not readable (see Flags of the group object in the ETS)

         
    • Jan-Philipp Bolle

      Hello Martin,

      I read in your documentation but I think I still missing a little bit of the big puzzle.

      I first tested with the provided debian packages. But to make sure that the version I am using is compiled with the group cache I build a new version by my own (./configure --enable-ft12 --enable-groupcache).

      I started the eibd with “eibd -c -i -u ft12:/dev/ttyS0”. Then I tryed to use the vbusmonitor with "vbusmonitor1 local:/tmp/eib" . And I am not able to receive packages. If I use the “busmonitor1 local:/tmp/eib” with out the cache option I can see all messages for instance “…1.1.3 to 0/0/1 …”.
      I also tried to use the command “groupcachereadsync local:/tmp/eib 0/0/1” but it do not work.
      Before I search the problem in the javaprogram I think it is easier to get the commands working.

      In your post you write “Group address is not readable (see Flags of the group object in the ETS)”. But I don’t know what this could mean. I seared in the ets where I configured the group address but I can’t find any possibility to alow reading of the groupaddress.
      The only feature I found was reading the groupaddress in the groupmonitor of the ets.
      But if I read the group 0/0/1 via ets I get in the row “source” not found.
      Is this my problem?

      Thank you for the supported.
      Regards Philipp

       
      • Martin Koegler

        Martin Koegler - 2009-05-30

        Please check, that bcuaddrtab ft12:/dev/ttyS0 return zero. Else you need to change it with bcuaddrtab to zero.

         
    • Jan-Philipp Bolle

      Thank you Martin.
      Now it works.

      I can listen to one groupaddress but not to all groups. So far I understand the documentation if I listen to 0/0/0 I will receive all massages “Listening on group address 0/0/0 means that all group communication packets from the back end should be delivered.”.

      Then I tried to use the busmonitor in java (like it is you used it in vbusmonitor1.c) but I can’t get it to work.
                  Buffer b = new Buffer ();
                  EIBConnection c = new EIBConnection ("127.0.0.1");
                  c.EIBOpenVBusmonitorText();
                  System.out.println("busmonitor open");
                  while(true) {
                      int len = c.EIBGetBusmonitorPacket_async(b);
                      if (len == -1){
                          System.out.println("Read failed");
                      }
                      if (b.data != null){
                          System.out.println("read: "+b.data.length);
                      } else {
                          System.out.println("no data found");
                          Thread.currentThread().sleep(100);
                      }
                  }

      Any idea how to receive all messesage of the bus in Java?

       
      • Martin Koegler

        Martin Koegler - 2009-06-02

        You call a _async function. It only initatiates the remote call, you need to call EIBComplete to finish it (with maybe polling for completion in between).

        T_Group only allows communication with 1 group address. For communication with all group addresses, you need to use a group socket and the association send/receive function. My fist post should contain an example.

         
    • axele

      axele - 2009-07-27

      Hi Martin,

      I jump onto this thread as my current problem seems to be somewhat similar to what I read.
      I also have the problem, that I can write to a group address but not read from it. I tried the command "bcuaddrtab usb:2:2:1:0" and got the answer "Size: 1". As you wrote above, I tried to set the size to 0 with "bcuaddrtab -w 0 usb:2:2:1:0". But this command never returns and blocks the USB bus. I have to reboot. The environment I'm using is Kubuntu 9.04 running in a virtual Box on Windows Vista. The interface to EIB is a ALBRECHT JUNG KNX-USB Data Interface. Any issues you're aware with this configuration? And what is this command for?

      Btw. it works fine using the linux tools and also using the java eib client library as well as calimero as long as I do not try to read from a group address. Also monitoring the bus works fine using the eib client library on windows.

      Thanks und viele Grüße,
      Axel

       
      • Martin Koegler

        Martin Koegler - 2009-07-28

        My first guess is, that its a virtualbox problem, as you have to reboot and it blocks the USB bus. The usbfs interface should not (and does not as far as I know) any way to disturb the whole USB bus.
        I suggest to try this on a native linux installation. There should not be any problems.
        Jung 2130 USB R2 UP is on the HCL [http://bcusdk.wiki.sourceforge.net/SupportedHardware ; Other compilant USB interface will work too, but have not been tested].

        You can add -t1023 to the bcuaddrtab/eibd parameters, pipe the output into a file  and mail it to mkoegler@auto.tuwien.ac.at. I can look for something incorrect, but I doubt, that I will find anything.

         
    • axele

      axele - 2009-07-28

      Thanks Martin,

      your're exactly right. After several tries and reboots :-( I finally could write 0 with bcuaddrtab and start eibd again. Now I can read the group address - great!

      I'm still curious: What does it do and why is it initialized to 1 on my (and obviously others) devices? Can this functionality be included into the eibd itself? It would then be easier to automate the startup process.

      Axel

       
      • Martin Koegler

        Martin Koegler - 2009-07-29

        bcuaddrtab changes the programming of the interface device, so it is a seperate program. The user should remember the old setting and can it restore it via bcuaddrtab anytime he wants. An automatic solution could leave the user with a different configured device.

        The value control, how the device filters telegrams. 0 turn filtering off, while 1 (or bigger) are used for the normal BCU operation.

        On http://www.auto.tuwien.ac.at/~mkoegler/index.php/knxlive, you can download knxconfig_0.2.tar.gz. It includes a shell script (EIBD setup wizard). You can use it as for an example for the integration of eibd and bcuaddrtab. The shell script was written for a Live CD and grants permissions to any user on your system, so please check the code, before you run it on any valuable system.

         
    • axele

      axele - 2009-07-30

      Thanks for the info. This setup using a virtual machine is just for development and testing. The final setup will include a linux pc. I'll have a look at the shell scripts and try to adopt them.

      Do you know about an interface (usb or serial, I don't care) that a private acting person can afford? The commercial ones are quite expensive. If there is a kit available, I'm willing to get out my soldering iron from the drawer...

       
      • Martin Koegler

        Martin Koegler - 2009-07-31

        How much do you want to spend on an interface?

        https://sourceforge.net/apps/trac/bcusdk/wiki/SupportedHardware contains a list of all possibilities.

        If you want something cheap, you can look at the TPUART. TPUART and EIBD yields to a stable solution. Other clients (eg. ETS) can only connect via the EIBD EIBnet/IP server.

        The Siemens BTM costs about 30 €. You need an additional level convert (with/without galvanic isolation depending on your needs). MAX232 based solutions start at 10 € (without galvanic isolation). I remember post of such user on the bcusdk mailing list, so you could try to ask there for details.

        You can download all information necessary to built our TPUART board (which includes opto-couplers) from our website. The TPUART IC is sold by Opternus. The price for such a board will probably depend on your skills.

         
    • axele

      axele - 2009-08-03

      Looks promising.
      I'm using the startup script from the live CD now and everything works fine.

       

Log in to post a comment.