【问题标题】:How to use queue at retrofit如何在改造时使用队列
【发布时间】:2015-07-23 21:45:17
【问题描述】:

我的 PHP 服务器脚本通过 RS232 连接到硬件,因此只有一个请求会给出有效的反馈。如何确保一次只发送一个请求,例如队列?

一个 Timer 调用了这两个函数,所以我在服务器站点上看到了 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(); }
}

【问题讨论】:

    标签: php android retrofit


    【解决方案1】:

    这不可能通过改造而不是正确的方式。

    解决方案是编写一个通过 RS232 进行通信的单一后台应用程序,通过 memcached 获取命令变量。 memcached 由一个可到达的 php 组件读写。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-22
      • 2019-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-25
      • 2013-06-30
      • 1970-01-01
      相关资源
      最近更新 更多