void ReaderCE_OnAccessCompleted(object sender, CSLibrary.Events.OnAccessCompletedEventArgs e)
 {
     switch (e.access)
     {
         case TagAccess.WRITE:
             if (e.success && e.bank == Bank.EPC)
             {
                 //Increase tag count
                 currentCount++;
                 txtSuccessTag.Text = currentCount.ToString();
                 if (currentCount == nbCount.Value)
                 {
                     ThreadStop();
                 }
             }
             break;
         case TagAccess.READ:
             if (e.success && e.bank == Bank.EPC)
             {
                 Debug.WriteLine("EPC = " + e.data.ToString());
             }
             else
             {
                 Debug.WriteLine(string.Format("Read {0} error", e.bank));
             }
             break;
     }
 }
        public string ExportLibraryCSL(string[] libnames, string directory, string name)
        {
            try
            {
                var oneLibToSerialize = new CSLibrary();
                foreach (var n in libnames)
                {
                    oneLibToSerialize.Merge(Library.getFromSpecificLibrary(n));
                }

                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }
                var filePath = Path.Combine(directory, name + ".csl");

                using (FileStream fileStream = File.Create(filePath))
                {
                    Serializer.Serialize(fileStream, oneLibToSerialize);
                }

                return("Library written to " + filePath);
            }
            catch (Exception e) {
                return("Export failed " + e.Message);
            }
        }
        //public void Update()
        //{
        //    Stopwatch sp = new Stopwatch();
        //    sp.Start();
        //    Library.Clear();
        //    //foreach (var l in this.DefaultLibraries)
        //    //{
        //    //    this.Library.Append(l);
        //    //}
        //    //foreach (var l in this.UserLibraries)
        //    //{
        //    //    this.Library.Append(l);
        //    //}
        //    sp.Stop();
        //    Debug.WriteLine("Update library: " + sp.ElapsedMilliseconds + "ms");
        //}

        public string ImportUserLibraryCSV(string Directory)
        {
            string    name        = Path.GetFileName(Directory);
            CSLibrary importedLib = null;

            try
            {
                importedLib = CSV.CSVImportExport.ImportLibrary(Directory);
            }
            catch {
            }
            if (importedLib != null)
            {
                try
                {
                    importedLib.Name      = name;
                    importedLib.IsLocked  = true;
                    importedLib.IsDefault = true;
                    importedLib.applyLibName(name);
                    importedLib.applyLock(false);
                    importedLib.applyIsDefault(false);
                    this.Library.Merge(importedLib);
                    this.UserLibraries.Add(importedLib);

                    return("Library merged from " + Directory);
                }
                catch { return("Library could not be imported"); }
            }
            else
            {
                return("Library could not be imported");
            }
        }
예제 #4
0
        public MainWindow()
        {
            InitializeComponent();

            Library = LibraryDefaults.GetDefaultLibrary();

            ErrorTextBox.Text = "Default Library generated" + Library.TimeStamp;
        }
 static void RFID_OnAsyncCall(object sender, CSLibrary.Events.OnAsyncCallbackEventArgs e)
 {
     switch (e.type)
     {
         case CallbackType.TAG_RANGING:
             Logger.WriteLine(String.Format("PC-EPC = {0}, {1}", e.info.epc, e.info.pc));
             break;
     }
 }
 static void RFID_OnAsyncCall(object sender, CSLibrary.Events.OnAsyncCallbackEventArgs e)
 {
     switch (e.type)
     {
         case CallbackType.TAG_INVENTORY:
         case CallbackType.TAG_SEARCHING:
             Logger.WriteLine(string.Format("PC-EPC = {0}-{1}", e.info.pc.ToString(), e.info.epc.ToString()));
             break;
     }
 }
 void ReaderCE_OnStateChanged(object sender, CSLibrary.Events.OnStateChangedEventArgs e)
 {
     switch (e.state)
     {
         case RFState.IDLE:
             //
             //Device.MelodyPlay(RingTone.T1, BuzzerVolume.HIGH);
             break;
         case RFState.BUSY:
             btnStop.Enabled = true;
             break;
     }
 }
        public CSLibrary getAllLibraryReferences(CSLibrary library)
        {
            var newLib = new CSLibrary();

            newLib.Add(library.getElementByName <CSOpaqueConstruction>(this.Materials.RoofConstruction));
            newLib.Add(library.getElementByName <CSOpaqueConstruction>(this.Materials.FacadeConstruction));
            newLib.Add(library.getElementByName <CSOpaqueConstruction>(this.Materials.SlabConstruction));
            newLib.Add(library.getElementByName <CSOpaqueConstruction>(this.Materials.PartitionConstruction));
            newLib.Add(library.getElementByName <CSOpaqueConstruction>(this.Materials.GroundConstruction));
            newLib.Add(library.getElementByName <CSOpaqueConstruction>(this.Materials.InternalMassConstruction));


            HashSet <string> List_usedYearSchedules = new HashSet <string>();


            // add zone schedules
            List_usedYearSchedules.Add(this.Loads.OccupancySchedule);
            List_usedYearSchedules.Add(this.Loads.AirspeedSchedule);
            List_usedYearSchedules.Add(this.Conditioning.MechVentSchedule);
            List_usedYearSchedules.Add(this.Ventilation.ScheduledVentilationSchedule);
            List_usedYearSchedules.Add(this.DomHotWater.WaterSchedule);
            List_usedYearSchedules.Add(this.Loads.LightsAvailibilitySchedule);
            List_usedYearSchedules.Add(this.Loads.EquipmentAvailibilitySchedule);
            List_usedYearSchedules.Add(this.Ventilation.NatVentSchedule);
            List_usedYearSchedules.Add(this.Conditioning.HeatingSchedule);
            List_usedYearSchedules.Add(this.Conditioning.CoolingSchedule);
            List_usedYearSchedules.Add(this.Conditioning.HeatingSetpointSchedule);
            List_usedYearSchedules.Add(this.Conditioning.CoolingSetpointSchedule);


            foreach (string s in List_usedYearSchedules.ToList())
            {
                if (string.IsNullOrWhiteSpace(s))
                {
                    continue;
                }
                // check if year schedule is not array schedule
                if (library.YearSchedules.Any(o => o.Name == s))
                {
                    var ys = library.YearSchedules.First(o => o.Name == s);
                    newLib.Add(ys);
                }
                else if (library.ArraySchedules.Any(o => o.Name == s))
                {
                    newLib.Add(library.ArraySchedules.First(o => o.Name == s));
                }
            }

            return(newLib);
        }
        public void InitializeOrClear()
        {
            var culture = Thread.CurrentThread.CurrentCulture;

            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); // use US culture
            var fullDefault = LibraryDefaults.GetDefaultLibrary();

            DefaultLibraries = new List <CSLibrary>();
            UserLibraries    = new List <CSLibrary>();
            DefaultLibraries.Add(fullDefault);  //add hardcoded minimum default lib
            UserLibraries.Add(new CSLibrary()); //add blank user library
            Library = new CSLibrary();
            Library.Append(fullDefault);
            Thread.CurrentThread.CurrentCulture = culture; // set it back
        }
        void ReaderXP_OnAsyncCallback(object sender, CSLibrary.Events.OnAsyncCallbackEventArgs e)
        {
            //Using asyn delegate to update UI
            if (e.type == CallbackType.TAG_RANGING)
            {
                m_totaltag++;

                UpdateRecords(e.info);
                //20090219,18:00:44,1000-0000-0000-0000-0000-0688 
                //YYYYMMDD,HH:MM:SS,Tag ID(24byte)

                //Program.tagDataLogSw.WriteLine(string.Format("{0},{1}", DateTime.Now.ToString("yyyymmdd,hh:MM:ss"), BitConverter.ToString(e.info.epc.ToBytes())));
                //SaveTagData(string.Format("{0},{1}", DateTime.Now.ToString("yyyyMMdd,hh:mm:ss"), BitConverter.ToString(e.info.epc.ToBytes())));
            }
        }
        public CSLibrary getAllLibraryReferences(CSLibrary library)
        {
            var newLib = new CSLibrary();

           

            if (library.GlazingConstructions.Any(o => o.Name == this.Construction))
            {
                var ys = library.GlazingConstructions.First(o => o.Name == this.Construction);
                newLib.Add(ys);
            }
            else if (library.GlazingConstructionsSimple.Any(o => o.Name == this.Construction))
            {
                newLib.Add(library.GlazingConstructionsSimple.First(o => o.Name == this.Construction));
            }


            HashSet<string> List_usedYearSchedules = new HashSet<string>();


            // add zone schedules
            List_usedYearSchedules.Add(this.ShadingSystemAvailibilitySchedule);
            List_usedYearSchedules.Add(this.ZoneMixingAvailibilitySchedule);
            List_usedYearSchedules.Add(this.AFN_WIN_AVAIL);
        


            foreach (string s in List_usedYearSchedules.ToList())
            {
                if (string.IsNullOrWhiteSpace(s))
                {
                    continue;
                }
                // check if year schedule is not array schedule 
                if (library.YearSchedules.Any(o => o.Name == s))
                {
                    var ys = library.YearSchedules.First(o => o.Name == s);
                    newLib.Add(ys);
                }
                else if (library.ArraySchedules.Any(o => o.Name == s))
                {
                    newLib.Add(library.ArraySchedules.First(o => o.Name == s));
                }
            }

            return newLib;
        }
 void HotKeys_OnKeyEvent(CSLibrary.HotKeys.Key KeyCode, bool KeyDown)
 {
     if (!KeyDown)
     {
         switch (KeyCode)
         {
             case CSLibrary.HotKeys.Key.F1:
                 AttachCallback(false);
                 using (ReaderInfomation info = new ReaderInfomation())
                 {
                     info.ShowDialog();
                 }
                 AttachCallback(true);
                 break;
         }
     }
 }
 void ReaderXP_TagCompletedEvent(object sender, CSLibrary.Events.OnAccessCompletedEventArgs e)
 {
     if (e.access == TagAccess.READ)
     {
         switch (e.bank)
         {
             case Bank.ACC_PWD:
                 if (e.success)
                 {
                     UpdateBankInfo(e.bank, Program.ReaderXP.Options.TagReadAccPwd.password.ToString());
                 }
                 break;
             case Bank.EPC:
                 if (e.success)
                 {
                     UpdateBankInfo(e.bank, Program.ReaderXP.Options.TagReadEPC.epc.ToString());
                 }
                 break;
             case Bank.KILL_PWD:
                 if (e.success)
                 {
                     UpdateBankInfo(e.bank, Program.ReaderXP.Options.TagReadKillPwd.password.ToString());
                 }
                 break;
             case Bank.PC:
                 if (e.success)
                 {
                     UpdateBankInfo(e.bank, Program.ReaderXP.Options.TagReadPC.pc.ToString());
                 }
                 break;
             case Bank.TID:
                 if (e.success)
                 {
                     UpdateBankInfo(e.bank, Program.ReaderXP.Options.TagReadTid.tid.ToString());
                 }
                 break;
             case Bank.USER:
                 if (e.success)
                 {
                     UpdateBankInfo(e.bank, Program.ReaderXP.Options.TagReadUser.pData.ToString());
                 }
                 break;
         }
     }
 }
        static void RFID_OnCompleted(object sender, CSLibrary.Events.OnAccessCompletedEventArgs e)
        {
            switch (e.access)
            {
                case TagAccess.READ:
                case TagAccess.WRITE:
#if CSV
                    Logger.WriteLine(string.Format("{0},{1},{2},{3}",
                                           e.access,
                                           e.bank,
                                           e.success ? "OK" : "FAILED",
                                           e.data.ToString()
                                           ));
#else
                    Logger.WriteLine(string.Format("{0} {1} bank, Result = {2}, Data = {3}",
                       e.access,
                       e.bank,
                       e.success ? "OK" : "FAILED",
                       e.data.ToString()
                       ));
#endif
                    break;
                case TagAccess.LOCK:
                case TagAccess.KILL:
                case TagAccess.ERASE:
#if CSV
                    Logger.WriteLine(string.Format("{0},{1},{2}",
                                e.access,
                                e.bank,
                                e.success ? "OK" : "FAILED"
                                ));
#else
                    Logger.WriteLine(string.Format("{0} {1} bank, Result = {2}",
                                e.access,
                                e.bank,
                                e.success ? "OK" : "FAILED"
                                ));
#endif
                    break;
            }
        }
 void ReaderXP_StateChangedEvent(object sender, CSLibrary.Events.OnStateChangedEventArgs e)
 {
     switch (e.state)
     {
         case RFState.IDLE:
             if (!m_stop)
             {
                 EnableButton(true);
                 EnableForm(true);
             }
             else
             {
                 CloseForm();
             }
             break;
         case RFState.BUSY:
             EnableButton(false);
             break;
         case RFState.ABORT:
             EnableForm(false);
             break;
     }
 }
        public string ExportLibraryCSV(string[] libnames, string directory, string name)
        {
            try
            {
                var oneLibToSerialize = new CSLibrary();
                foreach (var n in libnames)
                {
                    oneLibToSerialize.Merge(Library.getFromSpecificLibrary(n));
                }

                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }
                var filePath = Path.Combine(directory, name);

                CSV.CSVImportExport.ExportLibrary(oneLibToSerialize, filePath);

                return("Library written to " + filePath);
            }
            catch (Exception e) {
                return("Export failed " + e.Message);
            }
        }
 static void RFID_OnCompleted(object sender, CSLibrary.Events.OnAccessCompletedEventArgs e)
 {
     throw new Exception("The method or operation is not implemented.");
 }
        static void RFID_OnChanged(object sender, CSLibrary.Events.OnStateChangedEventArgs e)
        {

        }
예제 #19
0
 void ReaderCE_StateChangedEvent(object sender, CSLibrary.Events.OnStateChangedEventArgs e)
 {
     Invoke((System.Threading.ThreadStart)delegate()
     {
         switch (e.state)
         {
             case RFState.IDLE:
                 EnableUpdate(false);
                 if (!m_stop)
                 {
                     m_totaltag = 0;
                     Device.MelodyPlay(RingTone.T1, BuzzerVolume.HIGH);
                     EnableForm(true);
                     RefreshListView();
                 }
                 else
                 {
                     CloseForm();
                 }
                 break;
             case RFState.BUSY:
                 EnableUpdate(true);
                 Device.MelodyPlay(RingTone.T2, BuzzerVolume.HIGH);
                 timeStarted = CSLibrary.Tools.DateTimeEx.Now;
                 break;
             case RFState.ABORT:
                 EnableForm(false);
                 break;
             case RFState.RESET:
                 EnableUpdate(false);
                 Program.ReaderCE.Reconnect(10);
                 Program.ReaderCE.StartOperation(Operation.TAG_INVENTORY, Program.appSetting.Cfg_blocking_mode);
                 EnableUpdate(true);
                 break;
         }
     });
 }
예제 #20
0
        void ReaderCE_TagInventoryEvent(object sender, CSLibrary.Events.OnAsyncCallbackEventArgs e)
        {
            Invoke((System.Threading.ThreadStart)delegate()
            {
                //Using asyn delegate to update UI
                if (e.type == CallbackType.TAG_INVENTORY)
                {
                    m_totaltag++;

                    UpdateRecords(e.info);

                    if (Program.appSetting.Cfg_blocking_mode)
                    {
                        Application.DoEvents();
                    }

                    //btn_start.BackColor = Color.FromArgb(0, 192, 0);
                    //btn_start.Text = "Start";
                    //bToggleStartButton = false;
                    //btn_clear.Enabled = btn_exit.Enabled = btn_save.Enabled = cb_sorting.Enabled = true;
                    //startMenu1_OnButtonClick(ButtonClickType.Stop);
                    //Stop();
                }
            });
        }
예제 #21
0
        public static CSOpaqueConstruction QuickConstruction(string name, ConstructionCategory type, string[] layers, double[] thickness, string category, string source, ref CSLibrary Library)
        {
            CSOpaqueConstruction oc = new CSOpaqueConstruction();

            for (int i = 0; i < layers.Length; i++)
            {
                try
                {
                    if (thickness.Length != layers.Length)
                    {
                        continue;
                    }
                    if (!(thickness[i] > 0))
                    {
                        continue;
                    }

                    if (Library.OpaqueMaterials.Any(x => x.Name == layers[i]))
                    {
                        var mat = Library.OpaqueMaterials.First(o => o.Name == layers[i]);
                        Layer <CSOpaqueMaterial> layer = new Layer <CSOpaqueMaterial>(thickness[i], mat);
                        oc.Layers.Add(layer);
                    }
                    else
                    {
                        Debug.WriteLine("ERROR: " + "Could not find " + layers[i]);
                        Logger.WriteLine("ERROR: " + "Could not find " + layers[i]);
                        return(null);
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                }
            }

            oc.Name       = name;
            oc.Type       = type;
            oc.Category   = category;
            oc.DataSource = source;


            Library.Add(oc);
            return(oc);
        }
예제 #22
0
        public static CSYearSchedule QuickSchedule(string Name, double[] dayArray, double[] weArray, ScheduleType type, string category, string dataSource, ref CSLibrary Library)
        {
            //int[] MonthFrom = { 1 };
            //int[] DayFrom = { 1 };
            //int[] MonthTo = { 12 };
            //int[] DayTo = { 31 };

            CSDaySchedule someDaySchedule = new CSDaySchedule(Name, type, dayArray.ToList());

            someDaySchedule.DataSource = dataSource;
            someDaySchedule.Category   = category;
            someDaySchedule            = Library.Add(someDaySchedule);

            CSDaySchedule weSchedule = new CSDaySchedule(Name + "WeekEnd", type, weArray.ToList());

            weSchedule.DataSource = dataSource;
            weSchedule.Category   = category;
            weSchedule            = Library.Add(weSchedule);

            CSDaySchedule[] daySchedulesArray = { someDaySchedule, someDaySchedule, someDaySchedule, someDaySchedule, someDaySchedule, weSchedule, weSchedule };
            WeekSchedule    someWeekSchedule  = new WeekSchedule(daySchedulesArray, new DateTime(2006, 1, 1), new DateTime(2006, 12, 31));

            //someWeekSchedule.DataSource = dataSource;
            //someWeekSchedule.Category = category;
            //someWeekSchedule = Library.Add(someWeekSchedule);

            WeekSchedule[] weekSchedulesArray = { someWeekSchedule };
            CSYearSchedule someYearSchedule   = new CSYearSchedule(Name, type, weekSchedulesArray.ToList()); //, MonthFrom.ToList(), DayFrom.ToList(), MonthTo.ToList(), DayTo.ToList()

            someYearSchedule.DataSource = dataSource;
            someYearSchedule.Category   = category;

            Library.Add(someYearSchedule);
            return(someYearSchedule);
        }
        void ReaderCE_TagInventoryEvent(object sender, CSLibrary.Events.OnAsyncCallbackEventArgs e)
        {
            //Using asyn delegate to update UI
            if (e.type == CallbackType.TAG_INVENTORY)
            {
                //Device.BuzzerOn(2000, 40, BuzzerVolume.HIGH);

                UpdateRecords(e.info);
            }
        }
 void ntpClient_OnSyncStateChangedNotify(CSLibrary.Tools.TimeSync.SyncState state)
 {
     switch (state)
     {
         case CSLibrary.Tools.TimeSync.SyncState.DNSResolve:
             ts_status.Text = "Resolving remote server address...";
             btn_startSync.Enabled = false;
             break;
         case CSLibrary.Tools.TimeSync.SyncState.Idle:
             ts_status.Text = "Idle";
             btn_startSync.Text = "Time Sync";
             btn_startSync.BackColor = Color.FromArgb(0, 192, 0);
             btn_startSync.Enabled = true;
             break;
         case CSLibrary.Tools.TimeSync.SyncState.Connect:
             ts_status.Text = "Connecting...";
             btn_startSync.Text = "Sync Stop";
             btn_startSync.BackColor = Color.Red;
             btn_startSync.Enabled = false;
             break;
         case CSLibrary.Tools.TimeSync.SyncState.Request:
             ts_status.Text = "Sending request...";
             btn_startSync.Text = "Sync Stop";
             btn_startSync.BackColor = Color.Red;
             btn_startSync.Enabled = true;
             break;
         case CSLibrary.Tools.TimeSync.SyncState.WaitResponse:
             ts_status.Text = "Waiting for response...";
             btn_startSync.Text = "Sync Stop";
             btn_startSync.BackColor = Color.Red;
             btn_startSync.Enabled = true;
             break;
     }
 }
        public static void ExportLibrary(CSLibrary lib, string folderPath)
        {
            //folderPath += @"\ClimateStudioLibrary-" + lib.TimeStamp.Year + "-" + lib.TimeStamp.Month + "-" + lib.TimeStamp.Day + "-" + lib.TimeStamp.Hour + "-" + lib.TimeStamp.Minute;

            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }


            //Schedules
            if (!FilesAndFolders.IsFileLocked(new FileInfo(folderPath + @"\DaySchedules_Old.csv")))
            {
                writeDayCSV(folderPath + @"\DaySchedules_Old.csv", lib.DaySchedules.ToList());
            }
            if (!FilesAndFolders.IsFileLocked(new FileInfo(folderPath + @"\DaySchedules.csv")))
            {
                writeLibCSV <CSDaySchedule>(folderPath + @"\DaySchedules.csv", lib.DaySchedules.ToList());
            }

            if (!FilesAndFolders.IsFileLocked(new FileInfo(folderPath + @"\YearSchedules.csv")))
            {
                writeYearCSV(folderPath + @"\YearSchedules.csv", lib.YearSchedules.ToList());
            }

            if (!FilesAndFolders.IsFileLocked(new FileInfo(folderPath + @"\ArraySchedules.csv")))
            {
                writeArrayScheduleCSV(folderPath + @"\ArraySchedules.csv", lib.ArraySchedules.ToList());
            }

            //Material Construction

            if (!FilesAndFolders.IsFileLocked(new FileInfo(folderPath + @"\OpaqueMaterials.csv")))
            {
                writeLibCSV <CSOpaqueMaterial>(folderPath + @"\OpaqueMaterials.csv", lib.OpaqueMaterials.ToList());
            }

            if (!FilesAndFolders.IsFileLocked(new FileInfo(folderPath + @"\OpaqueConstructions_Old.csv")))
            {
                writeOpaqueConstructionsCSV(folderPath + @"\OpaqueConstructions_Old.csv", lib.OpaqueConstructions.ToList());
            }

            if (!FilesAndFolders.IsFileLocked(new FileInfo(folderPath + @"\OpaqueConstructions.csv")))
            {
                writeLibCSV <CSOpaqueConstruction>(folderPath + @"\OpaqueConstructions.csv", lib.OpaqueConstructions.ToList());
            }


            //Glazing
            if (!FilesAndFolders.IsFileLocked(new FileInfo(folderPath + @"\GlazingMaterials.csv")))
            {
                writeLibCSV <CSGlazingMaterial>(folderPath + @"\GlazingMaterials.csv", lib.GlazingMaterials.ToList());
            }

            if (!FilesAndFolders.IsFileLocked(new FileInfo(folderPath + @"\GasMaterials.csv")))
            {
                writeLibCSV <CSGasMaterial>(folderPath + @"\GasMaterials.csv", lib.GasMaterials.ToList());
            }


            if (!FilesAndFolders.IsFileLocked(new FileInfo(folderPath + @"\GlazingConstructions_Old.csv")))
            {
                writeGlazingConstructionsCSV(folderPath + @"\GlazingConstructions_Old.csv", lib.GlazingConstructions.ToList());
            }


            if (!FilesAndFolders.IsFileLocked(new FileInfo(folderPath + @"\GlazingConstructions.csv")))
            {
                writeLibCSV <CSGlazingConstruction>(folderPath + @"\GlazingConstructions.csv", lib.GlazingConstructions.ToList());
            }

            if (!FilesAndFolders.IsFileLocked(new FileInfo(folderPath + @"\GlazingConstructionSimple.csv")))
            {
                writeLibCSV <CSGlazingConstructionSimple>(folderPath + @"\GlazingConstructionSimple.csv", lib.GlazingConstructionsSimple.ToList());
            }

            //Settings
            if (!FilesAndFolders.IsFileLocked(new FileInfo(folderPath + @"\WindowSettings.csv")))
            {
                writeLibCSV <CSWindowDefinition>(folderPath + @"\WindowSettings.csv", lib.WindowSettings.ToList());
            }

            if (!FilesAndFolders.IsFileLocked(new FileInfo(folderPath + @"\ZoneVentilations.csv")))
            {
                writeLibCSV <CSZoneVentilation>(folderPath + @"\ZoneVentilations.csv", lib.ZoneVentilations.ToList());
            }

            if (!FilesAndFolders.IsFileLocked(new FileInfo(folderPath + @"\ZoneConditioning.csv")))
            {
                writeLibCSV <CSZoneConditioning>(folderPath + @"\ZoneConditioning.csv", lib.ZoneConditionings.ToList());
            }

            if (!FilesAndFolders.IsFileLocked(new FileInfo(folderPath + @"\ZoneConstruction.csv")))
            {
                writeLibCSV <CSZoneConstruction>(folderPath + @"\ZoneConstruction.csv", lib.ZoneConstructions.ToList());
            }

            if (!FilesAndFolders.IsFileLocked(new FileInfo(folderPath + @"\ZoneLoad.csv")))
            {
                writeLibCSV <CSZoneLoad>(folderPath + @"\ZoneLoad.csv", lib.ZoneLoads.ToList());
            }

            if (!FilesAndFolders.IsFileLocked(new FileInfo(folderPath + @"\DomHotWater.csv")))
            {
                writeLibCSV <CSZoneHotWater>(folderPath + @"\DomHotWater.csv", lib.DomHotWaters.ToList());
            }

            if (!FilesAndFolders.IsFileLocked(new FileInfo(folderPath + @"\ZoneDefinition.csv")))
            {
                // writeLibCSV<ZoneDefinition>(folderPath + @"\ZoneDefinition.csv", lib.ZoneDefinitions.ToList());
                writeZoneDefCSV(folderPath + @"\ZoneDefinition.csv", lib.ZoneDefinitions.ToList());
            }
        }
 void ReaderXP_OnCompleted(object sender, CSLibrary.Events.OnAccessCompletedEventArgs e)
 {
     if (e.access == TagAccess.KILL)
     {
         resultForm1.UpdateResult(e.success);
     }
 }
        void ReaderCE_TagSearchOneEvent(object sender, CSLibrary.Events.OnAsyncCallbackEventArgs e)
        {
            switch (e.type)
            {
                case CallbackType.TAG_SEARCHING:
                    rssi = (int)((TagCallbackInfo)e.info).rssi;

                    UpdateRssiLb(rssi.ToString());
                    //lb_rssi.Text = rssi.ToString();

                    UpdateProgressValue(rssi);

                    //Tone
                    EnToneTmr(true);

                    if (rssi < 0)
                        UpdateRssiLb(String.Empty);
                    else
                        RestartOORDetectTmr();

                    if (Program.appSetting.Cfg_blocking_mode)
                    {
                        Application.DoEvents();
                    }

                    break;
            }
        }
예제 #28
0
        void Reader_TagInventoryEvent(object sender, CSLibrary.Events.OnAsyncCallbackEventArgs e)
        {
            Invoke((System.Threading.ThreadStart)delegate()
            {
                UInt32 tid;

                try
                {
                    if (e.type == CallbackType.TAG_RANGING)
                    {
                        if (radioButton1.Checked) // EM4324
                        {
                            if (e.info.epc.GetLength() < e.info.pc.EPCLength + 3)
                                return;

                            tid = (UInt32)((e.info.epc.ToUshorts()[e.info.pc.EPCLength] << 16) | e.info.epc.ToUshorts()[e.info.pc.EPCLength + 1]);
                            if (tid != 0xe200b001U && tid != 0xe200b002U)
                                return;

                            EM4324Info (e.info);
                        }
                        else if (radioButton2.Checked)// EM4325
                        {
                            if (e.info.epc.GetLength() < e.info.pc.EPCLength + 6)
                                return;

                            tid = (UInt32)((e.info.epc.ToUshorts()[e.info.pc.EPCLength - 1] << 16) | e.info.epc.ToUshorts()[e.info.pc.EPCLength]) & 0xffffffc0U;
                            if (tid != 0xe280b040U)
                                return;

                            EM4325Info(e.info);
                        }
                        else
                            return;
                    }
                }
                catch (Exception ex)
                {
                }
            });
        }
예제 #29
0
 void Reader_StateChangedEvent(object sender, CSLibrary.Events.OnStateChangedEventArgs e)
 {
     Invoke((System.Threading.ThreadStart)delegate()
     {
         switch (e.state)
         {
             case RFState.IDLE:
                 break;
             case RFState.BUSY:
                 Device.MelodyPlay(RingTone.T2, BuzzerVolume.HIGH);
                 break;
             case RFState.ABORT:
                 break;
             case RFState.RESET:
                 break;
         }
     });
 }
 static void RFID_OnAsyncCall(object sender, CSLibrary.Events.OnAsyncCallbackEventArgs e)
 {
     throw new Exception("The method or operation is not implemented.");
 }
        private static List <CSZoneDefinition> readZoneDefCSV(string fp, CSLibrary Lib)
        {
            var records = new List <CSZoneDefinition>();

            if (!File.Exists(fp))
            {
                //Eto.Forms.MessageBox.Show(fp + " is missing!");
                return(records);
            }


            using (var reader = new StreamReader(fp))
                using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
                {
                    csv.Configuration.HasHeaderRecord   = true;
                    csv.Configuration.HeaderValidated   = null;
                    csv.Configuration.MissingFieldFound = null;
                    csv.Configuration.IgnoreBlankLines  = true;


                    csv.Read();
                    csv.ReadHeader();

                    while (csv.Read())
                    {
                        try
                        {
                            CSZoneDefinition record = new CSZoneDefinition();
                            record.Name = csv.GetField <string>("Name");

                            string loads         = csv.GetField <string>("Loads");
                            string cond          = csv.GetField <string>("Conditioning");
                            string vent          = csv.GetField <string>("Ventilation");
                            string hotwater      = csv.GetField <string>("HotWater");
                            string constructions = csv.GetField <string>("Constructions");

                            record.Loads        = Lib.ZoneLoads.First(x => x.Name == loads);
                            record.Conditioning = Lib.ZoneConditionings.First(x => x.Name == cond);
                            record.Ventilation  = Lib.ZoneVentilations.First(x => x.Name == vent);
                            record.DomHotWater  = Lib.DomHotWaters.First(x => x.Name == hotwater);
                            record.Materials    = Lib.ZoneConstructions.First(x => x.Name == constructions);

                            record.HeatingCO2      = csv.GetField <double>("HeatingCO2 [Kg/kWh]");
                            record.HeatingCost     = csv.GetField <double>("HeatingCost [$/kWh]");
                            record.CoolingCO2      = csv.GetField <double>("CoolingCO2 [Kg/kWh]");
                            record.CoolingCost     = csv.GetField <double>("CoolingCost [$/kWh]");
                            record.HotWaterCO2     = csv.GetField <double>("HowWaterCO2 [Kg/kWh]");
                            record.HotWaterCost    = csv.GetField <double>("HotWaterCost [$/kWh]");
                            record.ElectricityCO2  = csv.GetField <double>("ElectricityCO2 [Kg/kWh]");
                            record.ElectricityCost = csv.GetField <double>("ElectricityCost [$/kWh]");

                            string datasource = csv.GetField <string>("Data Source");
                            record.DataSource = datasource;

                            records.Add(record);
                        }
                        catch (Exception ex) { Debug.WriteLine(ex.Message); }
                    }
                }
            return(records);
        }
 void ReaderXP_OnStateChanged(object sender, CSLibrary.Events.OnStateChangedEventArgs e)
 {
     switch (e.state)
     {
         case RFState.BUSY:
             btn_startInventory.Enabled = false;
             btn_stopInventory.Enabled = true;
             break;
         case RFState.IDLE:
             bool someReaderReset = false;
             foreach (HighLevelInterface reader in Program.ReaderList)
             {
                 if (reader.LastResultCode == Result.NETWORK_RESET)
                 {
                     someReaderReset = true;
                     new Thread(new ThreadStart(Reset)).Start();
                 }
             }
             if (someReaderReset)
             {
                 btn_startInventory.Enabled = false;
                 btn_stopInventory.Enabled = true;
             }
             else
             {
                 btn_startInventory.Enabled = true;
                 btn_stopInventory.Enabled = false;
             }
             break;
         case RFState.RESET:
             break;
         case RFState.ABORT:
             break;
     }
 }
 void ReaderCE_OnStateChanged(object sender, CSLibrary.Events.OnStateChangedEventArgs e)
 {
     switch (e.state)
     {
         case CSLibrary.Constants.RFState.IDLE:
             if (!bStop)
             {
                 UpdateCWBtn(true);
             }
             else
             {
                 this.Close();
             }
             break;
         case CSLibrary.Constants.RFState.BUSY:
             UpdateCWBtn(false);
             break;
     }
 }
        public void LoadLibrariesFromDirectories()
        {
            Debug.WriteLine("LoadLibrariesFromDirectories");
            //------
            // DEFAULT LOCATION
            //------
            if (Directory.Exists(DefaultFilesAndDirectories.defaultLibPath))
            {
                //Binary Library Files
                var libFiles = Directory.GetFiles(DefaultFilesAndDirectories.defaultLibPath, "*.csl");
                foreach (var p in libFiles)
                {
                    Stopwatch sp = new Stopwatch();
                    sp.Start();
                    string name = Path.GetFileName(p).Replace(".csl", "");

                    CSLibrary importedLib = null;
                    using (FileStream fileStream = File.OpenRead(p))
                    {
                        importedLib = Serializer.Deserialize <CSLibrary>(fileStream);
                    }

                    importedLib.Name      = name;
                    importedLib.IsLocked  = true;
                    importedLib.IsDefault = true;
                    importedLib.applyLibName(name);
                    importedLib.applyLock(true);
                    importedLib.applyIsDefault(true);
                    this.DefaultLibraries.Add(importedLib);
                    this.Library.Append(importedLib);
                    sp.Stop();
                    Debug.WriteLine("Loading binary " + p + " - " + sp.ElapsedMilliseconds + "ms");
                }
            }

            //------
            // USER LOCATION
            //------
            if (Directory.Exists(DefaultFilesAndDirectories.userLibPath))
            {
                //Binary Library Files
                var libFiles = Directory.GetFiles(DefaultFilesAndDirectories.userLibPath, "*.csl");
                foreach (var p in libFiles)
                {
                    Stopwatch sp = new Stopwatch();
                    sp.Start();
                    string name = Path.GetFileName(p).Replace(".csl", "");

                    CSLibrary importedLib = null;
                    using (FileStream fileStream = File.OpenRead(p))
                    {
                        importedLib = Serializer.Deserialize <CSLibrary>(fileStream);
                    }

                    importedLib.Name      = name;
                    importedLib.IsLocked  = true;
                    importedLib.IsDefault = false;
                    importedLib.applyLibName(name);
                    importedLib.applyLock(true);
                    importedLib.applyIsDefault(false);
                    this.UserLibraries.Add(importedLib);
                    this.Library.Append(importedLib);
                    sp.Stop();
                    Debug.WriteLine("Loading binary " + p + " - " + sp.ElapsedMilliseconds + "ms");
                }
            }
        }
        protected void PaintCell(Graphics gx, ref RECT pCell_Rect, CSLibrary.Net.DeviceInfomation pEntry, uint entry_number)
        {
            // Make a copy of the passed cell rectangle
            RECT cell_rect = pCell_Rect;

            // Draw the cell border on top and bottom
            IntPtr hdc = gx.GetHdc();
            DrawEdge(hdc, ref cell_rect, EDGE_ETCHED, BF_TOP | BF_BOTTOM);
            gx.ReleaseHdc(hdc);
            //-----------------------
            // Set Background Color
            //-----------------------

            bool white_text = true;

            int r1 = 0xff, g1 = 0xFF, b1 = 0xFF; // Initialize to white 
            int r2 = 0xff, g2 = 0xff, b2 = 0xff; // Initial values should never be seen

            // Specify the Start and Stop color 
            switch (pEntry.mode)
            {

                case CSLibrary.Net.Mode.Bootloader: // Select Gold

                    r1 = 0xff; g1 = 0xff; b1 = 0x00;  // Start color
                    r2 = 0xff; g2 = 0xcc; b2 = 0x00;	// Stop color
                    white_text = false;
                    break;


                case CSLibrary.Net.Mode.Unknown: // Select Red
                    r1 = 0xfc; g1 = 0xc6; b1 = 0x0a;  // Start color
                    r2 = 0xff; g2 = 0x00; b2 = 0x00;	// Stop color
                    white_text = false;
                    break;


                case CSLibrary.Net.Mode.Normal: // Select Green 
                    r1 = 0x66; g1 = 0xff; b1 = 0x66;  // Start color 
                    r2 = 0x00; g2 = 0xcc; b2 = 0x00;	// Stop color 
                    white_text = false;
                    break;

            }


            // Color the cell
            for (int i = 0; i < Math.Abs(cell_rect.top - cell_rect.bottom); i++)
            {
                int r, g, b;
                r = r1 + (i * (r2 - r1) / Math.Abs(cell_rect.top - cell_rect.bottom));
                g = g1 + (i * (g2 - g1) / Math.Abs(cell_rect.top - cell_rect.bottom));
                b = b1 + (i * (b2 - b1) / Math.Abs(cell_rect.top - cell_rect.bottom));

                gx.FillRectangle(new SolidBrush(Color.FromArgb(r, g, b)),
                    new Rectangle(cell_rect.left, cell_rect.top + i, Math.Abs(cell_rect.right - cell_rect.left), 1));
            }

            //-----------------------
            // Create Fonts + Colors
            //-----------------------
            Font large_bold_font = new Font("Arial", 12, FontStyle.Bold);
            Font mid_font = new Font("Arial", 12, FontStyle.Regular);
            Font mid_bold_font = new Font("Arial", 14, FontStyle.Bold);

            //-----------------------
            // Write the text
            //-----------------------

            Color org_color;								// Temporary Variable
            string temp_str;					// Temporary Strings


            // Do not overwrite the background -- FILL OFF
            hdc = gx.GetHdc();
            SetBkMode(hdc, TRANSPARENT);
            gx.ReleaseHdc(hdc);
            // Set the default color
            if (white_text)
                TextColor = Color.Black;
            else
                TextColor = Color.Black;


            //-------------------------------------------------------
            // Write the first label <TEXT1> -- Device Name/Type
            //-------------------------------------------------------

            gx.DrawString(pEntry.device_name, large_bold_font, new SolidBrush(TextColor),
                new PointF(cell_rect.left + TEXT1_LEFT,
                    cell_rect.top + TEXT1_TOP));

            //-------------------------------------------------------
            // Write the second label <TEXT2> -- IP Address
            //-------------------------------------------------------

            // If sorted by this method
            if (true)
            {

                // Set Color
                if (white_text)
                {
                    org_color = TextColor;
                    TextColor = Color.Yellow;
                }
                else
                {
                    org_color = TextColor;
                    TextColor = Color.Blue;
                }

            }
            else
            {
                // normal color
            }

            temp_str = pEntry.ip.ToString();
            gx.DrawString(temp_str, large_bold_font, new SolidBrush(TextColor),
                new PointF(cell_rect.left + TEXT2_LEFT,
                    cell_rect.top + TEXT2_TOP));
            // If color changed, restore color
            if (true)
                TextColor = org_color;

            //-------------------------------------------------------
            // Write the third label <TEXT3> - Additional Description
            //-------------------------------------------------------

            gx.DrawString(pEntry.description, mid_font, new SolidBrush(TextColor),
            new PointF(cell_rect.left + TEXT3_LEFT,
                cell_rect.top + TEXT3_TOP));

            //-------------------------------------------------------
            // Write the fourth label <TEXT4> -- Mac Address
            //-------------------------------------------------------

            {
                temp_str = pEntry.mac.ToString();
                gx.DrawString(temp_str, mid_font, new SolidBrush(TextColor),
                new PointF(cell_rect.left + TEXT4_LEFT,
                cell_rect.top + TEXT4_TOP));

            }

            // Raised edge if selected
            if (entry_number == SelectedIndex)
            {

                IntPtr brush1 = CreateSolidBrush((uint)new RGB(Color.Black).ToInt32());
                int i;

                RECT sel;
                sel = cell_rect;
                sel.right -= 1;
                hdc = gx.GetHdc();
                FrameRect(hdc, ref sel, brush1);
                gx.ReleaseHdc(hdc);

                // Thicken Border
                for (i = 0; i < 6; i++)
                {
                    sel.left += 1;
                    sel.bottom -= 1;
                    sel.right -= 1;
                    sel.top += 1;
                    hdc = gx.GetHdc();
                    FrameRect(hdc, ref sel, brush1);
                    gx.ReleaseHdc(hdc);

                }
                DeleteObject(brush1);
            }

            //-----------------------
            // Cleanup
            //-----------------------

            // Delete Fonts
            large_bold_font.Dispose();
            mid_font.Dispose();
            mid_bold_font.Dispose();
        }
 void ReaderXP_OnAccessCompleted(object sender, CSLibrary.Events.OnAccessCompletedEventArgs e)
 {
     Trace.WriteLine(string.Format("Bank {0}, Access {1}, Result {2}, Data {3}", e.bank, e.access,e.success, e.data == null ? null : e.data.ToString()));
 }
 void ReaderCE_StateChangedEvent(object sender, CSLibrary.Events.OnStateChangedEventArgs e)
 {
     switch (e.state)
     {
         case RFState.IDLE:
             if (!m_stop)
             {
                 //Device.MelodyPlay(RingTone.T1, BuzzerVolume.HIGH);
                 ToggleButton();
                 EnableForm(true);
             }
             else
             {
                 CloseForm();
             }
             break;
         case RFState.BUSY:
             //Device.MelodyPlay(RingTone.T2, BuzzerVolume.HIGH);
             ToggleButton();
             break;
         case RFState.ABORT:
             EnableForm(false); ;
             break;
     }
 }
 void ReaderCE_StateChangedEvent(object sender, CSLibrary.Events.OnStateChangedEventArgs e)
 {
     switch (e.state)
     {
         case RFState.IDLE:
             EnableForm(true);
             if (!m_stop)
             {
                 switch (m_opt)
                 {
                     case Opts.TAG_SEARCH:
                         //Device.MelodyPlay(RingTone.T1, BuzzerVolume.HIGH);
                         ChangeBtnState(false);
                         break;
                 }
             }
             else
             {
                 CloseForm();
             }
             break;
         case RFState.BUSY:
             switch (m_opt)
             {
                 case Opts.TAG_SEARCH:
                     //Device.MelodyPlay(RingTone.T2, BuzzerVolume.HIGH);
                     ChangeBtnState(true);
                     break;
             }
             break;
         case RFState.ABORT:
             EnableForm(false);
             break;
     }
 }
 void ReaderXP_StateChangedEvent(object sender, CSLibrary.Events.OnStateChangedEventArgs e)
 {
     switch (e.state)
     {
         case RFState.IDLE:
             if (!m_stop)
             {
                 //Device.MelodyPlay(CSLibrary.Device.RingTone.T1, BUZZER_SOUND.HIGH);
             }
             else
             {
                 CloseForm();
             }
             EnableForm(true);
             break;
         case RFState.BUSY:
             //Device.MelodyPlay(CSLibrary.Device.RingTone.T2, BUZZER_SOUND.HIGH);
             break;
         case RFState.ABORT:
             EnableForm(false);
             break;
     }
 }
 public void AddItem(CSLibrary.Net.DeviceInfomation info)
 {
     lock (myLock)
     {
         m_items.Add(info);
     }
     if (Change != null)
     {
         Change.Invoke();
     }
 }
        static void RFID_OnCompleted(object sender, CSLibrary.Events.OnAccessCompletedEventArgs e)
        {
            switch (e.access)
            {
                case TagAccess.READ:
                case TagAccess.WRITE:
#if CSV
                    switch (e.bank)
                    {
                        case Bank.EPC:
                        case Bank.TID:
                        case Bank.USER:
                            Logger.WriteLine(string.Format("{0},{1},{2},{3},{4},0x{5}",
                               e.access,
                               e.bank,
                               e.success ? "OK" : "FAILED",
                               TagRead.offset,
                               TagRead.count,
                               e.data.ToString()
                               ));
                            break;
                        case Bank.ACC_PWD:
                        case Bank.KILL_PWD:
                        case Bank.PC:
                            Logger.WriteLine(string.Format("{0},{1},{2},0x{3}",
                               e.access,
                               e.bank,
                               e.success ? "OK" : "FAILED",
                               e.data.ToString()
                               ));
                            break;
                    }
#else
                    Logger.WriteLine(string.Format("{0} {1} bank, Result = {2}, Data = {3}",
                       e.access,
                       e.bank,
                       e.success ? "OK" : "FAILED",
                       e.data.ToString()
                       ));
#endif
                    break;
                case TagAccess.LOCK:
                case TagAccess.KILL:
                case TagAccess.ERASE:
#if CSV
                    Logger.WriteLine(string.Format("{0},{1},{2}",
                                e.access,
                                e.bank,
                                e.success ? "OK" : "FAILED"
                                ));
#else
                    Logger.WriteLine(string.Format("{0} {1} bank, Result = {2}",
                                e.access,
                                e.bank,
                                e.success ? "OK" : "FAILED"
                                ));
#endif
                    break;
            }

        }
 public void UpdateItem(CSLibrary.Net.DeviceInfomation info, int index)
 {
     m_items[index] = info;
     if (Change != null)
     {
         Change.Invoke();
     }
 }