Skip to content

xarm_set_effector_modbus_rtu_cmd

1. Introduction

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

2. Request & Response

Message

json
{
    "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"
}

Request

NameTypeRequired fieldsDescription
isloopboolNowhether to send Modbus commands cyclically.
mdb_infoArrayYes

command information. For example: [{'checked': True, 'note': {'cn':'','en': ''},'delay':'','cmd':'00 01 00 02'}]

('checked'- whether check the format is correct or not;'note'-{'cn':'','en': ''}'delay'-delay time'cmd'-modbus command)

end_fmvStringYesThe firmware version of end IO board, e.g.‘2.5.9’
buadrateintYesmodbus baud rate(4800-2500000)
is_stopintNowheter to stop sending the command
host_idintYes

Host ID.

11: linear motor

10: controller 485

9: tool end 485

Response

code=0->success;
code!=0->Failed, refer to xarm_api_code;

3. Code Example

background

python
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

javascript
self.setEffectorModbusCmd = (datacallbackhost_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);
    }
  });
}