我无法使用Jamod android连接服务器

时间:2019-12-02 11:34:39

标签: java android

早上好,我不确定,我正在使用智能手机的锁定库,正在与PLC通讯,但是当您建立连接时,它无法连接,也不知道自从我每次以来的错误单击单选按钮,是的,如果他不连接并且无论何时不讲话,他都会这样做,有人可以帮我吗?

private TCPMasterConnection con = null;
private ModbusTCPTransaction trans = null;
private ReadCoilsRequest rcreq=null;
private ReadCoilsResponse rcres=null;
private InetAddress addr = null;
private int port = Modbus.DEFAULT_PORT;
private byte byteArray[]={(byte)192, (byte)168, (byte)0, (byte)182};




private RadioGroup radioGroup;
private Button buttonAction;
private TextView depurar;



@RequiresApi(api = Build.VERSION_CODES.M)
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_principal);

    radioGroup = findViewById(R.id.radioGroup);
    buttonAction = findViewById(R.id.buttonAction);
    depurar =  findViewById(R.id.textViewD);


    checkRadioButotn();


    buttonAction.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {



        }
    });


}


public void checkRadioButotn(){

    radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int i) {

            if (i == R.id.radioButtonYes ){

                try {

                    //IP address;
                    addr = InetAddress.getByName("192.168.8.87");
                    // Open the connection
                    con = new TCPMasterConnection(addr);
                    con.setPort(502);
                    con.connect();
                    rcreq = new ReadCoilsRequest(02001, 2);
                    trans = new ModbusTCPTransaction(con);
                    trans.setRequest(rcreq);
                    trans.execute();
                    rcres = (ReadCoilsResponse) trans.getResponse();
                    if (con.isConnected()) {
                        depurar.setText("conecta");
                    }


                } catch (Exception e) {
                    Log.d("MODBUS", "connection error");
                    depurar.setText("no conecta");
                    con.close();
                }





            } else if (i == R.id.radioButtonNo){

            } else if (i == R.id.radioButtonThanks){

            } else  if (i == R.id.radioButtonCheers){

            }

        }
    });





}

0 个答案:

没有答案