Exemplo n.º 1
0
 internal static void WriteIntTag(string tagName, int value)  //Fehlernummern siehe Log.cs 0504ZZ
 {
     try
     {
         if (Is32BitSystem)
         {
             NativeMethods32 intouch = new NativeMethods32(0, 0);
             intouch.WriteInteger(tagName, value);
         }
         else
         {
             NativeMethods intouch = new NativeMethods(0, 0);
             intouch.WriteInteger(tagName, value);
         }
     }
     catch (DllNotFoundException dllex)
     {
         Log.Write(Log.Cat.InTouchDB, Log.Prio.Error, 050401, string.Format("InTouch-Bibliotheken nicht bereit zum Schreiben: {0}", dllex.Message));
         //Program.AppErrorOccured = true;
     }
     catch (Exception ex)
     {
         Log.Write(Log.Cat.InTouchDB, Log.Prio.Error, 050402, string.Format("Fehler beim Schreiben in InTouch für TagName >{4}<: \r\n\t\tTyp: {0} \r\n\t\t Fehlertext: {1}  \r\n\t\t InnerException: {2}  \r\n\t\t StackTrace: {3}", ex.GetType().ToString(), ex.Message, ex.InnerException, ex.StackTrace, tagName));
         //Program.AppErrorOccured = true;
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Lese tagName aus InTouch (view.exe)
        /// </summary>
        /// <param name="tagName">Name des zu lesenden Tags.</param>
        /// <returns>object mit Tag-Wert. Muss durch cast in gewünschten Datentyp gewandelt werden. Später ggf. per Delegaten ansprechen, um cast zu vermeiden?</returns>
        public static object ReadTag(string tagName) //Fehlernummern siehe Log.cs 0501ZZ
        {
            object result = null;

            try
            {
                if (Is32BitSystem)
                {
                    NativeMethods32 intouch = new NativeMethods32(0, 0);

                    switch (intouch.GetTagType(tagName))
                    {
                    case 1:     //PT_DISCRETE:
                        result = intouch.ReadDiscrete(tagName);
                        break;

                    case 2:     //PT_INTEGER:
                        result = intouch.ReadInteger(tagName);
                        break;

                    case 3:     //PT_REAL:
                        result = intouch.ReadFloat(tagName);
                        break;

                    case 4:     //PT_STRING:
                        result = intouch.ReadString(tagName);
                        break;
                    }
                }
                else
                {
                    NativeMethods intouch = new NativeMethods(0, 0);

                    switch (intouch.GetTagType(tagName))
                    {
                    case 1:     //PT_DISCRETE:
                        result = intouch.ReadDiscrete(tagName);
                        break;

                    case 2:     //PT_INTEGER:
                        result = intouch.ReadInteger(tagName);
                        break;

                    case 3:     //PT_REAL:
                        result = intouch.ReadFloat(tagName);
                        break;

                    case 4:     //PT_STRING:
                        result = intouch.ReadString(tagName);
                        break;
                    }
                }

                Log.Write(Log.Cat.InTouchVar, Log.Prio.Info, 050101, string.Format("Lese Tag: {0} = {1}", tagName, result));
                return(result);
            }
            catch (DllNotFoundException dllex)
            {
                Log.Write(Log.Cat.InTouchDB, Log.Prio.Error, 050102, string.Format("InTouch-Bibliotheken nicht bereit: {0}", dllex.Message));
                //Program.AppErrorOccured = true;
                return(null);
            }
            catch (Exception ex)
            {
                Log.Write(Log.Cat.InTouchDB, Log.Prio.Error, 050103, string.Format("Fehler beim Lesen aus InTouch für TagName >{4}<: \r\n\t\tTyp: {0} \r\n\t\t Fehlertext: {1}  \r\n\t\t InnerException: {2}  \r\n\t\t StackTrace: {3}", ex.GetType().ToString(), ex.Message, ex.InnerException, ex.StackTrace, tagName));
                //Program.AppErrorOccured = true;
                return(null);
            }
        }