Android简单案例


package com.ge6.newland.ge6;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.nle.mylibrary.enums.led.PlayType;
import com.nle.mylibrary.enums.led.ShowSpeed;
import com.nle.mylibrary.forUse.led.LedListener;
import com.nle.mylibrary.forUse.led.LedScreen;
import com.nle.mylibrary.forUse.rfid.RFID;
import com.nle.mylibrary.forUse.rfid.SingleEpcListener;
import com.nle.mylibrary.forUse.zigbee.ZigBee;
import com.nle.mylibrary.transfer.ConnectResultListener;
import com.nle.mylibrary.transfer.DataBusFactory;

public class RfidActivity extends AppCompatActivity {
    RFID rfid;
    ZigBee zigbee;
    TextView rfidData;
    LedScreen ledScreen;
    Double tem;
    TextView temp;
    Button button;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rfid);
        temp = findViewById(R.id.temp);
        button = findViewById(R.id.send);

        zigbee = new ZigBee(DataBusFactory.newSocketDataBus("192.168.2.15", 6001), null);
        ledScreen = new LedScreen(DataBusFactory.newSocketDataBus("192.168.2.15", 6002), null);


        Toast.makeText(getApplicationContext(), "ledScreen:" + ledScreen.openSuccess(), Toast.LENGTH_LONG).show();


        new Thread(() -> {
            while(true){
                try {
                    Thread.sleep(5000);
                    double[] val=zigbee.getFourEnter();
                    tem = val[3];
                    Log.d("tem",tem+"");
                    runOnUiThread(() -> temp.setText(tem+""));
                    ledsend(tem+"");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();

        button.setOnClickListener(view -> ledsend("222"));
    }

    public void ledsend(String string){
        try{

            ledScreen.sendTxt(string, PlayType.LEFT, ShowSpeed.SPEED3, 1, 100, new LedListener() {
                @Override
                public void onSuccess(boolean b) {
                    Log.d("LED","1");
                }

                @Override
                public void onFail(Exception e) {
                    Log.d("LED","2");
                }
            });
        }
        catch (Exception e){

        }
    }

}

原创文章,作者:dweifng,如若转载,请注明出处:https://blog.ytso.com/274326.html

(0)
上一篇 2022年7月14日
下一篇 2022年7月14日

相关推荐

发表回复

登录后才能评论