returning data from a cog
Bits
Posts: 414
I am trying to return data from a cog but want to get it in one operation so to speak.
Here is what I normally end up doing.
Now what I would love to do is return all 3 data in one call, something like this below.
Here is what I normally end up doing.
Pub Get_spectrometer Return spectrometer Pub Get_polarization Return polarization Pub Get_phase velocity Return phase velocity
Now what I would love to do is return all 3 data in one call, something like this below.
Pub Get_machine Return spectrometer & polarization & phase velocity
Comments
return spectrometer << 16 | polarization << 8 | phase_velocity
If your variables are bigger the only way is to pass an address of a value buffer and let the get-function directly write it to these variables:
If the variables are in the same *.SPIN-file there is no need at all to return the values, because all parts of this SPIN-file have access to those variables.
As noted the only way to return multiple values or complex structures is to pass the address of said structure to the method, have it fill in the results based on that pointer and then return.
Now this all applies equally well when the Spin method is running in another COG. But in that case, lets assume the COG runs forever, you also have to include something in that data structure that indicates when the result is ready and available. Perhaps one LONG is used as a command to "doSomething" with the data. That command may then be set to "doneSomething" when the COG has written the results back.