Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Driver for Bigass Fan
So I started to write a CML driver for my BAF Haiku fan, based on the unpublished protocol and CML drivers by others.

In short, any command sent to the device needs to be enclosed between < starting and > ending delimiters device replies or status updates are enclosed in between (...) round brackets.

I would like to check if for getting the messages from the devices I could use the helper function below and define the startbyte and endbyte to be the round brackets?

   [InOut] MEng.Object SrcObj
   , [In]  MEng.Card8 EndTime
   , [In]  MEng.Card1 StartByte
   , [In]  MEng.Card1 EndByte
   , [Out] MEng.String ToFill
)   Returns MEng.Boolean;

I am sorry the noob questions here, but how would I handle multiple messages in short succession coming from the device?
As an example of messages coming from the device see below:

Do the messages actually have a start and stop byte? They look like they more likely to only have a line termination. If so, then GetASCIITermedMsg would be the more appropriate scheme.

Are the above unsolicited or in response to a query? If in response to a query, and you don't know how many there will be, sometimes it's best to just send the query and let your poll method pick them up. as they come in. Your poll method can do a fairly short poll timeout, then do a loop where it loops maybe 8 times, with a very short timeout, maybe 5ms. It will read until either it times out and doesn't get a msg or you hit the 8 msg limit. Then return. Next time you'll grab any more that have shown up.

If you do a query and you kjnow for sure that a particular set of msgs are coming back, then just read until you either hit an end time or you have gotten the last one you expect. The '2' versions of the msg reader method exist just for that. You can pre-calculate an end time, and just keep passing that back into the msg reader as you loop. It will read as long as you haven't hit that end time.
Dean Roddey
Explorans limites defectum
Oh, I just noticed that those lines probably aren't single msgs, but you really want to pick out the stuff inside the () parens. If so, then you are correct, use the start/stop msg guy. If there are new lines in there somewhere, they should get ignored since they are outside of any parens it looks like.

Otherwise, the other strategy stuff above is still relevant.
Dean Roddey
Explorans limites defectum
So the messages I added in the first post came indeed in response to a query.
But there are no new lines, it may just look like that in the forum post.
The protocol looks like this:


The number of messages in reply is variable, and some are repeated..., that is where I am lost whether the the poll needs to be fast to get all of those, or how else ()()() messages would appear in GetASCIIStartStopMsg2 routine?
If you set the start and stop chars to ( and ), then you will just get one of those at a time. You can make the poll fast, just don't stay in there very long. Do a read in a loop, as mentioned, with a very short timeout on the read. That way, you can pick up what is there and process them, and get out fast as soon as you have eaten anything that has arrived.

SO set the the poll timeout to 100ms, and loop maybe 8 to 16 times per round, with a timeout of 5ms on each round. That should let you quickly response to anything that comes in.

Of course you could do the same after a query as well. So you could just have a helper method that takes a count of times to loop and will loop that many times with the very short read timeout and break out when it doesn't see anything. You could call that both from your poll callback and after a query that you know is going to return some variable number of messages
Dean Roddey
Explorans limites defectum
OK, so got the receiving of messages down and those now come in alright.
Have another theory question here:
 - What is the point of actively polling besides the initial query and setting of field values?

When the driver connects initially would query the status, say fan is on, spinning forward, speed is 3, etc. If there are changes in those parameters, the device would send updates..., processing those is not sufficient? Querying all fields especially like every second seems unnecessary.
The documentation on the driver development very eloquently explains my questions - thanks for that.
Any basic tutorial on how (properly...) to use the debugger in the CML IDE?
There isn't such a tutorial, at least not anymore in the 5.x video series. I need to do a driver for that. Maybe I can do that today. I haven't done any CQC videos in a while, so I need to get some more done.
Dean Roddey
Explorans limites defectum

Possibly Related Threads...
Thread Author Replies Views Last Post
  New Driver - How hard would this be? kblagron 4 509 05-20-2019, 11:28 AM
Last Post: zaccari
  Cytech Comfort Driver znelbok 6 480 04-10-2019, 05:39 PM
Last Post: znelbok
  OpenHAB Driver whozeawhat 6 2,325 01-16-2019, 06:45 AM
Last Post: greymatter
  LIFX Driver bobskie708 14 3,915 01-10-2019, 06:36 PM
Last Post: Dean Roddey
  XBMC Driver wuench 428 186,160 12-28-2018, 11:07 AM
Last Post: dogman
  Amazon Echo Hue Simulator Driver wuench 117 49,687 12-24-2018, 11:10 AM
Last Post: Dean Roddey
  RunTimer2 driver rbroders 15 5,587 12-14-2018, 05:28 PM
Last Post: rbroders
  Generic Modbus Driver - Serial & IP znelbok 25 14,524 10-09-2018, 08:59 AM
Last Post: Ron Haley
  Issues debugging IP based driver jnolting 5 1,271 09-24-2018, 11:52 AM
Last Post: Dean Roddey
  Enhance Driver Test Harness Field Monitor rbroders 1 807 09-24-2018, 10:49 AM
Last Post: Dean Roddey

Forum Jump:

Users browsing this thread: 1 Guest(s)