2012-12-01 52 views
1

我在Java中为Android编写了这个简单的代码,以通过以太网(WiFi)连接到KNX总线。不幸的是没有工作Android上的Calimero knx api停止工作

public class MainActivity extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.activity_main, menu); 
    return true; 
} 

@Override 
protected void onStart() { 

    super.onStart(); 
    /*Pokus pro spojeni*/ 
    setContentView(R.layout.activity_main); 
    Button actButton = (Button) findViewById(R.id.button1); 
    int a=1; 
    actButton.setText("1234" + Integer.toString(a)); 
    new NewComm().execute("Sending....."); 
    Log.i ("MyTag","Starting....."); 
    } 
} 

final class NewComm extends AsyncTask<String, Void, Void>{ 

@Override 
protected Void doInBackground(String... text) { 

      String Enable = "Enalbe"; 
    String Disable = "Disable"; 
    String Address = "1/5/217"; 
    final CEMI_Connection tunnel; 
    try { 
     /* Create a new connection using CEMI_Connection 
     * to KNXnet/IP interface (in this case the ip 
     * 192.168.1.3), with the default port 
     */ 

     System.out.println("vsm> Connecting....."); 
     tunnel = new CEMI_Connection(
       new InetSocketAddress("192.168.0.110", 
         EIBNETIP_Constants.EIBNETIP_PORT_NUMBER), 
         new TunnellingConnectionType()); 

     /* Just saying that it connected. In case of an error, 
     *    
     *    
     * this is not executed, so you know it was unable to connect 
     */ 
     System.out.println("Connected."); 
     /* Create the knx device (a port from a relay for example)    
     * and declare it as a boolean device, and it's a Enable/Disable    
     * device. In the API docs there are all kinds avaliable 
     */ 

     PointPDUXlator object = PDUXlatorList.getPointPDUXlator(
       PDUXlatorList.TYPE_BOOLEAN[0], 
       PointPDUXlator_Boolean.DPT_ENABLE[0]); 

     /* Declare that we are going to write some info in the "Address" 
     *    * and this info is writed in the string Enable. To disable just 
     *       * change the variable    
     */ 

     object.setServiceType(PointPDUXlator.A_GROUPVALUE_WRITE);    
     object.setASDUfromString(Enable); 

     /* Create the message to be sent to device 
     * The device KNX address was declared in the begining 
     */ 

     CEMI_L_DATA message = new CEMI_L_DATA(
       CEMI_L_DATA.MC_L_DATAREQ, 
       new EIB_Address(), 
       new EIB_Address(Address), 
       object.getAPDUByteArray()); 
     /* Send the message using the connection "tunnel" 
     */    
     tunnel.sendFrame(message, CEMI_Connection.WAIT_FOR_CONFIRM); 

     /* Print that the message was sent 
     */ 
     System.out.println("Message Sent to " + Address + ": " + Enable); 

     /* Disconnect from the device and print it to the screen    
     * If your device can handle more than 1 Tunneling connection you    
     * can let it connected, but in my case I use different devices    
     * to control it, so I always have to disconnect after doing 
     * anything    
     */ 

     tunnel.disconnect(null); 
     System.out.println("Disconnected."); 
     }  catch (EICLException ex) { 
       ex.printStackTrace(); 
       System.out.println("vsm> Connection exception! "+ex.getMessage()); 
        } // connection error 
    return null; 

} 


} 

此代码无法在我的android手机上运行。如果我运行它,该程序失败,并在我的android手机上显示消息“应用程序停止工作....”。但在PC上,类似的代码(doInBackground()的内容)工作良好。正常工作意味着我能够在另一台计算机上接收KNX连接UDP数据包。

在Android设备上,我可以通过wifi发送简单的UDP数据包 - 这意味着WiFi连接和Android Java中的基本代码正在工作。

任何人都可以经历检查我的代码,并给我一个建议,问题在哪里? calimero API使用正确的代码的一部分?这对我有所帮助。 Calimero API可以在Android操作系统中工作吗?有没有人有过这方面的经验(我认为是这样,根据论坛上的帖子)。

logcat的内容:

12-01 07:48:03.452: E/dalvikvm(15234): Could not find class 'tuwien.auto.eicl.CEMI_Connection', referenced from method com.example.testapp.NewComm.doInBackground 

12-01 07:48:03.452: W/dalvikvm(15234): VFY: unable to resolve new-instance 550 (Ltuwien/auto/eicl/CEMI_Connection;) in Lcom/example/testapp/NewComm; 

12-01 07:48:03.452: D/dalvikvm(15234): VFY: replacing opcode 0x22 at 0x000e 

12-01 07:48:03.452: W/dalvikvm(15234): VFY: unable to resolve exception class 555 
(Ltuwien/auto/eicl/util/EICLException;) 

12-01 07:48:03.452: W/dalvikvm(15234): VFY: unable to find exception handler at addr 0x80 

12-01 07:48:03.452: W/dalvikvm(15234): VFY: rejected Lcom/example/testapp/NewComm;.doInBackground ([Ljava/lang/String;)Ljava/lang/Void; 

12-01 07:48:03.452: W/dalvikvm(15234): VFY: rejecting opcode 0x0d at 0x0080 

12-01 07:48:03.452: W/dalvikvm(15234): VFY: rejected Lcom/example/testapp/NewComm;.doInBackground ([Ljava/lang/String;)Ljava/lang/Void; 

12-01 07:48:03.462: W/dalvikvm(15234): Verifier rejected class Lcom/example/testapp/NewComm; 

12-01 07:48:03.462: D/AndroidRuntime(15234): Shutting down VM 
12-01 07:48:03.462: W/dalvikvm(15234): threadid=1: thread exiting with uncaught exception (group=0x40a95228) 

12-01 07:48:03.472: E/AndroidRuntime(15234): FATAL EXCEPTION: main 

12-01 07:48:03.472: E/AndroidRuntime(15234): java.lang.VerifyError: com/example/testapp/NewComm 

12-01 07:48:03.472: E/AndroidRuntime(15234): at com.example.testapp.MainActivity.onStart(MainActivity.java:48) 

12-01 07:48:03.472: E/AndroidRuntime(15234): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1195) 

12-01 07:48:03.472: E/AndroidRuntime(15234): at android.app.Activity.performStart(Activity.java:4548) 

12-01 07:48:03.472: E/AndroidRuntime(15234): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2178) 

12-01 07:48:03.472: E/AndroidRuntime(15234): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2240) 

12-01 07:48:03.472: E/AndroidRuntime(15234): at android.app.ActivityThread.access$600(ActivityThread.java:139) 

12-01 07:48:03.472: E/AndroidRuntime(15234): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262) 

12-01 07:48:03.472: E/AndroidRuntime(15234): at android.os.Handler.dispatchMessage(Handler.java:99) 

12-01 07:48:03.472: E/AndroidRuntime(15234): at android.os.Looper.loop(Looper.java:156) 

12-01 07:48:03.472: E/AndroidRuntime(15234): at android.app.ActivityThread.main(ActivityThread.java:4977) 

12-01 07:48:03.472: E/AndroidRuntime(15234): at java.lang.reflect.Method.invokeNative(Native Method) 

12-01 07:48:03.472: E/AndroidRuntime(15234): at java.lang.reflect.Method.invoke(Method.java:511) 

12-01 07:48:03.472: E/AndroidRuntime(15234): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 

12-01 07:48:03.472: E/AndroidRuntime(15234): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 

12-01 07:48:03.472: E/AndroidRuntime(15234): at dalvik.system.NativeStart.main(Native Method) 
+0

我尝试了一些调试尝试,错误发生在“新的TunnellingConnectionType()“。 – vsm

回答

1

同样的问题发生在我身边。你需要检查你导入到项目中的jar文件,你可以这样做: YourProjectName(右键单击) - > Properties - > Java BuildPath - > Order and export