DLM Posted September 23, 2014 Share Posted September 23, 2014 Hi! Has you may guess I'm trying to use PersistData table to keep persistent data across director restarts, but I'm not getting it.function OnPropertyChanged(strProperty) if (strProperty == "Code") then codex = string.sub(Properties[strProperty], 1, -1) if (nil == PersistData) then PersistData = {} end PersistData["Code"] = codex end endIs this right? "codex" is a basic variable that it's just printed a few times (via SendToProxy):C4:SendToProxy(5001, "DISPLAY_TEXT", "<text>Code: " .. codex .. ".</text>")How can I use this? Instead of codex just use PersistData["Code"]?C4:SendToProxy(5001, "DISPLAY_TEXT", "<text>Code: " .. PersistData["Code"] .. ".</text>") Link to comment Share on other sites More sharing options...
RyanE Posted September 23, 2014 Share Posted September 23, 2014 Yes, you would just use PersistData["Code"] instead of codex. When you assign anything to the PersistData table, it will get persisted the next time the project file saves. You can trigger a project file save (although you should do it as infrequently as possible) by calling: C4:InvalidateState() However, this is somewhat moot, as Properties are also persisted, so if you're only putting the value of the property into the display text, you only need to do this: C4:SendToProxy(5001, "DISPLAY_TEXT", "<text>Code: " .. Properties["Code"] .. ".</text>") And call OnPropertyChanged("Code") at the init of your driver (in OnDriverLateInit or OnDriverInit). That'll trigger your property changed code once the driver has loaded. RyanE Link to comment Share on other sites More sharing options...
DLM Posted September 23, 2014 Author Share Posted September 23, 2014 Thank you RyanE, for your always helpful replies.I ended up using the second option and not PersistData.Just have one question which I don't find an answer to. When director restarts any devices online, go offline and online again? Drivers restart has if they were added to a project for the first time?I ask this because I'm working with an alarm system that's needs to receive the following command to accept and send commands (only at the first time is connected):C4:SendToNetwork(6001, 1002, tohex("03") .. "LI" .. Properties["Code"] .. tohex("0D"))So when director restarts I have to send this command again, right? Link to comment Share on other sites More sharing options...
RyanE Posted September 23, 2014 Share Posted September 23, 2014 I'd probably put it in the OnConnectionStatusChanged function, so every time the network connection to the panel happens, it sends the init code. That way, you know the device is actually online before sending it, and you're guaranteed to send it every time the device comes up *or* director comes up, and also when the device is initially identified and addressed. RyanE Link to comment Share on other sites More sharing options...
DLM Posted September 25, 2014 Author Share Posted September 25, 2014 That worked very well, thank you.Last question, when I unplug Ethernet cable the driver doesn't go offline in Composer but stops working (obviously!) but when I plug the cable again, it runs every commands that were entered while unpluged.Is there any "dump" function I can use or a way to detect if the cable is plugged or not? Link to comment Share on other sites More sharing options...
RyanE Posted September 25, 2014 Share Posted September 25, 2014 TCP has no way to tell until a certain time has expired, because TCP was designed as a stream protocol that just keeps working even if the cable is unplugged and then plugged back in. It's retry mechanism has to time out before it will close the connection. There's no workaround to that, other than if the protocol has some sort of ACK, your driver can do the disconnect itself if it times out (i.e. sends the command, does not get a reply in X seconds). RyanE Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.