0

ttyS1ポートのボーレートを毎秒変更する必要があります。したがって、9600ボーでリモートマシンをウェイクアップし、19200ボーで通信した後、リモートマシンをウェイクアップする必要があります。ただし、ウェイクアップ信号と実際のデータ通信の間には時間制限があります。このトリックにはHandler&Threadを使用します。

私はそれを行い、Handler&Threadで問題ないようです。1ミリ秒と500ミリ秒の間、すべての入口の遅延後を切り替えました。しかし、それはうまくいきません。1ミリ秒のタスクには、ほぼ10〜15ミリ秒かかる場合があります。

また、UIを更新して「runOnUiThread」を追加すると、結果が30ミリ秒のように最悪になることに気付きました。

注:ウェイクアップ信号を1回だけでなく、毎回送信する必要があります。

何か案が?

public void serial_query(){
    try {
        Runnable cookimageupdate = new Runnable(){
            public void run(){
                            try {
                                if (mOutputStream != null) {
                                    mSerialPort.close();

                                    if (mLAP==0) //First LAP is used to HOLTEK Wake-Up.  Second one is real data.
                                            {mLAP=1; mSerialPort=new SerialPort(new File("/dev/ttyS1"), 9600, 0); mBufferbuf = (byte)0x00; mOutputStream.write(mBufferbuf);}
                                    else    {mLAP=0; mSerialPort=new SerialPort(new File("/dev/ttyS1"), 19200, 0); mOutputStream.write(mBuffer);}


                                } else {
                                        return;
                                }
                        } catch (IOException e) {
                                e.printStackTrace();
                                return;
                        }
                            try{
                                runOnUiThread(new Runnable() {
                                       public void run() {

                                               //meat_temp.setText(_meatprobe_temp.toString());
                                               if (_pt1000_status==1) {pt_status.setText("   PT1000 open-circuit");}
                                               else if (_pt1000_status==2){pt_status.setText("   PT1000 short-circuit");}
                                               else if (_pt1000_status==0){pt_status.setText("   -");}
                                       }
                               });

                               }
                            catch (Exception e)
                            {
                               e.getLocalizedMessage();
                            }

                         if (mLAP==1) 
                                {handler_serial.postDelayed(this, 1);}
                        else    {handler_serial.postDelayed(this, 500);}
            }
        };
        handler_serial.postDelayed(cookimageupdate, 50);    //start with 50mSec. delay
    }
    catch(Exception e){
        e.printStackTrace();
        return;
    }
};
4

1 に答える 1

0

遅延したランナブルをポストするには、1 ミリ秒は短すぎます。ほとんどのハンドラーは、メッセージの処理にそれよりも時間がかかります。

このような低遅延の場合は、使用する方がよいでしょう

Thread.sleep().
于 2012-08-17T07:16:29.017 に答える