C
C
Chvalov2015-08-27 16:16:47
Java
Chvalov, 2015-08-27 16:16:47

Connection settings are not set at startup in Physicaloid, what's the problem?

There is a code that, when switching to a RadioButton, assigns different values ​​​​to the driver:

rgBaudrate.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                case R.id.rb0:
                    mPhysicaloid.setBaudrate(9600);
                    break;

                case R.id.rb1:
                    UartConfig uartConfig = new UartConfig(19200, UartConfig.DATA_BITS8, UartConfig.STOP_BITS1, UartConfig.PARITY_NONE, false, false);
                    mPhysicaloid.setConfig(uartConfig);
                    break;

                default:
                    tvAppend(tvRead, "no set");
                    break;
                }
            }
        });

Here is the full code : GITHUB
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tutorial5);

        btOpen  = (Button) findViewById(R.id.btOpen);
        btClose = (Button) findViewById(R.id.btClose);
        btWrite = (Button) findViewById(R.id.btWrite);
        etWrite = (EditText) findViewById(R.id.etWrite);
        tvRead  = (TextView) findViewById(R.id.tvRead);
        rgBaudrate = (RadioGroup) findViewById(R.id.rgBaudrate);
        rb0 = (RadioButton) findViewById(R.id.rb0);
        rb1 = (RadioButton) findViewById(R.id.rb1);

        setEnabledUi(false);

        mPhysicaloid = new Physicaloid(this);

    UartConfig uartConfig = new UartConfig(19200, UartConfig.DATA_BITS8, UartConfig.STOP_BITS1, UartConfig.PARITY_NONE, false, false);
    mPhysicaloid.setConfig(uartConfig);

How can I make this code work when the application starts?
UartConfig uartConfig = new UartConfig(19200, UartConfig.DATA_BITS8, UartConfig.STOP_BITS1, UartConfig.PARITY_NONE, false, false);
    mPhysicaloid.setConfig(uartConfig);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Bolshakov, 2015-08-27
@Chvalov

Can be configured before the first USB access in the openDevice() method ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question