Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need some help with developing a driver
#1
I am new to CQC and unfortunately don't know much about coding, though I am trying to learn. I am trying to re purpose the webcontrol device driver to use with my airscape fan. My understanding of the webcontrol driver is that it was basically parsing the webcontrol output webpage which was in an XML type format. This is essentially what I need to do with the airscape fan. The airscape fan returns the following type of data when you send it the following command - http://10.0.0.15/fanspd.cgi

Webpage data

fanspd0 doorinprocess0 timeremaining0 macaddr60:CB:FB:00:11:EE  

That data string is setup in the following way:

fanspd<fanspd>0</fanspd>
doorinprocess<doorinprocess>0</doorinprocess>
timeremaining<timeremaining>0</timeremaining>
macaddr<macaddr>60:CB:FB:00:11:EE</macaddr>

I have managed to change and strip out what wasn't needed in the webcontrol driver, add the fields I need and compile it. Where I am having problems is when I compile and run the driver I get an error message in the log saying "Driver airscape does not have a field named 'fanspd'. I am not sure what is going wrong, I was thinking maybe it is because there is text before the node that is identical to the node.  My other thought is that maybe it is because there is no hierarchy in the returned webpage. Below is the code that I think is responsible for my problems. This is the code that was modified from the webcontrol driver. The strPath variable had a value of "\response" in the webcontrol driver. I have removed that value as the airscape data does not have that.
Code:
ForEach(theXML)
           strPath := "";
           strPath.Append(theXML.GetName());

           m_XML.GetAnchor(strPath, m_Anchor);
           m_XML.GetChildText(m_Anchor, strPathVal);

           Switch(theXML)
               Case e_XML.fanspd :
                   WriteFloatFldByName("fanspd",cvtStrToFlt(strPathVal));
               EndCase;

               Case e_XML.doorinprocess :
                   WriteFloatFldByName("DoorOpening",cvtStrToFlt(strPathVal));
               EndCase;

Any help would be appreciated.
Reply
#2
You have to register all fields in the override of your init procedure (initializeother, initializesocket).   This is done in 3 steps:

1.) Define the field (name/type/access)
TmpFld.Set(strFldName, eFldType, eFldAccess);

2.) Add the Field to the field list:
Fields.AddObject(TmpFld);

3.) After you have added all of your fields, register them.
SetFields(Fields);
Wuench
My Home Theater/Automation Website

[THREAD=5957]BlueGlass CQC Config[/THREAD]
[THREAD=10624]Wuench's CQC Drivers[/THREAD]
Reply
#3
There should have been similar code in the original one, so you can go back to that as well for an example. In some cases you don't do it in the initialize method, but generally you do. The exception is when you have to first connect to the device and ask it it how it is configured before you can know what fields to register.
Dean Roddey
Software Geek Extraordinaire
Reply
#4
(01-01-2017, 10:09 AM)Dean Roddey Wrote: There should have been similar code in the original one, so you can go back to that as well for an example. In some cases you don't do it in the initialize method, but generally you do. The exception is when you have to first connect to the device and ask it it how it is configured before you can know what fields to register.

Thanks for the replies but I guess wasn't very clear in my first post and I forgot to attach the code for the driver that I modified. The code in the post was just the part that I think is not working correctly. I have attached the full driver code that I have modified. 

Adam


Attached Files
.txt   airscape driver code.txt (Size: 10.53 KB / Downloads: 2)
Reply
#5
You removed the SetFields() call. You are adding the fields to a collection, but never actually registering them with the base driver class. You need to pass that list to SetFields().
Dean Roddey
Software Geek Extraordinaire
Reply
#6
(01-01-2017, 12:19 PM)Dean Roddey Wrote: You removed the SetFields() call. You are adding the fields to a collection, but never actually registering them with the base driver class. You need to pass that list to SetFields().
 You are right I did remove that and I shouldn't have. I added it back in and my fields now show up in the driver test harness, but it is still not working. I think it has something to do with the XML hierarchy and the way the original driver was setup.

The driver does not fail but is continuously in a "wait to connect" mode. When I step through the code I get to line number 174 (see attached image) and then when going to line number 175 something goes wrong and it skips down to line 325 which is 
Code:
 Method FreeCommResource() Returns Boolean    Begin
       Return True;
   EndMethod;

The driver then basically starts over and continuously loops through.
I think my main problem here is I don't understand the XMLparser and the getanchor method and how it works. I have read through all the documents and I understand how it works in the original webcontrol driver but just can't seem to get it right here.


Attached Files
.jpg   Airscape IDE view.jpg (Size: 299.23 KB / Downloads: 2)
Reply
#7
The path you are passing to GetAnchor() isn't valid. You'll need to look at the XML and see what the path to that element is. Keep in mind that this is a path, not a name, and it's intended to allow you to get to nested elements in the hierarchy easily. So it's like

/outerelem/innerelem/moreinnerelem

and so forth. So it's a path down through the hierarchy. So, at least you probably should start the path with / and then append your name that you are looking for if it's just a top level element.
Dean Roddey
Software Geek Extraordinaire
Reply
#8
Here is the XML I am trying to extract data from, it is copied exactly as it appears and how CQC is seeing it.

fanspd<fanspd>0</fanspd>
doorinprocess<doorinprocess>0</doorinprocess>
timeremaining<timeremaining>0</timeremaining>
macaddr<macaddr>60:CB:FB:00:11:EE</macaddr>
ipaddr<ipaddr>10.0.0.15</ipaddr>
model<model>3.5eWHF</model>
softver: <softver>2.14.2</softver>
interlock1: <interlock1>0</interlock1>
interlock2: <interlock2>0</interlock2>
cfm: <cfm>0</cfm>
power: <power>0</power>
inside: <house_temp>-99</house_temp>
<DNS1>10.0.0.1</DNS1>
attic: <attic_temp>50</attic_temp>
OA: <oa_temp>-99</oa_temp>
server response: <server_response>­ pîÇ1Ìýà„T‚ž!vEÀڍ s’ ‹ ñ</server_response>
DIP Switches: <DIPS>11100</DIPS>
Remote Switch: <switch2>1111</switch2>
Setpoint:<Setpoint>0</Setpoint>

From this I would say there is no top level element. Everything is at the same level. If I understand what you said I should put a "/" in the strPath and then append the name of the element I am looking for and it should work, unfortunately it still can't find the element. I attached a picture that shoes the IDE with me stepping through the code and the point where it fails. Could the text before the element that is identically named as the element be causing problems? 

This is actually how I had things setup initially but when things weren't working I accidentally deleted the setfields call which caused its own problems.


Attached Files
.jpg   Airscape IDE view2.jpg (Size: 433.99 KB / Downloads: 0)
Reply
#9
That's not actually legal XML. Are you sure that's all of it? I would hope that that's actually just the contents of an overall containing element?
Dean Roddey
Software Geek Extraordinaire
Reply
#10
Nope that is all of it. I kind of figured something wasn't right. I also checked the online documentation and it shows the same setup. http://blog.airscapefans.com/archives/ge...ntrols-api

Could I add the top level element to the beginning and end similar to how this line is added to the beginning "<?xml version=\"1.0\" ?>". Or is the text before each element that is making it not work?
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Vantage Controls Driver for Infusion System KenC 3 125 Yesterday, 12:10 PM
Last Post: Dean Roddey
  Another SMS Driver - SMS Global, one for everyone else znelbok 21 5,336 10-21-2017, 07:19 PM
Last Post: znelbok
  Monoprice Blackbird 4x4 HDMI Switcher - Driver request batwater 9 4,159 10-14-2017, 05:30 PM
Last Post: rtarver
  XBMC Driver wuench 419 111,237 07-02-2017, 11:04 AM
Last Post: Dean Roddey
  IMAP Email Driver whozeawhat 11 1,766 06-14-2017, 11:53 AM
Last Post: whozeawhat
  Which JVC Projector Driver indygreg 29 5,227 05-12-2017, 08:29 AM
Last Post: Dean Roddey
  Amazon Echo Hue Simulator Driver wuench 101 20,635 05-02-2017, 09:38 AM
Last Post: Dean Roddey
  SageTV Player V2 Driver chmilar 6 1,424 04-14-2017, 03:36 PM
Last Post: chmilar
  SageTV Driver George M 16 2,653 02-16-2017, 07:10 PM
Last Post: Dean Roddey
  ADA Suite 16 driver assistance zane 3 1,189 01-17-2017, 06:27 AM
Last Post: zane

Forum Jump:


Users browsing this thread: 1 Guest(s)