Skip to content

Commit

Permalink
added modbus_set_slave error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
v-zhuravlev committed Sep 24, 2018
1 parent 7dd939a commit b7eda07
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/modbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,12 @@ int zbx_modbus_read_registers(AGENT_REQUEST *request, AGENT_RESULT *result)
modbus_free(ctx);
return SYSINFO_RET_FAIL;
}
modbus_set_slave(ctx, slave_id);
if (modbus_set_slave(ctx, slave_id) == -1)
{
SET_MSG_RESULT(result, strdup("Check slaveid parameter"));
modbus_free(ctx);
return SYSINFO_RET_FAIL;
}

//<reg> set register to start from
errno = 0;
Expand Down
4 changes: 2 additions & 2 deletions tests/test_01modbus_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_bad_register_string(self, host):

def test_bad_slaveid_integer(self, host):
key = "modbus_read_registers["+host+",5000,99,3,uint32,BE,0]"
assert zabbix_get(key) == 'ZBX_NOTSUPPORTED: Illegal data address'
assert zabbix_get(key) == 'ZBX_NOTSUPPORTED: Check slaveid parameter'
def test_bad_slaveid_string(self, host):
key = "modbus_read_registers["+host+",bad,1,3,uint32,BE,0]"
assert zabbix_get(key) == 'ZBX_NOTSUPPORTED: Check slaveid parameter'
assert zabbix_get(key) == 'ZBX_NOTSUPPORTED: Check slaveid parameter'

0 comments on commit b7eda07

Please sign in to comment.