Page 1 of 1

Problem with getOutputState

Posted: Fri Jan 29, 2016 9:14 pm
by jsalo
I encountered the problem when I tried to do this.
I played with == 0, == 1, == false, etc.. nothing seems to work.

Code: Select all

if (CPhidgetInterfaceKit_getOutputState(ifKit, 0, 0) == true)


When I cout getOutputState it returns ' 4 ' everytime even if I setOutputState and cout again.

Code: Select all

cout << CPhidgetInterfaceKit_getOutputState(ifKit, 0, 0) << endl;


I have quite few years of phidget programming experience using C#.
Everything is working fine on C# side and im getting true/false return when i check output states.
I switched recently from C# to C++, Im not sure if I am missing something here, am I doing it wrong?

Thank you
J.Salo

Re: Problem with getOutputState

Posted: Sat Jan 30, 2016 6:21 am
by frodegill
jsalo wrote:When I cout getOutputState it returns ' 4 ' everytime even if I setOutputState and cout again.

Code: Select all

cout << CPhidgetInterfaceKit_getOutputState(ifKit, 0, 0) << endl;

4 is EPHIDGET_INVALIDARG. If you look in the documentation, third parameter is an int* for the output state, and you send nullptr.

Code: Select all

int state;
if (EPHIDGET_OK == CPhidgetInterfaceKit_getOutputState(ifKit, 0, &state))
{
  cout << PFALSE!=state << endl;
}

Re: Problem with getOutputState

Posted: Sat Jan 30, 2016 10:00 am
by jsalo
Thank you, I got it working.

Re: Problem with getOutputState

Posted: Sat Jan 30, 2016 2:09 pm
by jsalo
I now face another problem. Im trying to get and set the output state in a loop.

Code: Select all

      for (i = 0; i < input_buffer.size(); i++)
      {
         CPhidgetInterfaceKit_getOutputState(ifKit, input_buffer[i].output, &output_state);

         if (output_state == 1)
         {
            CPhidgetInterfaceKit_setOutputState(ifKit, input_buffer[i].output, 0);
            // Do more stuff here
         }
      }   


It does not seem to update fast enough. If I set the outputState, the next iteration will still return the old value. Is my only option to abandon the getOutputState and keep my own record of output/input states.

Re: Problem with getOutputState

Posted: Sat Jan 30, 2016 2:27 pm
by frodegill
jsalo wrote:I now face another problem. Im trying to get and set the output state in a loop.
<snip code>
It does not seem to update fast enough. If I set the outputState, the next iteration will still return the old value. Is my only option to abandon the getOutputState and keep my own record of output/input states.

Yes, there is a delay (Phidgets guys can probably tell you exactly how many ms. Documentation only says "Reading the OutputState immediately after setting it will not return the value set - it will return the last state reported by the Phidget.", and the safe way is probably to wait for CPhidgetInterfaceKit_set_OnOutputChange_Handler callback), but for outputState you should keep record of state yourself anyhow - to be able to set them correctly after a IO board disconnect/reconnect (in which Phidgets forgets the outputStates)

Re: Problem with getOutputState

Posted: Sat Jan 30, 2016 2:34 pm
by jsalo
Ok, thank you for your fast reply again. Im going to implement somekind of list of output states so i can keep my own record of them.

Re: Problem with getOutputState

Posted: Mon Feb 01, 2016 8:17 am
by burley
The delay depends on the data rate you have set but the minimum would be 8ms.