Page 1 of 1

Property readonly

Posted: Sun Nov 30, 2008 6:11 am
by DsA
How to prohibit editing of property by the user in Device Plugin?

Re: Property readonly

Posted: Sun Nov 30, 2008 9:03 am
by ScottBot
If you are creating your own Device using the SDK, set the 'eIOType ioType' parameter of the 'pHB_RegisterDeviceProperty' call to 'ioInputOnly'.

Re: Property readonly

Posted: Sun Nov 30, 2008 10:11 am
by DsA
Thanks. Still a question. How to set restriction of entered values, for example from 0 to 100?

Re: Property readonly

Posted: Sun Nov 30, 2008 12:59 pm
by ScottBot
If you have derived a class from the CHardwareInterface class, you just need to call

Code: Select all

CHardwareInstance::SetPropertyLimits( const char* szPropertyName, int nLowLimit, int nHighLimit )
or pHB_SetPropertyLimits if not using CHardwareInterface. Call it right after you register the Property (RegisterHardwareModuleProperty).

Re: Property readonly

Posted: Mon Dec 01, 2008 5:41 pm
by DsA
It in Hardware Interface Plugin. I have not found the same function in Device Plugin?

Re: Property readonly

Posted: Mon Dec 01, 2008 9:54 pm
by ScottBot
DsA wrote:It in Hardware Interface Plugin. I have not found the same function in Device Plugin?
You're right. Sorry I was confused.

You can't restrict what a user will enter for a Property Value. The best you can do is to offer suggestions by associating Property Values to a Property by calling pHB_CreateDevicePropertyValue() when registering a new Property for the first time.

You can still generate an error or just refuse to change the Device Property in the plugin if the user tries to change the Property to an invalid value.

Re: Property readonly

Posted: Tue Dec 02, 2008 5:15 am
by DsA
I create properties calling pHB_CreateDevicePropertyValue () but how thus to set values of properties? It is possible a code example?

Re: Property readonly

Posted: Tue Dec 02, 2008 9:06 am
by ScottBot
Here's a snippet from the ::RegisterProperties() method of a Device plugin.

Code: Select all

// First attempt to register the Property (wizard version of registration that has prompt)
if (!m_CallBackInfo.pHB_RegisterDevicePropertyUsingWizard( m_CallBackInfo.m_hModuleHandle, 
                                                           nDeviceNumber, 
                                                           "Insteon Group", 
                                                           "Group", FALSE, 
                                                           "1", 
                                                           ioInputAndOutput, 
                                                           TRUE, 
                                                           TRUE, 
                                                           FALSE, 
                                                           FALSE, 
                                                           "Enter the group number" ))
{
   // The registration failed.  This is probably because this is the first time the property is being registered.
   // Attempt to create the new "Insteon Group" Property.
   if (!m_CallBackInfo.pHB_CreateDeviceProperty( "Insteon Group", "Group", ptNumeric ))
      return( FALSE );

   // The Property created successfully.  We can optionally add values to the Property.
   // This example creates numeric values from 1 to 256
   m_CallBackInfo.pHB_CreateDevicePropertyValue( "Insteon Group", "[1 - 256]" );

   // If not adding a sequential numeric range like above, call pHB_CreateDevicePropertyValue() for
   // each value to be added to the Property.
//   m_CallBackInfo.pHB_CreateDevicePropertyValue( "Insteon Group", "1" );
//   m_CallBackInfo.pHB_CreateDevicePropertyValue( "Insteon Group", "2" );
//   m_CallBackInfo.pHB_CreateDevicePropertyValue( "Insteon Group", "3" );
                                             
   // Now that the Property has been created, we can try and register it again (same call as at the top)          
   if (!m_CallBackInfo.pHB_RegisterDevicePropertyUsingWizard( m_CallBackInfo.m_hModuleHandle, 
                                                              nDeviceNumber, 
                                                              "Insteon Group", 
                                                              "Group", 
                                                              FALSE, 
                                                              "1", 
                                                              ioInputAndOutput, 
                                                              TRUE, 
                                                              TRUE, 
                                                              FALSE, 
                                                              FALSE, 
                                                              "Enter the group number" ))
      return( FALSE );
}

Re: Property readonly

Posted: Thu Dec 04, 2008 5:32 am
by DsA
I thank, all works =)

Re: Property readonly

Posted: Thu Jan 08, 2009 7:02 pm
by vc1234
I've attached a dll with the read-only Temperature property (ioInputOnly). I believe the device has to be recreated for ioInputOnly (should it not be rather called ioOutputOnly ?) to take effect.

Re: Property readonly

Posted: Mon Jun 22, 2009 10:28 pm
by EdInNY
Scott,

Just an FYI;
The comments in DeviceAPI.h say "ioType - Not currently used, but can/should be set correctly."

- Ed

Re: Property readonly

Posted: Tue Jun 23, 2009 7:27 am
by ScottBot
Thanks. I'll update the comments, since that argument is now used.