Forum Home › Forums › Development and Integration › Logic of archiveMask
- This topic has 5 replies, 3 voices, and was last updated 1 year ago by
Mikhail.
-
AuthorPosts
-
September 11, 2024 at 2:19 am #15376
showmustgoon
ParticipantI need to customize an event that supports both real-time and historical queries. If I add a new type in the Archives table in sequence and ensure that the archiveMask covers that bit when calling WriteEvent, will that work? I’m not entirely sure if this is the best implementation.
I’m uncertain about the calculation rules of archiveMask. Is it calculated based on the sequential order of entries in the Archives table? So, does this mean that the Archives table can cover up to 32 entries at most? Is my understanding correct?
September 11, 2024 at 6:12 am #15378manjey73
ParticipantYes, the number of bits is limited for archives and events. But you can create the necessary ones yourself from the code, only the code should do checks when creating, since the code that you assume may be occupied by another or has already been created.
September 11, 2024 at 8:44 am #15382showmustgoon
ParticipantAnd…..archiveBit?
I just noticed that when writing an Event, archiveMask is used, but when getting Event, archiveBit is used. This should be the reason why I can’t read the events I wrote. I am now tracking the logic of archiveBit.September 11, 2024 at 9:00 am #15383showmustgoon
ParticipantI think I finally figured it out.
When writing, it’s possible to write to multiple archives simultaneously, so using a mask is appropriate.
However, when reading, you can only read from a single archive, so a bit is used.
Additionally, I made another mistake: I used the maximum and minimum values of DateTime as parameters for TimeRange, which caused an overflow.My test code is as follows, and the archiveMask and archiveBit used for writing and reading correspond to each other.
if (DateTime.Now-LastTime>=TimeSpan.FromSeconds(10)) { LastTime=DateTime.Now; ServerContext.WriteEvent(16,new Event { Timestamp = DateTime.UtcNow, CnlNum = 1, DeviceNum = 1, CnlVal = 11, CnlStat = CnlStatusID.Defined, Text = "123321", Data = new byte[] {0x00,0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 }, // Position = 0 }); var r= ServerContext.GetEvents(4, new TimeRange(DateTime.Today.AddDays(-2),DateTime.Today.AddDays(2), true), null); Log.WriteMessage($"Custom Events{r.Count},{string.Join(",",r.Select(x=>x.Timestamp))}",LogMessageType.Info); }
-
This reply was modified 1 year ago by
showmustgoon.
September 11, 2024 at 9:16 am #15391Mikhail
ModeratorWhen writing, it’s possible to write to multiple archives simultaneously, so using a mask is appropriate.
However, when reading, you can only read from a single archive, so a bit is used.Correct.
Also check the ArchiveMask class.September 11, 2024 at 9:16 am #15392Mikhail
ModeratorSo, does this mean that the Archives table can cover up to 32 entries at most?
31, because the archive mask is signed integer.
-
This reply was modified 1 year ago by
-
AuthorPosts
- You must be logged in to reply to this topic.