示例#1
0
BLOCK_STATUS *ModBusTCP::ReportSlaveID(quint8 slave)
{

    uint8_t dest[10];
    int rc;
    BLOCK_STATUS *st = new BLOCK_STATUS;

    modbus_set_slave(ctx, slave);

    rc = modbus_report_slave_id(ctx, dest);

    qDebug() << "RC: " << rc;

    if (rc != -1)
    {



        st -> rstatus = true;
        if (dest[0]) st -> status = true;
        else st -> status = false;

        st -> SoftVersion = dest[1];
        st -> HardVersion = dest[2];

    } else
    {
        st -> rstatus = false;
    }


    return st;
}
示例#2
0
static int ctx_report_slave_id(lua_State *L)
{
	ctx_t *ctx = ctx_check(L, 1);

	uint8_t *buf = malloc(ctx->max_len);
	assert(buf);
#if LIBMODBUS_VERSION_CHECK(3,1,0)
	int rc = modbus_report_slave_id(ctx->modbus, ctx->max_len, buf);
#else
	int rc = modbus_report_slave_id(ctx->modbus, buf);
#endif
	if (rc < 0) {
		return libmodbus_rc_to_nil_error(L, rc, 0);
	}

	lua_pushlstring(L, (char *)buf, rc);
	return 1;
}
int report_slave_ID(){
    uint8_t slaveresponse_bytes[MODBUS_MAX_PDU_LENGTH];
    int rc;

    rc = modbus_report_slave_id(ctx, MODBUS_MAX_PDU_LENGTH, slaveresponse_bytes);
    if (rc > 1) {
        printf("Run Status Indicator: %s\n", slaveresponse_bytes[1] ? "ON" : "OFF");
    }
    return 1;
}