Esempio n. 1
0
        //private Boolean IsNumeric (System.Object Expression)
        //{
        //    if(Expression == null || Expression is DateTime)
        //        return false;

        //    if(Expression is Int16 || Expression is Int32 || Expression is Int64 || Expression is Decimal || Expression is Single || Expression is Double || Expression is Boolean)
        //        return true;

        //    try
        //    {
        //        if(Expression is string)
        //            Double.Parse(Expression as string);
        //        else
        //            Double.Parse(Expression.ToString());
        //            return true;
        //        } catch {} // just dismiss errors but return false
        //        return false;
        //    }
        //}

        public string saveStatus(string message, ref string status)
        {//"AONAON" or "AOFFAOFF" or "AON" or "AOFF"
            //statusMessage = first occurance of "AON"
            try
            {
                if (message.Length < 3)
                {
                    Logging.LogMessageToFile(this.ToString() + "-" + "message not okay => " + message, "ALL");
                    return(message);
                }

                string commandOn  = firstDeviceGroup.ToString() + "ON";
                string commandOff = firstDeviceGroup.ToString() + "OFF";

                if (StringHandler.Left(message, 0, 3) == commandOn)
                {
                    status = "ON";
                    //Debug.Print("Status = " + status);
                    return(message.Substring(3, message.Length - 3));
                }
                if (StringHandler.Left(message, 0, 4) == commandOff)
                {
                    status = "OFF";
                    //Debug.Print("Status = " + status);
                    return(message.Substring(4, message.Length - 4));
                }
                Logging.LogMessageToFile(this.ToString() + " - saveStatus - " + "error in message " + message + "[Should be A01A01AONAON for example]", "ALL");
                return("");
            }
            catch (Exception e)
            {
                Logging.LogMessageToFile(this.ToString() + " saveStatus - Catch " + e.Message, "ALL");
                return("");
            }
        }
Esempio n. 2
0
 public string Group()
 {
     try
     {
         if (address.Length > 0)
         {
             return(StringHandler.Left(address, 0, 1));
         }
         else
         {
             return("");
         }
     }
     catch
     {
         return("");
     }
 }
Esempio n. 3
0
 private string saveAddress(string message, ref string completeAddress) //receives full message without protocol => A01........
 {
     try
     {
         if (message.Length > 2)
         {
             int adresGroup = message[0];
             int adresTens  = message[1];
             int adresOnes  = message[2];
             if (adresTens > 47 && adresTens < 58 && adresOnes > 47 && adresOnes < 58 && adresGroup > 64 && adresGroup < 81)
             {//format checks out [A-P][0-1][0-9]
                 firstDeviceNumber = Convert.ToInt16(StringHandler.Left(message, 1, 2));
                 if (firstDeviceNumber < 16)
                 {
                     firstDeviceGroup = message[0]; //to be used with status analyzing
                     completeAddress  = StringHandler.Left(message, 0, 3);
                     //Debug.Print("Address = " + completeAddress);
                 }
             }
             if (message.Length > 3)
             {
                 return(message.Substring(3, message.Length - 3)); //return the remainder of the message
             }
             else
             {
                 return("");
             }
         }
         else
         {
             Logging.LogMessageToFile(this.ToString() + "-" + "message is not correct => " + message, "ALL");
             return("");
         }
     }
     catch (Exception e)
     {
         Logging.LogMessageToFile(this.ToString() + "-" + e.Message, "ALL");
         return("");
     }
 }