public void Connect() { Console.WriteLine("Connect"); try { m_IpAddress = Convert.ToString(BaseFunctions.GetPropValue(m_DriverProps, "IPAddress")); m_armAddress = Convert.ToString(BaseFunctions.GetPropValue(m_DriverProps, "ArmAddress")); m_Port = Convert.ToString(BaseFunctions.GetPropValue(m_DriverProps, "Port")); //m_VolumeUnits = Convert.ToString(BaseFunctions.GetPropValue(m_DriverProps, "Units")); if (!(m_Connected)) { m_Connected = m_device.Connect(m_IpAddress, m_armAddress, m_Port); } m_Connected = true; oasTagTimer.Change(500, 500); } catch (Exception ex) { Console.WriteLine("{0} : {1}", "Connect", ex.Message); m_OASDriverInterface.UpdateSystemError(true, "Connect", 1, "GetDefaultDriverConfig Exception: " + ex.Message); } }
private void UpdateOASTagTimerRoutine(object State) { try { if (m_InTimerRoutine) { return; } m_InTimerRoutine = true; DateTime currentTime = DateTime.Now; double localSeconds = currentTime.Second + (currentTime.Millisecond / (double)1000); tagList = m_device.ReturnCurrentTaglist(); ArrayList localArrayList = new ArrayList(); lock (m_Tags.SyncRoot) { lock (m_StaticTagValues.SyncRoot) { foreach (DictionaryEntry de in m_Tags) { string TagID = (string)de.Key; List <ClassProperty> TagItems = (List <ClassProperty>)de.Value; // Just simulating using the PollingRate property bool OKToPoll = true; if (m_LastUpdateTime.Contains(TagID)) { double PollingRate = (double)BaseFunctions.GetPropValue(TagItems, "PollingRate"); DateTime lastUpdateTime = (DateTime)m_LastUpdateTime[TagID]; if (lastUpdateTime.AddSeconds(PollingRate) > currentTime) { OKToPoll = false; } } if (OKToPoll) { if (m_LastUpdateTime.Contains(TagID)) { m_LastUpdateTime[TagID] = currentTime; } else { m_LastUpdateTime.Add(TagID, currentTime); } object Value = null; Value = tagList.Where(x => x.TagName == TagID).First().Value; bool Quality = false; if (Value != null && !string.IsNullOrWhiteSpace(Value.ToString())) { Quality = true; } // You can include mutiple values to the same tag with different timestamps in the same callback if you like. // In this example it just updates when the timer fires and the check for the PollingRate succeeds. localArrayList.Add(new ClassTagValue(TagID, Value, currentTime, Quality)); } } } } if (localArrayList.Count > 0) { // Send values to OAS Service m_OASDriverInterface.AsyncReadCallback((ClassTagValue[])localArrayList.ToArray(typeof(ClassTagValue))); } } catch (Exception ex) { Console.WriteLine("{0} : {1}", "TimerRoutine", ex.Message); m_OASDriverInterface.UpdateSystemError(true, "Communications", 5, "TimerRoutine Exception: " + ex.Message); } m_InTimerRoutine = false; }
// This method is called from the service to add tags to be monitored continuously. public void AddTags(List <ClassProperty>[] Tags) { Console.WriteLine("AddTags"); var localTime = DateTime.Now; try { if (prompts.Count > 0) { prompts.Clear(); } if (tagList.Count > 0) { tagList.Clear(); } // Add Logic. Props is a list of ClassProperty in the same order of Get Tag Config lock (m_Tags.SyncRoot) { foreach (List <ClassProperty> Props in Tags) { // Use the TagName as a unique identifier for the Tag Name and Parameter being interfaced with. string TagID = (string)BaseFunctions.GetPropValue(Props, "TagName"); DataPoint dp = (DataPoint)BaseFunctions.GetPropValue(Props, "DataPoint"); if (dp == DataPoint.Prompt) { int order = (int)BaseFunctions.GetPropValue(Props, "PromptOrder"); string promptText = (string)BaseFunctions.GetPropValue(Props, "PromptText"); string promptLength = (string)BaseFunctions.GetPropValue(Props, "PromptLength"); prompts.Add(new Prompts { TagName = TagID, Order = order, Prompt = promptText, PromptLength = promptLength }); } tagList.Add(new TagModel { TagName = TagID, LastRead = localTime, PollingRate = (double)BaseFunctions.GetPropValue(Props, "PollingRate"), Value = 0, DataPoint = dp.ToString() //ValueDataType = (string)BaseFunctions.GetPropValue(Props, "VolumeType") }); if (m_Tags.Contains(TagID)) { m_Tags[TagID] = Props; } else { m_Tags.Add(TagID, Props); } if (m_LastUpdateTime.Contains(TagID)) { m_LastUpdateTime.Remove(TagID); } } try { var cartId = tagList.Where(x => x.TagName.Contains("CartId")).First(); cartId.Value = m_cartId; cartId.LastRead = DateTime.Now; } catch (Exception e) { } m_device.LoadTags(tagList); m_device.LoadPrompts(prompts); } } catch (Exception ex) { Console.WriteLine("{0} : {1}", "AddTags", ex.Message); m_OASDriverInterface.UpdateSystemError(true, "Communications", 1, "AddTags Exception: " + ex.Message); } }