public uint AddNotification <T>(string varName, AdsTransmissionMode transmissionMode, uint cycleTime, object userData = null) { var varHandle = GetSymhandleByName(varName); uint length = GenericHelper.GetByteLengthFromType <T>(DefaultStringLength); return(AddNotification(varHandle, length, transmissionMode, cycleTime, userData, typeof(T))); }
public byte[] ReadBytes <T>(string varName) { uint varHandle = GetSymhandleByName(varName); var length = GenericHelper.GetByteLengthFromType <T>(defaultStringLenght); return(ReadBytes(varHandle, length)); }
public async Task <uint> AddNotificationAsync <T>(string varName, AdsTransmissionMode transmissionMode, uint cycleTime, uint arraylength = 1, object userData = null) { uint varHandle = await GetSymhandleByNameAsync(varName); var length = GenericHelper.GetByteLengthFromType <T>(DefaultStringLength, arraylength); var result = await AddNotificationAsync(varHandle, length, transmissionMode, cycleTime, userData, typeof(T)); return(result); }
/// <summary> /// Reads the value from the name of a twincat variable /// </summary> /// <param name="varName">A twincat variable like ".XXX" or "MAIN.YYY" etc.</param> /// <returns>A byte[] with the value of the twincat variable</returns> public async Task <byte[]> ReadBytesAsync <T>(string varName) { uint varHandle = await GetSymhandleByNameAsync(varName); var length = GenericHelper.GetByteLengthFromType <T>(DefaultStringLength); var result = await ReadBytesAsync(varHandle, length); return(result); }
/// <summary> /// Read the value from the handle returned by GetSymhandleByName. /// </summary> /// <typeparam name="T">A type like byte, ushort, uint depending on the length of the twincat variable</typeparam> /// <param name="varHandle">The handle returned by GetSymhandleByName</param> /// <param name="arrayLength">An optional array length.</param> /// <param name="adsObj">An optional existing object.</param> /// <returns>The value of the twincat variable</returns> public T Read<T>(uint varHandle, uint arrayLength = 1, object adsObj = null) { var length = GenericHelper.GetByteLengthFromType<T>(DefaultStringLength, arrayLength); var value = ReadBytes(varHandle, length); if (value != null) return GenericHelper.GetResultFromBytes<T>(value, DefaultStringLength, arrayLength, adsObj); else return default(T); }
/// <summary> /// Read the value from the handle returned by GetSymhandleByNameAsync. /// </summary> /// <typeparam name="T">A type like byte, ushort, uint depending on the length of the twincat variable</typeparam> /// <param name="varHandle">The handle returned by GetSymhandleByNameAsync</param> /// <param name="arrayLength">An optional array length.</param> /// <param name="adsObj">An optional existing object.</param> /// <returns>The value of the twincat variable</returns> public async Task <T> ReadAsync <T>(uint varHandle, uint arrayLength = 1, object adsObj = null) { var length = GenericHelper.GetByteLengthFromType <T>(DefaultStringLength, arrayLength); var value = await ReadBytesAsync(varHandle, length); if (value != null) { return(GenericHelper.GetResultFromBytes <T>(value, DefaultStringLength, arrayLength, adsObj)); } else { return(default(T)); } }
/// <summary> /// Add a noticiation when a variable changes or cyclic after a defined time in ms /// </summary> /// <typeparam name="T">Type for defining the length of the data that must be send by the notification</typeparam> /// <param name="varHandle">The handle returned by GetSymhandleByNameAsync</param> /// <param name="transmissionMode">On change or cyclic</param> /// <param name="cycleTime">The cyclic time in ms. If used with OnChange, then the value is send once after this time in ms</param> /// <param name="userData">A custom object that can be used in the callback</param> /// <returns></returns> public uint AddNotification <T>(uint varHandle, AdsTransmissionMode transmissionMode, uint cycleTime, object userData) { uint length = GenericHelper.GetByteLengthFromType <T>(DefaultStringLength); return(AddNotification(varHandle, length, transmissionMode, cycleTime, userData, typeof(T))); }
/// <summary> /// Read the value from the handle returned by GetSymhandleByName /// </summary> /// <typeparam name="T">A type like byte, ushort, uint depending on the length of the twincat variable</typeparam> /// <param name="varHandle">The handle returned by GetSymhandleByName</param> /// <returns>The value of the twincat variable</returns> public T Read <T>(uint varHandle) { byte[] value = ReadBytes(varHandle, GenericHelper.GetByteLengthFromType <T>(DefaultStringLength)); return(GenericHelper.GetResultFromBytes <T>(value, DefaultStringLength)); }
/// <summary> /// Read the value from the handle returned by GetSymhandleByNameAsync /// </summary> /// <typeparam name="T">A type like byte, ushort, uint depending on the length of the twincat variable</typeparam> /// <param name="varHandle">The handle returned by GetSymhandleByNameAsync</param> /// <returns>The value of the twincat variable</returns> public async Task <T> ReadAsync <T>(uint varHandle) { byte[] value = await ReadBytesAsync(varHandle, GenericHelper.GetByteLengthFromType <T>(DefaultStringLength)); return(GenericHelper.GetResultFromBytes <T>(value, DefaultStringLength)); }