매초마다 ttyS1 포트의 전송 속도를 변경해야합니다. 그래서 내가 9600 Bauds에서 원격 머신을 깨우고 19200 Bauds에서 통신을해야합니다. 그러나 웨이크 업 신호와 실제 데이터 통신 사이에는 시간 제한이 있습니다. 나는이 트릭을 위해 Handler & Thread를 사용한다.매 입구마다 지연된 방법 변경
나는 그것을했는데 처리기로 괜찮은 것 같습니다 & 스레드. 나는 1 밀리 초와 500 밀리 초 동안 모든 입구를 연기 한 채 토글했다. 그러나 그것은 나쁘다. 때로는 1 밀리 초 작업에 거의 10-15 밀리 초가 걸릴 수 있습니다.
또한 나는 "runOnUiThread"를 몇 가지 UI 업데이트와 함께 추가하면 결과가 30milliseconds와 같이 최악의 상태가된다는 것을 알아 차렸습니다.
참고 : 한 번에 Wake-up 신호를 전송해야합니다.
아이디어가 있으십니까?
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;
}
};
를 사용하여 더 나을 것입니다. 그리고 많은 것들이 더. 그러나 같은 결과. 안드로이드는 어떤 작업에 대해서도 특정 시간 간격을 첨부하려고합니다. 그래서 시리얼 통신은 가변적 인 시간 간격을 필요로합니다. 또는 다른 UI 프로세스가 나쁜 영향을 미칠 수 있습니다. 나는 다른 MCU의 소스 코드를 변경할 기회가 없도록해야만한다. 그것은 또 다른 제품입니다. 감사 – babur