Problem with getOutputState

C, C++, and Visual C++
jsalo
Fresh meat
Posts: 4
Joined: Fri Jan 29, 2016 8:29 pm
Contact:

Problem with getOutputState

Postby jsalo » Fri Jan 29, 2016 9:14 pm

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

frodegill
Phidget Mastermind
Posts: 114
Joined: Thu Mar 04, 2010 2:51 am
Contact:

Re: Problem with getOutputState

Postby frodegill » Sat Jan 30, 2016 6:21 am

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;
}

jsalo
Fresh meat
Posts: 4
Joined: Fri Jan 29, 2016 8:29 pm
Contact:

Re: Problem with getOutputState

Postby jsalo » Sat Jan 30, 2016 10:00 am

Thank you, I got it working.

jsalo
Fresh meat
Posts: 4
Joined: Fri Jan 29, 2016 8:29 pm
Contact:

Re: Problem with getOutputState

Postby jsalo » Sat Jan 30, 2016 2:09 pm

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.

frodegill
Phidget Mastermind
Posts: 114
Joined: Thu Mar 04, 2010 2:51 am
Contact:

Re: Problem with getOutputState

Postby frodegill » Sat Jan 30, 2016 2:27 pm

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)

jsalo
Fresh meat
Posts: 4
Joined: Fri Jan 29, 2016 8:29 pm
Contact:

Re: Problem with getOutputState

Postby jsalo » Sat Jan 30, 2016 2:34 pm

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.

User avatar
burley
Human-Cyborg Relations
Posts: 438
Joined: Tue Sep 27, 2011 2:37 pm
Location: Calgary
Contact:

Re: Problem with getOutputState

Postby burley » Mon Feb 01, 2016 8:17 am

The delay depends on the data rate you have set but the minimum would be 8ms.
Brian Burley
403-282-7335 ext. 6003
support@phidgets.com


Return to “C/C++”

Who is online

Users browsing this forum: No registered users and 1 guest