private void grouop_DataChanged(object sender, DataChangeEventArgs e) { foreach (OPCItemState sta in e.sts) { OPCItem item = this.group.Items.GetItemByClientHandler(sta.HandleClient); foreach (ItemValue iv in values) { if (iv.id == item.ID) { iv.value = sta; break; } } } foreach (ItemValue iv in values) { if (iv.value == null) { readed = false; return; } } readed = true; }
// ------------------------ IOPCDataCallback --------------- void IOPCDataCallback.OnDataChange( int dwTransid, int hGroup, int hrMasterquality, int hrMastererror, int dwCount, IntPtr phClientItems, IntPtr pvValues, IntPtr pwQualities, IntPtr pftTimeStamps, IntPtr ppErrors) { Trace.WriteLine("OpcGroup.OnDataChange"); if ((dwCount == 0) || (hGroup != state.HandleClient)) { return; } int count = (int)dwCount; int runh = (int)phClientItems; int runv = (int)pvValues; int runq = (int)pwQualities; int runt = (int)pftTimeStamps; int rune = (int)ppErrors; DataChangeEventArgs e = new DataChangeEventArgs(); e.transactionID = dwTransid; e.groupHandleClient = hGroup; e.masterQuality = hrMasterquality; e.masterError = hrMastererror; e.sts = new OPCItemState[count]; for (int i = 0; i < count; i++) { e.sts[i] = new OPCItemState(); e.sts[i].Error = Marshal.ReadInt32((IntPtr)rune); rune += 4; e.sts[i].HandleClient = Marshal.ReadInt32((IntPtr)runh); runh += 4; if (HRESULTS.Succeeded(e.sts[i].Error)) { short vt = Marshal.ReadInt16((IntPtr)runv); if (vt == (short)VarEnum.VT_ERROR) { e.sts[i].Error = Marshal.ReadInt32((IntPtr)(runv + 8)); } e.sts[i].DataValue = Marshal.GetObjectForNativeVariant((IntPtr)runv); e.sts[i].Quality = Marshal.ReadInt16((IntPtr)runq); e.sts[i].TimeStamp = Marshal.ReadInt64((IntPtr)runt); } runv += DUMMY_VARIANT.ConstSize; runq += 2; runt += 8; } if (DataChanged != null) { DataChanged(this, e); } }
void IOPCDataCallback.OnDataChange( int dwTransid, int hGroup, int hrMasterquality, int hrMastererror, int dwCount, IntPtr phClientItems, IntPtr pvValues, IntPtr pwQualities, IntPtr pftTimeStamps, IntPtr ppErrors) { Trace.WriteLine($"{nameof(OpcGroup)}.{nameof(IOPCDataCallback.OnDataChange)}, transID:{dwTransid}, count:{dwCount}, thread ID:{System.Threading.Thread.CurrentThread.ManagedThreadId}"); if ((dwCount == 0) || (hGroup != stateHandleClient)) { return; } DataChangeEventArgs eventArgs = new DataChangeEventArgs { TransactionID = dwTransid, GroupHandleClient = hGroup, MasterQuality = hrMasterquality, MasterError = hrMastererror, ItemStates = new OpcItemState[dwCount] }; for (int i = 0; i < dwCount; i++) { eventArgs.ItemStates[i] = new OpcItemState { Error = Extensions.ReadInt32(ppErrors, i), HandleClient = Extensions.ReadInt32(phClientItems, i) }; if (HRESULTS.Succeeded(eventArgs.ItemStates[i].Error)) { // Test if native variant is VT_ERROR short vt = Marshal.ReadInt16(pvValues, i * Extensions.NativeVariantSize); if (vt == (short)VarEnum.VT_ERROR) { eventArgs.ItemStates[i].Error = Marshal.ReadInt32(pvValues, (i * Extensions.NativeVariantSize) + 8); } eventArgs.ItemStates[i].DataValue = Extensions.GetObjectForNativeVariant(pvValues, i); eventArgs.ItemStates[i].Quality = Extensions.ReadInt16(pwQualities, i); eventArgs.ItemStates[i].TimeStamp = Extensions.ReadInt64(pftTimeStamps, i); } } dataChanged?.Invoke(this, eventArgs); }
// ------------------------------ events ----------------------------- public void TheGrpDataChange(object sender, DataChangeEventArgs e) { lock (locker) { InstantLogger.msg("DataChange event: gh={0} id={1} me={2} mq={3}", e.groupHandleClient, e.transactionID, e.masterError, e.masterQuality); foreach (OPCItemState s in e.sts) { if (HRESULTS.Succeeded(s.Error)) InstantLogger.msg(" ih={0} v={1} q={2} t={3}", s.HandleClient, s.DataValue, s.Quality, s.TimeStamp); else InstantLogger.msg(" ih={0} ERROR=0x{1:x} !", s.HandleClient, s.Error); } } }
public void TheGrpDataChange(object sender, DataChangeEventArgs e) { CoreEventGenerator(sender, e); }
// event handler: called if any item in group has changed values protected void theGrp_DataChange(object sender,DataChangeEventArgs e) { string sPLC_Adr,sAlias,sP; lock (lockThis) { // ����� ����� �������� ����� ����� � ������������������� ���� � ������ �� iThreadCnt++; DateTime dtBeg = DateTime.Now; //Trace.WriteLine("theGrp_DataChange id=" + e.transactionID.ToString() + " me=0x" + e.masterError.ToString("X")); //listOpcView.BeginUpdate(); //AddLogg("iThreadCnt=" + iThreadCnt + " Id " + Process.GetCurrentProcess().Id + ",� ������� " + e.sts.GetLength(0) + // " ���������"); foreach (OPCItemState s in e.sts) { try { if (HRESULTS.Succeeded(s.Error)) { //Trace.WriteLine(" val=" + s.DataValue.ToString()); if (s.HandleClient < pointLi.Count) { if (s.DataValue != null) { setTextInTxbViaDelegate(ref txtItemValue,s.DataValue.ToString()); setTextInTxbViaDelegate(ref txtItemQual,OpcGroup.QualityToString(s.Quality)); setTextInTxbViaDelegate(ref txtItemTimeSt,DateTime.FromFileTime(s.TimeStamp).ToString()); pointLi[s.HandleClient].opcItem = s; if (s.DataValue.GetType() == typeof(SByte[])) { pointLi[s.HandleClient].sDataValue = ConvertToRus((SByte[])s.DataValue,pointLi[s.HandleClient].iDataLength); } else { if (s.DataValue.GetType() == typeof(DateTime)) { pointLi[s.HandleClient].dtDataValue = Convert.ToDateTime(s.DataValue); } else { pointLi[s.HandleClient].iDataValue = Convert.ToInt32(s.DataValue); if (pointLi[s.HandleClient].CanonicalDataType == VarEnum.VT_R4) { pointLi[s.HandleClient].fDataValue = Convert.ToDouble(s.DataValue); } } } pointLi[s.HandleClient].iReadCnt++; if (Math.Max(pointLi[s.HandleClient].iReadCnt,pointLi[s.HandleClient].iReadCntMax) > pointLi[s.HandleClient].iReadCntMax) { pointLi[s.HandleClient].iReadCntMax = pointLi[s.HandleClient].iReadCnt; pointLi[s.HandleClient].dtMax = DateTime.Now; } DoStoreToOracle(s.HandleClient); // das Gelesene rausschmeissen DoStoreToCore(s.HandleClient); // dem Core senden if (sAliasToControl == pointLi[s.HandleClient].sAlias) { // der Punkt ist controlled setTextInTxbViaDelegate(ref txbCtrlItemDataType,pointLi[s.HandleClient].sCanonicalDataType); setTextInTxbViaDelegate(ref txbCtrlObjType, pointLi[s.HandleClient].opcItem.DataValue.GetType().ToString()); setTextInTxbViaDelegate(ref txbCtrlItemTimeSt,LoggDateToString()); setTextInTxbViaDelegate(ref txbCtrlItemValue, pointLi[s.HandleClient].opcItem.DataValue.ToString()); if (s.DataValue.GetType() == typeof(SByte[])) { setTextInTxbViaDelegate(ref txbCtrlItemValueUmc,pointLi[s.HandleClient].sDataValue); sP = pointLi[s.HandleClient].sDataValue; } else { if (s.DataValue.GetType() == typeof(DateTime)) { setTextInTxbViaDelegate(ref txbCtrlItemValueUmc, pointLi[s.HandleClient].dtDataValue.ToString()); sP = pointLi[s.HandleClient].dtDataValue.ToString(); } else { setTextInTxbViaDelegate(ref txbCtrlItemValueUmc, pointLi[s.HandleClient].iDataValue.ToString()); sP = pointLi[s.HandleClient].iDataValue.ToString(); } } AddLogg("Pkt" + s.HandleClient + "," + s.DataValue.GetType() + " ��������: '" + sP + "'"); setTextInTxbViaDelegate(ref txbCtrlItemQual, OpcGroup.QualityToString(pointLi[s.HandleClient].opcItem.Quality)); setTextInTxbViaDelegate(ref txbCtrlReadCnt,pointLi[s.HandleClient].iReadCnt.ToString()); setTextInTxbViaDelegate(ref txbCtrlReadCntMax,pointLi[s.HandleClient].iReadCntMax.ToString()); setTextInTxbViaDelegate(ref txbCtrldtMax,LoggDateToString(pointLi[s.HandleClient].dtMax)); } } else { AddLogg("s.HandleClient{" + s.HandleClient + "} s.DataValue == null"); } } else { AddLogg("s.HandleClient{" + s.HandleClient + "}>=pointLi.Count{" + pointLi.Count + "}"); } } else { AddLogg("s.HandleClient{" + s.HandleClient + "} ERROR 0x" + s.Error.ToString("X")); setTextInTxbViaDelegate(ref txtItemTimeSt,DateTime.FromFileTime(s.TimeStamp).ToString()); setTextInTxbViaDelegate(ref txtItemQual,"error"); setTextInTxbViaDelegate(ref txtItemValue,"ERROR 0x" + s.Error.ToString("X")); } } catch (Exception exc) { AddLogg("Pkt" + s.HandleClient + "," + s.DataValue.GetType() + " " + exc.Message); //listOpcView.EndUpdate(); } } //listOpcView.EndUpdate(); //AddLogg("iThreadCnt=" + iThreadCnt + ",������� ���������� " + e.sts.GetLength(0) + " ��������� " + // (DateTime.Now - dtBeg).Milliseconds.ToString() + " ms"); iThreadCnt--; } }
// ------------------------ IOPCDataCallback --------------- void IOPCDataCallback.OnDataChange( int dwTransid, int hGroup, int hrMasterquality, int hrMastererror, int dwCount, IntPtr phClientItems, IntPtr pvValues, IntPtr pwQualities, IntPtr pftTimeStamps, IntPtr ppErrors) { Trace.WriteLine( "OpcGroup.OnDataChange" ); if( (dwCount == 0) || (hGroup != state.HandleClient) ) return; int count = (int) dwCount; int runh = (int) phClientItems; int runv = (int) pvValues; int runq = (int) pwQualities; int runt = (int) pftTimeStamps; int rune = (int) ppErrors; DataChangeEventArgs e = new DataChangeEventArgs(); e.transactionID = dwTransid; e.groupHandleClient = hGroup; e.masterQuality = hrMasterquality; e.masterError = hrMastererror; e.sts = new OPCItemState[ count ]; for( int i = 0; i < count; i++ ) { e.sts[i] = new OPCItemState(); e.sts[i].Error = Marshal.ReadInt32( (IntPtr) rune ); rune += 4; e.sts[i].HandleClient = Marshal.ReadInt32( (IntPtr) runh ); runh += 4; if( HRESULTS.Succeeded( e.sts[i].Error ) ) { short vt = Marshal.ReadInt16( (IntPtr) runv ); if( vt == (short) VarEnum.VT_ERROR ) e.sts[i].Error = Marshal.ReadInt32( (IntPtr) (runv + 8) ); e.sts[i].DataValue = Marshal.GetObjectForNativeVariant( (IntPtr) runv ); e.sts[i].Quality = Marshal.ReadInt16( (IntPtr) runq ); e.sts[i].TimeStamp = Marshal.ReadInt64( (IntPtr) runt ); } runv += DUMMY_VARIANT.ConstSize; runq += 2; runt += 8; } if( DataChanged != null ) DataChanged( this, e ); }
private static void OnDataChange(object sender, DataChangeEventArgs e) { var sb = new StringBuilder("=========== OnDataChange "); foreach (var s in e.sts) { //Console.WriteLine("cHandle = {0} val = {1} qual = {2}", s.HandleClient, s.DataValue, s.Quality); sb.AppendFormat("{0}", s.HandleClient); SetValue(s.HandleClient, s.DataValue); sb.Append(";"); } foreach (var d in descriptions) { if ((d.Flags & FlexEventFlag.FlexEventOpcNotification) != 0) { fireFlex(d); d.Flags ^= FlexEventFlag.FlexEventOpcNotification; } } Console.WriteLine(sb); }
private void GroupDataChange(object sender, DataChangeEventArgs e) { try { // Запоминаем ссылку на событие по groupHandleClient группы BaseEvent _event = m_ClientGroups[e.groupHandleClient].Event; InstantLogger.log(string.Format("DataChange GroupId={0} GroupName={1} GroupLocation={2}", e.groupHandleClient, m_ClientGroups[e.groupHandleClient].Name, m_ClientGroups[e.groupHandleClient].Location), "OPC"); bool somethingChanged = false; // Пробегаемся рефлекшином по всем полям класса события, для которых пришли данные с контроллера // и заполняем их. При этом смотрим были ли какие то изменения в пропертях. // Так же если проперть имеет тип байт заполняем его через метод расширения класса Byte foreach (OPCItemState state in e.sts) { PropertyInfo property = _event.GetType().GetProperty(m_ClientGroups[e.groupHandleClient].Points[state.HandleClient].FieldName); object value = !m_ClientGroups[e.groupHandleClient].Points[state.HandleClient].IsBoolean ? Client.Convert(state.DataValue, m_ClientGroups[e.groupHandleClient].Points[state.HandleClient].Encoding): ((Byte) state.DataValue).GetBit(m_ClientGroups[e.groupHandleClient].Points[state.HandleClient].BitNumber) ; somethingChanged = value != property.GetValue(_event, null) ? true : false; property.SetValue(_event, value, null); } _event.Time = DateTime.Now; InstantLogger.log(_event.ToString(), "OPC"); // Проверяем существует ли фильтр для данного события и если существует, то смотрим равняется ли заданная проперть // фильтра заданному значению фильтра. // По итогам проверки отсылаем копию события либо нет. if (string.IsNullOrEmpty(m_ClientGroups[e.groupHandleClient].FilterPropertyName) || _event.GetType().GetProperty(m_ClientGroups[e.groupHandleClient].FilterPropertyName).GetValue(_event, null).ToString() == m_ClientGroups[e.groupHandleClient].FilterPropertyValue) { // Отсылаем событие только в том случае если хоть одна проперть в нем поменялась либо это самая первая посылка // данного события. if (somethingChanged || m_ClientGroups[e.groupHandleClient].FirstSend) { MainGates[m_ClientGroups[e.groupHandleClient].Destination].PushEvent(_event.ShallowCopy()); m_ClientGroups[e.groupHandleClient].FirstSend = false; } } } catch (Exception exc) { InstantLogger.log(string.Format("Data Change error -- {0}", exc.Message), "OPC"); } }
private void GroupDataChange(object sender, DataChangeEventArgs e) { if (OnOPCDataChangedHandler != null) { OnOPCDataChangedHandler(sender, e); } }