What do you mean by “returns nothing”? Did you mean it returns 0? In C, if a non-void function ever returns then it will return some value.
The Maestro’s Get Position command is two bytes (0x90 and channel) but you are not doing anything to guarantee that the command gets sent because you are not checking the return value of the write() function.
The Maestro’s Get Position command results in a two-byte response but you are not doing anything to guarantee that your program actually reads both bytes. For example, if read() returns 1 then it means that you have only succeeded in reading one byte from the Maestro, but your function will return anyway.
You did not post a complete program so it is hard to tell what options are enabled on the port. If the O_NONBLOCK option is enabled, then these issues can definitely cause you problems because you could read/write too little data.
Does your code run in Linux or Windows? It looks like Linux, please see this:
The only thing I would add to that example is that you should make sure the ONLCR and OCRNL options are disabled by adding this line of code right before tcsetattr:
options.c_oflag &= ~(ONLCR | OCRNL);
If it actually is Windows, see this example code:
–David
