-1
我的PHP服務器腳本通過RS232連接到硬件,因此只有一個請求會提供有效的反饋。我如何確保一次只能發送一個請求,如隊列?如何在改造中使用隊列
定時器調用這兩個函數,所以我在服務器站點2上看到同時發生的請求。
private void deviceGetActualVolume() {
if (isOnline()) {
RestAdapter adapter = new RestAdapter.Builder()
//.setLogLevel(RestAdapter.LogLevel.FULL)
.setEndpoint(deviceIp)
.build();
deviceAPI api = adapter.create(deviceAPI.class);
api.GetActualVolume(new Callback<deviceResponse>() {
@Override
public void success(deviceResponse device_response, Response response) {
if (!device_response.isOk()) {
Toast.makeText(MainActivity.this, "Command Error", Toast.LENGTH_LONG).show();
} else {
UpdateActualValue(0, device_response.getActualvolume());
}
}
@Override
public void failure(RetrofitError retrofitError) { Toast.makeText(MainActivity.this, "deviceGetActualVolume Failure", Toast.LENGTH_LONG).show(); }
});
} else { Toast.makeText(MainActivity.this, getString(R.string.notconnected), Toast.LENGTH_LONG).show(); }
}
private void deviceGetScale() {
if (isOnline()) {
RestAdapter adapter = new RestAdapter.Builder()
//.setLogLevel(RestAdapter.LogLevel.FULL)
.setEndpoint(deviceIp)
.build();
deviceAPI api = adapter.create(deviceAPI.class);
api.GetScaleValue(new Callback<deviceResponse>() {
@Override
public void success(deviceResponse device_response, Response response) {
if (!device_response.isOk()) {
Toast.makeText(MainActivity.this, "Command Error", Toast.LENGTH_LONG).show();
} else {
UpdateScaleValue(device_response.getScale());
}
}
@Override
public void failure(RetrofitError retrofitError) {
Toast.makeText(MainActivity.this, "deviceGetScale Failure", Toast.LENGTH_LONG).show();
}
});
} else { Toast.makeText(MainActivity.this, getString(R.string.notconnected), Toast.LENGTH_LONG).show(); }
}