Problem with HAI SDK

Basildane

Member
I'm building an application that will display a graphic of the home and property with real-time status display of security, devices, etc, represented on the floorplan.

Writing in C# Visual Studio 2010. I am using "notifications" to get real-time status updates from the panel.

So far so good, however, there seem to be some bugs in the SDK.
First, whenever I get an "extended status" notification for a zone, unit, thermostat, etc, the status byte is always zero the first time. If I say, open and close a door, the SECOND notification will contain correct information, but the first is always wrong (zero).

There seem to be tons of useful functions in the SDK, but no documentation for any of them. copystatus ... ? how do you use it? what does it do?

How does one "preload" the existing status of all devices when first starting the application? The status doesn't seem to be correct until you have someone change a device and change it back. On the other hand, PCA works perfectly, so I know it is possible.
 
I'm building an application that will display a graphic of the home and property with real-time status display of security, devices, etc, represented on the floorplan.

Writing in C# Visual Studio 2010. I am using "notifications" to get real-time status updates from the panel.

So far so good, however, there seem to be some bugs in the SDK.
First, whenever I get an "extended status" notification for a zone, unit, thermostat, etc, the status byte is always zero the first time. If I say, open and close a door, the SECOND notification will contain correct information, but the first is always wrong (zero).

There seem to be tons of useful functions in the SDK, but no documentation for any of them. copystatus ... ? how do you use it? what does it do?

How does one "preload" the existing status of all devices when first starting the application? The status doesn't seem to be correct until you have someone change a device and change it back. On the other hand, PCA works perfectly, so I know it is possible.

Well, I have my program working now. I figured out all the problems by just trying functions and watching the responses... :<<<
 
Do you have some tips to post that you've learned? Specifically, how you figured out the status byte problem always returning 0 the first time.
 
Do you have some tips to post that you've learned? Specifically, how you figured out the status byte problem always returning 0 the first time.
Sure,

The first challenge was getting notifications to start. I used this syntax, but there is nothing about how to setup the callback function.

Code:
HAC.Connection.Send(new clsOL2EnableNotifications(HAC.Connection, true), HandleNotify);
It seemed that the sample code was written to use the function "HandleUnsolicitedPackets", but I spent literally days trying to figure that out. The problem is that "HandleUnsolicitedPackets" has the wrong function header to be used in clsOL2EnableNotifications. The arguments are all wrong.

So I created my own callback called HandleNotify. Now I could get notifications, but mysteriously, they don't go to HandleNotify like I told it to, they actually go the HandleUnsolicitedPackets callback from the sample code. That took more days of stack traces and debugging to figure out.

Once again, I setup a dummy callback called HandleNotify to satisfy the clsOL2EnableNotifications call, but the SDK ignores my pointer and sends the notifications to HandleUnsolicitedPackets. OK, I can deal with that.


The next problem was when I would use a object, like HAC.Units[51].Status, it would be zero. Turns out you have to preload all of the status information by requesting every Unit and Zone, and then using CopyProperties to load it into the class. Like this: HAC.Units.CopyProperties(MSG);


Another thing that stumped me for a while is that sample code actually has some fatal flaws in it. For example, HandleUnsolicitedPackets has a call to SetStatusText to display log information. This CANNOT work like this. HandleUnsolicitedPackets must use BeginInvoke before it can call SetStatusText or it will fail with a cross threading exception...


One problem I am currently looking at is the access control readers. They don't seem to be supported in the SDK classes, so I have to parse the bytes manually.


Handling thermostat temperatures to display them in degrees was an enormous challenge. The bytes do not match what is in the PDF. Especially the outdoor temp readings. By pure chance I found a bit of sample code online that happened to move the bytes into the thermostat class, then called the OutdoorTempText method and presto, the bytes were translated to degrees for me! I wish that was documented somewhere it would have saved me about 12 hours of coding.


So now that I see how these classes work for thermostats, I went back and rewrote the entire application to use that model for zones, units, areas, etc. I removed all of my byte and bit level parsing functions that were decoding all the return data from the panel. Phew.


My challenge now, and this has nothing to do with the sdk, is to make my floorplan resizable and have all of the status objects on the floorplan resize with it...


The program is up and running. It's really cool to see the rooms light up when people enter and outdoor motion detectors turn red when the dogs run through the yard!
 
Sorry to hear you were having difficulty with the SDK let me see if I can help...

All notifications are "unsolicited" and are processed by the unsolicited message handler. The message handler "HandleNotify" in your example would only receive the response to the enable notifications command, which should have been an ACK, acknowledging that the command was successfully executed.

To move message information from a received message to the HAC object you must use the CopyProperties method. The properties are not automatically copied for a couple of reasons. First not every application needs to or wants to maintain the HAC state machine. Second in some cases you may want to see the previous state of a unit, zone, thermostat, etc. and compare it to the new state. if the copy properties happened automatically you would lose the previous state.

I fixed the problem with the SetStatusText in the HandleUnsolicitedPackets routine.

The protocol documents clearly indicate that all temperatures are in OmniTemp which is the internal temperature format of the controller. The OmniTemp scale is 1/2 degree C starting at -40 C. That is -40 C = 0 OmniTemp. All of this is covered in Appendix C where there is also a temperature chart. In the example code there is a example of requesting and parsing thermostat temperatures in the "Log Thermostat 1" section.

I have tried to eliminate as much of the bit manipulation as possible. There is a clsText with about 100 useful routines like DecodeTemp, EncodeTemp, GetAlarmText, GetAudioKeyPressText, GetEnergyCostText, etc. to decode, translate and pick apart the various bit maps.

Also most of the objects have conversion routines built in. For example on thermostats you have the property CoolSetpoint which is in OnmiTemp, but you also have CoolSetpointText which is the temperature automatically converted to the temperature scale defined in the controller. You have HorC_Status and HorC_StatusText. The first is a bitmap the second is the bitmap decoded.

I hope this is helpful. Also I would recommend visiting the HAI Developer Forum.

I will be posting an update the SDK with access control and other new features as soon as we release firmware 3.9 which has some exciting new features. And no I can't tell you about them until they are officially released so check back around the end of the month.
 
Sorry to hear you were having difficulty with the SDK let me see if I can help...

All notifications are "unsolicited" and are processed by the unsolicited message handler. The message handler "HandleNotify" in your example would only receive the response to the enable notifications command, which should have been an ACK, acknowledging that the command was successfully executed.

To move message information from a received message to the HAC object you must use the CopyProperties method. The properties are not automatically copied for a couple of reasons. First not every application needs to or wants to maintain the HAC state machine. Second in some cases you may want to see the previous state of a unit, zone, thermostat, etc. and compare it to the new state. if the copy properties happened automatically you would lose the previous state.

I fixed the problem with the SetStatusText in the HandleUnsolicitedPackets routine.

The protocol documents clearly indicate that all temperatures are in OmniTemp which is the internal temperature format of the controller. The OmniTemp scale is 1/2 degree C starting at -40 C. That is -40 C = 0 OmniTemp. All of this is covered in Appendix C where there is also a temperature chart. In the example code there is a example of requesting and parsing thermostat temperatures in the "Log Thermostat 1" section.

I have tried to eliminate as much of the bit manipulation as possible. There is a clsText with about 100 useful routines like DecodeTemp, EncodeTemp, GetAlarmText, GetAudioKeyPressText, GetEnergyCostText, etc. to decode, translate and pick apart the various bit maps.

Also most of the objects have conversion routines built in. For example on thermostats you have the property CoolSetpoint which is in OnmiTemp, but you also have CoolSetpointText which is the temperature automatically converted to the temperature scale defined in the controller. You have HorC_Status and HorC_StatusText. The first is a bitmap the second is the bitmap decoded.

I hope this is helpful. Also I would recommend visiting the HAI Developer Forum.

I will be posting an update the SDK with access control and other new features as soon as we release firmware 3.9 which has some exciting new features. And no I can't tell you about them until they are officially released so check back around the end of the month.

Hi, It's great to hear from someone.

It is helpful. But I do have my app working. I see the translation functions and figured out DecodeTemp and EncodeTemp, I use them in my thermostat control routines. But I have not found any documentation on the other functions... I'm sure they are useful and would love to make use of them.

I've been trying off and on for over a year to get on the hai developer's forums. No luck so far.

So, my system now is displaying a floor plan of the house, property, with icons representing security, units, readers, smokes, thermostats, areas. Most items are clickable and bring up context sensitive controls to do things like open/close garage door, adjust thermostats, light levels, etc.

As for the new release, will it require a firmware update on the panels too?
 
New firmware allows the controller to do new things. There is a corresponding new release of PC Access to allow you to configure the new firmware features. The two sort of go together and as a rule the PC Access version should be greater than or equal to the firmware version of the controller or data may be lost. I should probably release a SDK update every time I release a PC Access update so that third party developers can also access the new features. In the future I will try to keep the SDK synced with PC Access.
 
Back
Top