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
  Sage Media Server driver (beta) Fonceur 698 268,278 07-26-2020, 04:59 PM
Last Post: sic0048
  RainMachine Sprinkler Irrigation Controller Driver kblagron 50 5,457 06-01-2020, 01:18 PM
Last Post: Dean Roddey
  Russound MCA-66 on TCP driver 5 622 05-24-2020, 06:23 AM
Last Post: gReatAutomation
  Samsung SmartTV Driver George M 0 208 05-20-2020, 09:04 AM
Last Post: George M
  OpenWeatherMap Weather Driver Using OneCall API kblagron 11 1,035 05-18-2020, 04:09 AM
Last Post: dlmorgan999
  Tesla Driver Driver kfly 10 1,491 05-08-2020, 08:49 AM
Last Post: gReatAutomation
  JVC D-ILA Driver jokermac 34 6,139 04-13-2020, 01:28 AM
Last Post: Mark Stega
  LIFX Driver bobskie708 15 6,826 01-05-2020, 11:00 AM
Last Post: simplextech
  Universal Devices ISY Insteon Driver wuench 369 180,564 12-28-2019, 05:15 PM
Last Post: simplextech
  RunTimer2 driver rbroders 18 8,490 10-17-2019, 04:38 PM
Last Post: rbroders

Forum Jump:

Users browsing this thread: 1 Guest(s)