Jump to content


Photo
- - - - -

School of Hard Knocks


  • Please log in to reply
5 replies to this topic

#1 123

123

    Cocoonut

  • Registered
  • PipPipPipPip
  • 1978 posts
  • Location:Montreal, QC
  • Experience:average
  • Software:Premise
  • Hardware:Elk M1

Posted 04 March 2008 - 09:17 AM

Please add to this thread things you've learned about Premise that will save other people time and effort.
NOTE: Please discuss issues elsewhere and only post confirmed quirks here.

PROGRAMMING

Never name a property "ID"!
Premise stores all objects in XML format. Each object has a unique (hidden) identifier called "ID". If you name a property "ID" it will duplicate the existing object identifier ... and that violates an XML structural rule.

Nothing bad happens immediately. However, when Premise SYS Server starts up it loads the most recent backup of the XML data and halts on the line containing the duplicate identifiers. It discards the whole backup file and attempts to load an older backup copy. It will keep doing this until it finds a valid XML backup. If it runs out of available backups it reverts to a blank slate.

I discovered this while developing a new Module. Every backup copy had the duplicated "ID" so SYS Server was unable to load any of them! To find the offending line, change the backup file's extension from XDO to XML and open it with Internet Explorer. IE will display the XML file, halt at the offending line, and print an error message.

In conclusion, you should avoid creating any two properties with the same name!


Steer clear of special characters when scripting!
This is another XML bugaboo. XML stores special characters like ampersand (&) and single quote ('), and several others, in an encoded format. Ideally, when you enter the "&" character in a script, Premise should store it as "&" in the XML file. It does not do this so, once again, SYS Server will fail to load the XML file. Phooey! And so in my script comments, you won't find much more than a-z and 0-9. This topic is documented in greater detail in this post.

Edited by 123, 27 June 2009 - 06:10 PM.


#2 123

123

    Cocoonut

  • Registered
  • PipPipPipPip
  • 1978 posts
  • Location:Montreal, QC
  • Experience:average
  • Software:Premise
  • Hardware:Elk M1

Posted 22 August 2008 - 01:56 PM

Don't use an existing Module to create a new one.

If you want to build a new Module be sure to create one from scratch. Do not simply modify an existing one and give it a new name.

DO NOT DO THIS:
You have an existing module called "DoorControl".
You export it to create a backup ("DoorControl.xdo").
You rename the "DoorControl" Module to "GarageDoorControl" and modify its code.
You export "GarageDoorControl".
You now want "DoorControl" as well so you import "DoorControl.xdo" and ... uh-oh ... now you've learned a painful lesson!


Both Modules have the same GUID (uh-oh)! When you import DoorControl.xdo it overlays itself onto the existing GarageDoorControl module. You now have a software version of "The Fly" ... a tangled combination of code from both modules.

All is not lost because you can use a text-editor to replace the duplicated GUIDs in GarageDoorControl.xdo ... assuming you remembered to export the GarageDoorControl module before you trounced it. Be advised that this is a tedious task and is a last resort to avoid losing the new Module. To create unique GUIDs, you can use Microsoft's guidgen.exe or guidgen.com. And yes, it happened to me. :(

Edited by 123, 22 August 2008 - 03:22 PM.


#3 123

123

    Cocoonut

  • Registered
  • PipPipPipPip
  • 1978 posts
  • Location:Montreal, QC
  • Experience:average
  • Software:Premise
  • Hardware:Elk M1

Posted 17 August 2009 - 10:22 AM

IRemotePremiseObjectCollection doesn't play nice with a foreach loop.

IRemotePremiseObjectCollection is a MiniBroker class that represents a collection of Premise objects. For example, assuming "Home" represents the Premise Home object, this line of code returns a collection of Lighting objects.

IRemotePremiseObjectCollection Lights = Home.GetObjectsByType("sys://Schema/Device/Lighting/Lighting", true);

IRemotePremiseObjectCollection includes a method called Count that reveals the number of elements in the collection. The following for loop will print the name of each light in the collection.

// List all lights using a for loop.
	for (int x = 0; x < Lights.Count; x++)
		Debug.WriteLine(Lights.Item(x).Name);

A neater way of iterating through each element in the collection is to use a foreach loop. Unfortunately, when used with a foreach loop, the collection behaves as if it has Count+1 elements! The foreach loop attempts to look at one more element than actually exists in the collection and fails.

// List all lights using a foreach loop.
	// This will fail!
	foreach (IRemotePremiseObject Light in Lights)
		Debug.WriteLine(Light.Name);

The workaround is to simply use a for loop or to wrap the foreach in a try-catch like so:
// List all lights using a foreach loop in a try-catch.
	try
	{
		foreach (IRemotePremiseObject Light in Lights)
			Debug.WriteLine(Light.Name);
	}
	catch
	{
		// Bug: We are here because the collection behaves as if there are Count+1 elements.
	}


#4 123

123

    Cocoonut

  • Registered
  • PipPipPipPip
  • 1978 posts
  • Location:Montreal, QC
  • Experience:average
  • Software:Premise
  • Hardware:Elk M1

Posted 28 October 2009 - 09:07 AM

Unable to extend an existing Unit class.

I tried to extend the Velocity class so that, in addition to MetersPerSecond and FeetPerSecond, it would have built-in conversions for KilometersPerHour and MilesPerHour. I was unsuccessful and I'm going to assume this is because Premise does not allow you to extend a "core" Premise class (i.e. classes in Schema.System).

A Unit's "conversion" is actually a class called "UnitChild". Builder doesn't let you add them to a new class. To get around this limitation, I exported my class into an XDO, manually appended the "UnitChild" classes, and then re-imported the XDO. Premise didn't complain about the new extended Velocity class but it didn't use it either.

In contrast, if I create a class that inherits from Velocity, the new conversions work ... sort of. It should've inherited the existing conversions (m/s and ft/s) but all that appears in the editor are the new conversions (kph and mph).

The results of my tests are summarized in the attached image.

Attached Files



#5 etc6849

etc6849

    Cocoonut

  • Registered
  • PipPipPipPip
  • 1605 posts
  • Location:Irmo, SC
  • Experience:average
  • Software:Premise
  • Hardware:Elk M1
  • Tech:X10-RF, Z-Wave, Custom
  • Phone:OBi100/110

Posted 09 January 2011 - 03:06 AM

Sysevent.SrcProperty.Name becomes "trigger" when a property is called using a macro!

I think 123 and I have discussed this before, but I couldn't find it so I'll post it here.

Scenario
You are making a module for an RS232 controlled lighting network. You have a property called Brightness that also changes PowerState if a light is off to turn it on. To prevent PowerState from also sending RS232 code that would turn the light on (cuts down on RS232 traffic), you use a statement such as:
if sysevent.srcProperty.name <> "Brightness" then ... end if
within the OnChangePowerState script for the lighting class.


The danger here is trusting that sysevent.srcProperty.name will always be "Brightness" if brightness is changed! In reality, if a scriptMacro changes the brightness and not the user directly, sysevent.srcProperty.name becomes "Trigger" and the RS232 command is sent twice: once for the OnChangeBrightness script and once for the OnChangePowerState script, doh!

The easiest solution I can think of is to use a simple Boolean flag called "BrightnessChanging" and set it to true before Brightness sets the PowerState and false once the OnChangeBrightness script is finished. OnChangePowerState would in turn check that this flag is false before processing anything so only a single RS232 command is sent to the lighting network.

#6 Powox

Powox

    Cocooner

  • Registered
  • PipPip
  • 20 posts
  • Location:Paris, France
  • Software:Premise, Custom
  • Hardware:Custom
  • Tech:Custom, Control4, KNX
  • Audio:AirPlay
  • Video:Windows Media Center
  • CCTV:ip

Posted 21 February 2011 - 04:15 PM

Not enough disk space ?

I Have had a problem of disk space. few kilo octets only...
But, premise has rewrite the main XDO, so to write, premise has opened the file and ... not enough disk space to rewrite and close the file...

consequence : soft reset...

Jean-Michel

Edited by Powox, 21 February 2011 - 04:15 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users