public ITcAdsSymbol ReadSymbol(string symbolName, out object Value) { try { Value = 0; ITcAdsSymbol symbol = m_adsClient.ReadSymbolInfo(symbolName); if (symbol == null) { throw (new SystemException("Unable to read Symbol Info " + symbolName)); } try { Value = m_adsClient.ReadSymbol(symbol); } catch (AdsDatatypeNotSupportedException err) { Value = 0; } catch (Exception err) { throw (new SystemException("Unable to read Symbol Info. " + symbolName + " " + err.Message)); } return(symbol); } catch (Exception err) { throw (new SystemException("Unable to read Symbol Info. " + symbolName + " " + err.Message)); } }
public ITcAdsSymbol ReadSymbol(string symbolName, out uint Value) { object v; ITcAdsSymbol r = ReadSymbol(symbolName, out v); Value = Convert.ToUInt32(v); return(r); }
public ITcAdsSymbol ReadSymbol(string symbolName, out short Value) { object v; ITcAdsSymbol r = ReadSymbol(symbolName, out v); Value = Convert.ToInt16(v); return(r); }
public ITcAdsSymbol ReadSymbol(string symbolName, out byte Value) { object v; ITcAdsSymbol r = ReadSymbol(symbolName, out v); Value = Convert.ToByte(v); return(r); }
public ITcAdsSymbol ReadSymbol(string symbolName, out float Value) { object v; ITcAdsSymbol r = ReadSymbol(symbolName, out v); Value = Convert.ToSingle(v); return(r); }
public ITcAdsSymbol ReadSymbol(string symbolName, out string Value) { object v; ITcAdsSymbol r = ReadSymbol(symbolName, out v); Value = v as string; return(r); }
public AdsErrorCode TryGetSymbol(string symbolPath, bool bLookup, out ITcAdsSymbol symbol) { if (string.IsNullOrEmpty(symbolPath)) { throw new ArgumentOutOfRangeException("name"); } symbol = null; SymbolInfoTable table = this; lock (table) { if (bLookup) { TcAdsSymbol symbol2 = null; if (this._symbolTable.TryGetValue(symbolPath, out symbol2)) { symbol = symbol2; return(AdsErrorCode.NoError); } } } AdsErrorCode deviceSymbolNotFound = AdsErrorCode.DeviceSymbolNotFound; AdsStream stream = new AdsStream(symbolPath.Length + 1); using (AdsBinaryWriter writer = new AdsBinaryWriter(stream)) { writer.WritePlcAnsiString(symbolPath, symbolPath.Length + 1); AdsStream rdDataStream = new AdsStream(0xffff); int readBytes = 0; deviceSymbolNotFound = this._adsClient.TryReadWrite(0xf009, 0, rdDataStream, 0, (int)rdDataStream.Length, stream, 0, (int)stream.Length, out readBytes); if (deviceSymbolNotFound == AdsErrorCode.NoError) { using (AdsBinaryReader reader = new AdsBinaryReader(rdDataStream)) { AdsSymbolEntry symbolEntry = new AdsSymbolEntry(-1L, this._encoding, reader); bool flag2 = true; flag2 = StringComparer.OrdinalIgnoreCase.Compare(symbolPath, symbolEntry.name) == 0; symbol = new TcAdsSymbol(symbolEntry, (TcAdsDataType)this._datatypeTable.ResolveDataType(symbolEntry.type)); SymbolInfoTable table2 = this; lock (table2) { this._symbolTable[symbolPath] = (TcAdsSymbol)symbol; if (!flag2 && !this._symbolTable.ContainsKey(symbol.Name)) { this._symbolTable[symbol.Name] = (TcAdsSymbol)symbol; string message = $"InstancePath Ambiguity '{symbolPath}' and '{symbol.Name}'!"; TwinCAT.Ads.Module.Trace.TraceWarning(message); } } } } } return(deviceSymbolNotFound); }
public ITcAdsSymbol GetSymbol(string symbolPath, bool bLookup) { if (string.IsNullOrEmpty(symbolPath)) { throw new ArgumentOutOfRangeException("name"); } ITcAdsSymbol symbol = null; AdsErrorCode adsErrorCode = this.TryGetSymbol(symbolPath, bLookup, out symbol); if ((adsErrorCode != AdsErrorCode.NoError) && (adsErrorCode != AdsErrorCode.DeviceSymbolNotFound)) { throw AdsErrorException.Create(adsErrorCode); } return(symbol); }
public ITcAdsSymbol FindSymbol(string symbolName) { try { ITcAdsSymbol symbol = symbolLoader.FindSymbol(symbolName); if (symbol == null) { return(null); } return(symbol); } catch (Exception err) { return(null); } }
private void btnFindSymbol_Click(object sender, System.EventArgs e) { try { ITcAdsSymbol symbol = symbolLoader.FindSymbol(tbSymbolname.Text); if (symbol == null) { MessageBox.Show("Symbol " + tbSymbolname.Text + " not found"); return; } SetSymbolInfo(symbol); } catch (Exception err) { MessageBox.Show(err.Message); } }
/// <summary> /// Trying to subscribe to the update events /// </summary> /// <returns>true - if subscribed</returns> internal override bool TrySubscribe() { if (!Device.Ready) { return(false); } try { if (IndexGroup == -1 && IndexOffset == -1) { try { ITcAdsSymbol sym = Device.AdsClient.ReadSymbolInfo(RemoteName); IndexGroup = sym.IndexGroup; IndexOffset = sym.IndexOffset; } catch { } } if (IndexGroup > -1 && IndexOffset > -1) { NotifyHandle = Device.AdsClient.AddDeviceNotificationEx( IndexGroup, IndexOffset, AdsTransMode.OnChange, 0, 0, this, typeof(T)); } else { NotifyHandle = Device.AdsClient.AddDeviceNotificationEx( RemoteName, AdsTransMode.OnChange, 0, 0, this, typeof(T)); } } catch { NotifyHandle = -1; } return(NotifyHandle > -1); }
private void SetSymbolValue(ITcAdsSymbol symbol) { currentSymbol = symbol; string Value = symbol.Name.ToString(); try { Value = adsClient.ReadSymbol(symbol).ToString(); } catch (AdsDatatypeNotSupportedException err) { log.Debug("Ads fault . " + err.Message); } catch (Exception err) { log.Debug("Unable to read Symbol Info. " + err.Message); } }
private void SetSymbolInfo(ITcAdsSymbol symbol) { currentSymbol = symbol; tbName.Text = symbol.Name.ToString(); tbIndexGroup.Text = symbol.IndexGroup.ToString(); tbIndexOffset.Text = symbol.IndexOffset.ToString(); tbSize.Text = symbol.Size.ToString(); tbDatatype.Text = symbol.Type; tbDatatypeId.Text = symbol.Datatype.ToString(); try { tbValue.Text = adsClient.ReadSymbol(symbol).ToString(); } catch (AdsDatatypeNotSupportedException err) { tbValue.Text = err.Message; } catch (Exception err) { MessageBox.Show("Unable to read Symbol Info. " + err.Message); } }
/// <summary> /// Converts an ADS symbol to tag. /// </summary> /// <param name="symbol">The symbol.</param> /// <param name="adsPort">The ads port.</param> /// <returns></returns> /// <exception cref="TagException"></exception> public static Tag ConvertSymbolToTag(ITcAdsSymbol symbol, int adsPort) { if (symbol == null) { return(null); } string[] names = symbol.Name.Split('.'); string name; string scope; if (names.Length == 1) { scope = string.Empty; name = names[0]; } else { scope = names[0]; name = symbol.Name.Replace(scope + ".", string.Empty); } var tag = new Tag { AdsPort = adsPort, Name = name, Scope = scope, BitSize = symbol.Size * 8, DataType = symbol.Type, IndexGroup = symbol.IndexGroup, IndexOffset = symbol.IndexOffset }; tag.MetaData = MetaDataParser.Parse(symbol.Comment); return(tag); }
//Ads Types public void GetPLCvarInfo(PLCvar pv) { ITcAdsSymbol symbol = adsClient.ReadSymbolInfo(pv.PLCname); pv.PLCtype = symbol.Type; }
public AdsErrorCode TryGetDataType(ITcAdsSymbol symbol, bool bLookup, out ITcAdsDataType dataType) => this._datatypeTable.TryLoadType(((ITcAdsSymbol5)symbol).TypeName, bLookup, out dataType);
public AdsSymbolException(string message, ITcAdsSymbol symbol) : this(message, symbol, null) { }
public AdsSymbolException(string message, string symbolName, Exception innerException) : base(message, innerException) { this.Symbol = null; this.SymbolName = symbolName; }
public AdsSymbolException(string message, ITcAdsSymbol symbol, Exception innerException) : base(message, innerException) { this.Symbol = symbol; this.SymbolName = symbol.Name; }
public RpcMethodNotSupportedException(string methodName, ITcAdsSymbol symbol) : base(string.Format(ResMan.GetString("RpcMethodNotSupported_Message"), methodName, symbol.Name), symbol) { }
public RpcMethodNotSupportedException(int vTableIndex, ITcAdsSymbol symbol) : base(string.Format(ResMan.GetString("RpcMethodNotSupported_Message2"), vTableIndex, symbol.Name), symbol) { }
public bool ReadSymbol(string str) { ITcAdsSymbol symbol = m_plcSymbols[str]; return(Convert.ToBoolean(m_adsClient.ReadSymbol(symbol))); }
public object InvokeRpcMethod(ITcAdsSymbol symbol, IRpcMethod rpcMethod, object[] parameterValues) { if (symbol == null) { throw new ArgumentNullException("symbol"); } if (rpcMethod == null) { throw new ArgumentNullException("rpcMethod"); } if (parameterValues == null) { throw new ArgumentNullException("parameters"); } if (rpcMethod.Parameters.Count != parameterValues.Length) { throw new ArgumentOutOfRangeException("parameters", $"Parameter mismatch! The number of expected parameters is '{rpcMethod.Parameters.Count}"); } object returnValue = null; string variableName = $"{symbol.Name}#{rpcMethod.Name}"; ITcAdsDataType type = null; if (!rpcMethod.IsVoid) { type = (ITcAdsDataType)this._datatypeTable.ResolveDataType(rpcMethod.ReturnType); } List <IDataType> list = new List <IDataType>(); foreach (RpcMethodParameter parameter in rpcMethod.Parameters) { ITcAdsDataType item = (ITcAdsDataType)this._datatypeTable.ResolveDataType(parameter.TypeName); if (item == null) { throw new AdsDatatypeNotSupportedException(); } list.Add(item); } int wrLength = 0; SymbolAdsMarshaller marshaller = new SymbolAdsMarshaller(this._datatypeTable); object[] objArray = new object[0]; wrLength = marshaller.GetInMarshallingSize(rpcMethod, objArray); int outMarshallingSize = marshaller.GetOutMarshallingSize(rpcMethod, objArray); int variableHandle = this._adsClient.CreateVariableHandle(variableName); try { byte[] buffer = new byte[wrLength]; int num4 = marshaller.MarshallParameters((RpcMethod)rpcMethod, parameterValues, buffer, 0); using (AdsStream stream = new AdsStream(buffer)) { using (AdsStream stream2 = new AdsStream(outMarshallingSize)) { int num5 = 0; num5 = this._adsClient.ReadWrite(variableHandle, stream2, 0, outMarshallingSize, stream, 0, wrLength); if (outMarshallingSize > 0) { int num6 = marshaller.UnmarshalRpcMethod(rpcMethod, parameterValues, stream2.GetBuffer(), out returnValue); } } } } finally { this._adsClient.DeleteVariableHandle(variableHandle); } return(returnValue); }