1

イーサネット (WiFi) 経由で KNX バスに接続するために、Android 用の Java でこの単純なコードを作成しました。残念ながら機能していません

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 OS で動作しますか? 誰もそれを経験したことがありますか(ここのフォーラムの投稿によると、私はそう思います)。

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)
4

1 に答える 1

1

同じ問題が発生しました。プロジェクトにインポートした jar ファイルを確認する必要があります。次から実行できます: YourProjectName (右クリック) -> Properties -> Java BuildPath -> Order and export

于 2013-03-25T14:11:04.293 に答える