readRegister function undefined when used in GUIDE

1 visualización (últimos 30 días)
Hi All,
I'm a hobbyist attempting to create a basic gui that will sample data from an I2C based current sensor that is attached to my raspberry pi. I have written and successfully tested a class that correctly samples this data when run via a standard Matlab Script. However, when I attempt to code this into a gui, I get the following error message when I try to call the readRegister function:
Undefined function 'readRegister' for input arguments of type 'double'.
From doing research, I believe that matlab somehow cannot locate the readRegister function when called from the gui. This confuses me since the function easily runs if I simply call it from the command line, for example this works outside of the gui:
config_values = readRegister(sensor.i2cLink,register_address,'uint8',2);
where sensor.i2cLink and register_address are specifically defined (and verified to exist when debugging).
Does anyone know of a work around to this?

Respuesta aceptada

Walter Roberson
Walter Roberson el 24 de Abr. de 2019
readRegister requires an object of class device but inside your GUI you are instead passing it an object of class double. In particular you should check sensor.i2cLink to see if it is [], the empty array, such as if the link configuration had not been done yet or had failed.
  1 comentario
Christopher Gates
Christopher Gates el 24 de Abr. de 2019
You were right (and saved my evening). My i2cLink variable had been defined but wasn't being passed correctly from one function to another so it was cleared to []
Thank you for your help!

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by