public static bool LoadFromFile(string fileName, out Diary obj)
 {
     System.Exception exception = null;
     return(LoadFromFile(fileName, out obj, out exception));
 }
 private void WindowLoaded(object sender, RoutedEventArgs e)
 {
     _diary = Diary.LoadFromFile("Diary.xml");
     dataGrid1.ItemsSource = _diary.Rec;
 }
 public static bool Deserialize(string xml, out Diary obj)
 {
     System.Exception exception = null;
     return(Deserialize(xml, out obj, out exception));
 }
 private void WindowLoaded(object sender, RoutedEventArgs e)
 {
     _diary = Diary.LoadFromFile("Diary.xml");
     dataGrid1.ItemsSource = _diary.Rec;
 }
예제 #5
0
        public static void UploadDiary(Diary diary)
        {
            //  DiaryWriteRecord = 0xbd,
            // Options = 0 (3-8 бит - номер ячейки)
            // Запись первой части данных в ячейку (статус и настройки)
            // 0 - Статус
            // 1 - вид
            // 2,3,4 год(от 12 года), мес, день
            // 5, 6 - время

            //  DiaryWriteRecord = 0xbd,
            // Options = 1 (3-8 бит - номер ячейки)
            // Запись второй части данных (текст)

            byte[] bytes, crc;

            for (var i = 0; i < 13 && i < diary.Rec.Count; i++)//!diary.Rec.Count
            {
                bytes = new byte[12];

                bytes[0]  = BtMessage.Start;
                bytes[1]  = (byte)(bytes.Length + 2); // length
                bytes[2]  = (byte)BtMessage.Message.DiaryWriteRecord;
                bytes[3]  = (byte)i;
                bytes[4]  = (byte)diary.Rec[i].Status;
                bytes[5]  = (byte)diary.Rec[i].Alarm;
                bytes[6]  = (byte)(diary.Rec[i].DateTime.Year - 1900);
                bytes[7]  = (byte)(diary.Rec[i].DateTime.Month);
                bytes[8]  = (byte)(diary.Rec[i].DateTime.Day);
                bytes[9]  = (byte)(diary.Rec[i].DateTime.DayOfWeek);
                bytes[10] = (byte)(diary.Rec[i].DateTime.Hour);
                bytes[11] = (byte)(diary.Rec[i].DateTime.Minute);

                crc = Crc(bytes);

                MetaWatchService.inputOutputStream.Write(bytes, 0, bytes.Length);
                MetaWatchService.inputOutputStream.Write(crc, 0, crc.Length);

                Thread.Sleep(200);
                // Запись текста
                bytes = new byte[27];

                bytes[0] = BtMessage.Start;
                bytes[1] = (byte)(bytes.Length + 2); // length
                bytes[2] = (byte)BtMessage.Message.DiaryWriteRecord;
                bytes[3] = (byte)(0x80 | (byte)i);

                //var encoding = new ASCIIEncoding();
                var tmpTxt       = diary.Rec[i].Value.Trim().ToUpper();
                var messageBytes = Encoding.GetEncoding(1251).GetBytes(tmpTxt); //encoding.GetBytes(diary.Rec[i].Value);
                for (var j = 0; j < 21 && j < messageBytes.Length; j++)
                {
                    bytes[4 + j] = messageBytes[j];
                }

                crc = Crc(bytes);

                MetaWatchService.inputOutputStream.Write(bytes, 0, bytes.Length);
                MetaWatchService.inputOutputStream.Write(crc, 0, crc.Length);
                Thread.Sleep(200);


                /*bytes = new byte[12];
                 *
                 * bytes[0] = BtMessage.Start;
                 * bytes[1] = (byte)(bytes.Length + 2); // length
                 * bytes[2] = (byte)BtMessage.Message.DiaryWriteRecord;
                 * bytes[3] = (byte)(i + 1);
                 * bytes[4] = (byte)diary.Rec[i + 1].Status;
                 * bytes[5] = (byte)diary.Rec[i + 1].Alarm;
                 * bytes[6] = (byte)(diary.Rec[i + 1].DateTime.Year - 2012);
                 * bytes[7] = (byte)(diary.Rec[i + 1].DateTime.Month);
                 * bytes[8] = (byte)(diary.Rec[i + 1].DateTime.Day);
                 * bytes[9] = (byte)(diary.Rec[i + 1].DateTime.DayOfWeek);
                 * bytes[10] = (byte)(diary.Rec[i + 1].DateTime.Hour);
                 * bytes[11] = (byte)(diary.Rec[i + 1].DateTime.Minute);
                 *
                 * crc = Crc(bytes);
                 *
                 * MetaWatchService.inputOutputStream.Write(bytes, 0, bytes.Length);
                 * MetaWatchService.inputOutputStream.Write(crc, 0, crc.Length);
                 */
            }

            bytes = new byte[7];

            bytes[0] = BtMessage.Start;
            bytes[1] = (byte)(bytes.Length + 2); // length
            bytes[2] = (byte)BtMessage.Message.DiaryWriteEnd;
            bytes[3] = 0;

            crc = Crc(bytes);

            MetaWatchService.inputOutputStream.Write(bytes, 0, bytes.Length);
            MetaWatchService.inputOutputStream.Write(crc, 0, crc.Length);
        }
예제 #6
0
        public static void UploadDiary(Diary diary)
        {
            //  DiaryWriteRecord = 0xbd,
            // Options = 0 (3-8 бит - номер ячейки)
            // Запись первой части данных в ячейку (статус и настройки)
            // 0 - Статус
            // 1 - вид
            // 2,3,4 год(от 12 года), мес, день
            // 5, 6 - время

            //  DiaryWriteRecord = 0xbd,
            // Options = 1 (3-8 бит - номер ячейки)
            // Запись второй части данных (текст)

            byte[] bytes, crc;

            for (var i = 0; i < 13 && i < diary.Rec.Count; i++)//!diary.Rec.Count
            {
            bytes = new byte[12];

            bytes[0] = BtMessage.Start;
            bytes[1] = (byte)(bytes.Length + 2); // length
            bytes[2] = (byte)BtMessage.Message.DiaryWriteRecord;
            bytes[3] = (byte) i;
            bytes[4] = (byte) diary.Rec[i].Status;
            bytes[5] = (byte) diary.Rec[i].Alarm;
            bytes[6] = (byte) (diary.Rec[i].DateTime.Year - 1900);
            bytes[7] = (byte) (diary.Rec[i].DateTime.Month);
            bytes[8] = (byte) (diary.Rec[i].DateTime.Day);
            bytes[9] = (byte) (diary.Rec[i].DateTime.DayOfWeek);
            bytes[10] = (byte) (diary.Rec[i].DateTime.Hour);
            bytes[11] = (byte) (diary.Rec[i].DateTime.Minute);

            crc = Crc(bytes);

            MetaWatchService.inputOutputStream.Write(bytes, 0, bytes.Length);
            MetaWatchService.inputOutputStream.Write(crc, 0, crc.Length);

            Thread.Sleep(200);
            // Запись текста
            bytes = new byte[27];

            bytes[0] = BtMessage.Start;
            bytes[1] = (byte)(bytes.Length + 2); // length
            bytes[2] = (byte)BtMessage.Message.DiaryWriteRecord;
            bytes[3] = (byte) (0x80 | (byte)i);

            //var encoding = new ASCIIEncoding();
            var tmpTxt = diary.Rec[i].Value.Trim().ToUpper();
            var messageBytes = Encoding.GetEncoding(1251).GetBytes(tmpTxt); //encoding.GetBytes(diary.Rec[i].Value);
            for (var j = 0; j < 21 && j < messageBytes.Length; j++)
            {
                bytes[4 + j] = messageBytes[j];
            }

            crc = Crc(bytes);

            MetaWatchService.inputOutputStream.Write(bytes, 0, bytes.Length);
            MetaWatchService.inputOutputStream.Write(crc, 0, crc.Length);
            Thread.Sleep(200);

            /*bytes = new byte[12];

            bytes[0] = BtMessage.Start;
            bytes[1] = (byte)(bytes.Length + 2); // length
            bytes[2] = (byte)BtMessage.Message.DiaryWriteRecord;
            bytes[3] = (byte)(i + 1);
            bytes[4] = (byte)diary.Rec[i + 1].Status;
            bytes[5] = (byte)diary.Rec[i + 1].Alarm;
            bytes[6] = (byte)(diary.Rec[i + 1].DateTime.Year - 2012);
            bytes[7] = (byte)(diary.Rec[i + 1].DateTime.Month);
            bytes[8] = (byte)(diary.Rec[i + 1].DateTime.Day);
            bytes[9] = (byte)(diary.Rec[i + 1].DateTime.DayOfWeek);
            bytes[10] = (byte)(diary.Rec[i + 1].DateTime.Hour);
            bytes[11] = (byte)(diary.Rec[i + 1].DateTime.Minute);

            crc = Crc(bytes);

            MetaWatchService.inputOutputStream.Write(bytes, 0, bytes.Length);
            MetaWatchService.inputOutputStream.Write(crc, 0, crc.Length);
            */
            }

            bytes = new byte[7];

            bytes[0] = BtMessage.Start;
            bytes[1] = (byte)(bytes.Length + 2); // length
            bytes[2] = (byte)BtMessage.Message.DiaryWriteEnd;
            bytes[3] = 0;

            crc = Crc(bytes);

            MetaWatchService.inputOutputStream.Write(bytes, 0, bytes.Length);
            MetaWatchService.inputOutputStream.Write(crc, 0, crc.Length);
        }
 public static bool LoadFromFile(string fileName, out Diary obj)
 {
     System.Exception exception = null;
     return LoadFromFile(fileName, out obj, out exception);
 }
 /// <summary>
 /// Deserializes xml markup from file into an Diary object
 /// </summary>
 /// <param name="fileName">string xml file to load and deserialize</param>
 /// <param name="obj">Output Diary object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool LoadFromFile(string fileName, out Diary obj, out System.Exception exception)
 {
     exception = null;
     obj = default(Diary);
     try
     {
         obj = LoadFromFile(fileName);
         return true;
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return false;
     }
 }
 public static bool Deserialize(string xml, out Diary obj)
 {
     System.Exception exception = null;
     return Deserialize(xml, out obj, out exception);
 }
 /// <summary>
 /// Deserializes workflow markup into an Diary object
 /// </summary>
 /// <param name="xml">string workflow markup to deserialize</param>
 /// <param name="obj">Output Diary object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool Deserialize(string xml, out Diary obj, out System.Exception exception)
 {
     exception = null;
     obj = default(Diary);
     try
     {
         obj = Deserialize(xml);
         return true;
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return false;
     }
 }