xarm_set_effector_modbus_rtu_cmd

1. Introduction

Send Modbus RTU command.

Button: [Settings] - [Externals] - [Modbus RTU] - Send.

2. Request & Response

```
{
    "cmd": "xarm_set_effector_modbus_rtu_cmd",
    "data": {
        "is_loop": false,
       "mdb_info": [
{"checked": true, "note": {"cn": "", "en": ""}, "delay": "1000", "cmd": "08 10 01 00 00 01 02 00 01"}
],
        "end_fmv": "2.6.0",
        "baudrate": 115200,
        "is_stop": true,
        "host_id": 9
    },
    "id": "1"
}
```

3. Code Example

background

if info_dic.get('checked', False):
    try:
        response(client, cmd_id, code=100)
        if cmd and is_run:
            cmd_li = re.sub(',', ' ', cmd)
            cmd_li = re.sub(' +', ' ', cmd_li)
            cmd_li = cmd_li.strip().split(' ')
            int_li = [int(da, 16) for da in cmd_li]
            send_time = ''.join(str(datetime.now())[11:23])
            host_id = data.get('host_id', 9)
            code, ret = GLOBAL.XArm.xarm.getset_tgpio_modbus_data(int_li, host_id=host_id)
            recv_time = ''.join(str(datetime.now())[11:23])
            if code == 0 and ret:
                recv = ''
                for da in ret:
                    re1 = hex(da)[2:]
                    if len(re1) == 1:
                        re1 = '0' + re1
                    recv = recv + ' ' + re1
                    recv = recv.upper()
                response(client, cmd_id, code,
                         {'recv': recv, 'send': cmd, 'send_time': send_time, 'recv_time': recv_time})
            else:
                return response(client, cmd_id, 1, {'send': cmd, })
    except Exception as e:
        logger.error(e)
        return response(client, cmd_id, 1, {'send': cmd, })

front_end

self.setEffectorModbusCmd = (data, callback, host_id) => {
  const params = window.GlobalConstant.INIT_CMD_PARAMS_COMMON_DATA();
  Object.assign(params.data, data, {
    host_id: host_id,
  });
  self.sendCmd(window.GlobalConstant.SET_MODBUS_EFFECTOR_RTU_CMD, params, (dict) => {
    if (callback) {
      callback(dict);
    }
  });
} 

Last updated