Beispiel #1
0
 public RCS()
 {
     InitializeComponent();
     this.Hide();
     entry = new CTC(this);
     entry.Show();
 }
Beispiel #2
0
 static void Main()
 {
     //CTC.RemoveDuplicatesTest();
     //CTC.AreAnagramsTest();
     //CTC.ReplaceStringTesting();
     //CTC.UniqueTesting();
     CTC.RotateMatrixTest();
 }
Beispiel #3
0
        public void WroldMSGSend(object O)
        {
            NewMSG newMSG = (NewMSG)O;

            Console.WriteLine(newMSG.MSGText);
            ProtocolBytes MSG = new ProtocolBytes();

            MSG.AddData("MSG");
            string MSGStr = JsonConvert.SerializeObject(newMSG);

            MSG.AddData(MSGStr);
            Dictionary <string, ConnToClient> Online = ClientMC.A.CTCD;

            foreach (ConnToClient CTC in Online.Values)
            {
                CTC.Send(MSG);
            }
        }
Beispiel #4
0
        private void CTC_Click(object sender, EventArgs e)
        {
            try
            {
                ManagementObjectSearcher mosProcessor = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM CIM_Processor");
                ManagementObjectSearcher mosGPU       = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM CIM_VideoController");

                String cpubit          = "??";
                Int32  cpuclock        = 0;
                String cpumanufacturer = "Unknown";
                String cpuname         = "Unknown";
                String gpuname         = "Unknown";
                String gpuver          = "N/A";
                UInt32 gpuvram         = 0;
                String enclosure       = "Unknown";
                String Frequency       = "0";
                String coreCount       = "1";

                // Get CPU info
                foreach (ManagementObject moProcessor in mosProcessor.Get())
                {
                    cpuclock        = int.Parse(moProcessor["maxclockspeed"].ToString());
                    cpubit          = CPUArch(int.Parse(moProcessor["Architecture"].ToString()));
                    cpuname         = moProcessor["name"].ToString();
                    cpumanufacturer = moProcessor["manufacturer"].ToString();
                    coreCount       = moProcessor["NumberOfCores"].ToString();
                }

                // Get GPU info
                foreach (ManagementObject moGPU in mosGPU.Get())
                {
                    gpuname = moGPU["Name"].ToString();
                    gpuvram = Convert.ToUInt32(moGPU["AdapterRAM"]);
                    gpuver  = moGPU["DriverVersion"].ToString();
                }

                if (cpuclock < 1000)
                {
                    Frequency = String.Format("{0}MHz", cpuclock);
                }
                else
                {
                    Frequency = String.Format("{0}GHz", ((float)cpuclock / 1000).ToString("0.00"));
                }

                // Ok, print everything to the string builder
                StringBuilder sb = new StringBuilder();
                sb.Append(String.Format("Keppy's Synthesizer Information Dialog\n\n", DriverVer.Text));
                sb.Append("== Driver info =================================================\n");
                sb.Append(String.Format("Driver version: {0}\n", DriverVer.Text));
                sb.Append(String.Format("BASS version: {0}\n", BASSVer.Text));
                sb.Append(String.Format("BASSMIDI version: {0}\n", BASSMIDIVer.Text));
                sb.Append(String.Format("Compiled on: {0}\n\n", CompiledOn.Text));
                sb.Append("== Windows installation info ===================================\n");
                sb.Append(String.Format("Name: {0}\n", WinName.Text));
                sb.Append(String.Format("Version: {0}\n\n", WinVer.Text));
                sb.Append("== Computer info ===============================================\n");
                sb.Append(String.Format("Processor: {0} ({1})\n", cpuname, cpubit));
                sb.Append(String.Format("Processor info: {1} cores and {2} threads, running at {3}\n", cpumanufacturer, coreCount, Environment.ProcessorCount, Frequency));
                sb.Append(String.Format("Graphics card: {0}\n", gpuname));
                sb.Append(String.Format("Graphics card info: {0}MB VRAM, driver version {1}\n\n", (gpuvram / 1048576), gpuver));
                sb.Append("================================================================\n");
                sb.Append(String.Format("End of info. Got them on {0}.", DateTime.Now.ToString()));

                // Copy to clipboard
                Clipboard.SetText(sb.ToString());
                sb = null;

                MessageBox.Show("Copied to clipboard.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                string       message      = String.Format("Exception type: {0}\nException message: {1}\nStack trace: {2}", ex.GetType(), ex.Message, ex.StackTrace);
                String       Error        = String.Format("An error has occured while copying the info to the clipboard.\n\nError:\n{0}\n\nDo you want to try again?", message);
                DialogResult dialogResult = MessageBox.Show(Error, "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (dialogResult == DialogResult.Yes)
                {
                    CTC.PerformClick();
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Compile a single output component
        /// </summary>
        /// <param name="component">Component to be compiled</param>
        /// <param name="codeBuffer">Compiler's code buffer</param>
        /// <returns>If and else statements</returns>
        internal static Tuple <string, string> CompileOutputComponent(ComponentBase component, CompilerBuffer codeBuffer)
        {
            string ifCommand = string.Empty, elseCommand = string.Empty;

            if (component is Coil)
            {
                Coil coil = component as Coil;
                switch (coil.Mode)
                {
                case Coil.CoilMode.Negated:
                    ifCommand   = coil.FullName + " = false;";
                    elseCommand = coil.FullName + " = true;";
                    break;

                case Coil.CoilMode.Normal:
                    ifCommand   = coil.FullName + " = true;";
                    elseCommand = coil.FullName + " = false;";
                    break;

                case Coil.CoilMode.Reset:
                    ifCommand = coil.FullName + " = false;";
                    break;

                case Coil.CoilMode.Set:
                    ifCommand = coil.FullName + " = true;";
                    break;
                }
            }
            else if (component is ADC)
            {
                ifCommand = (component as ADC).Destination + " = analogRead(" + (component as ADC).FullName + ");";
            }
            else if (component is PWM)
            {
                ifCommand   = "analogWrite(" + (component as PWM).FullName + ", " + (component as PWM).DudyCycle + ");";
                elseCommand = "analogWrite(" + (component as PWM).FullName + ", 0);";
            }
            else if (component is RES)
            {
                ifCommand = (component as RES).FullName + " = 0;";
            }
            else if (component is CTC)
            {
                CTC ctc = component as CTC;
                ifCommand   = "if (" + OSR_FN + "(" + codeBuffer.OSRCount + ", true)) " + ctc.FullName + " = (" + ctc.FullName + " >= " + ctc.Limit + ") ? 0 : " + ctc.FullName + " + 1;";
                elseCommand = OSR_FN + "(" + codeBuffer.OSRCount + ", false));";
                codeBuffer.OSRCount++;
            }
            else if (component is MathComponent)
            {
                MathComponent mc = component as MathComponent;

                if (component is ADD)
                {
                    ifCommand = mc.Destination + " = " + mc.VarA + " + " + mc.VarB + ";";
                }
                else if (component is DIV)
                {
                    ifCommand = mc.Destination + " = " + mc.VarA + " / " + mc.VarB + ";";
                }
                else if (component is MUL)
                {
                    ifCommand = mc.Destination + " = " + mc.VarA + " * " + mc.VarB + ";";
                }
                else if (component is SUB)
                {
                    ifCommand = mc.Destination + " = " + mc.VarA + " - " + mc.VarB + ";";
                }
                else if (component is MOV)
                {
                    ifCommand = mc.Destination + " = " + mc.VarA + ";";
                }
            }
            else if (component is ELF)
            {
                ifCommand = (component as ELF).Name + "();";
            }

            return(new Tuple <string, string>(ifCommand, elseCommand));
        }
Beispiel #6
0
        /// <summary>
        /// Create a single component from XML data
        /// </summary>
        /// <param name="node">XML node containing component data</param>
        /// <returns>Created Component</returns>
        private static ComponentBase CreateComponent(XmlNode node)
        {
            ComponentBase component;

            switch (node.LocalName)
            {
                #region Basic
            case "Coil":
                Coil coil = new Coil();
                coil.Mode = node.Attributes["Mode"].Value.ToEnum <Coil.CoilMode>();
                coil.Type = node.Attributes["Type"].Value.ToEnum <Coil.CoilType>();
                component = coil;
                break;

            case "Contact":
                Contact contact = new Contact();
                contact.IsClosed   = node.Attributes["IsClosed"].Value.ToBool();
                contact.IsInverted = node.Attributes["IsInverted"].Value.ToBool();
                contact.Type       = node.Attributes["Type"].Value.ToEnum <Contact.ContactType>();
                component          = contact;
                break;

            case "SC": component = new SC(); break;

            case "OSF": component = new OSF(); break;

            case "OSR": component = new OSR(); break;
                #endregion Basic

                #region Compare Components
            case "EQU": component = new EQU(); break;

            case "GEQ": component = new GEQ(); break;

            case "GRT": component = new GRT(); break;

            case "LEG": component = new LEG(); break;

            case "LES": component = new LES(); break;

            case "NEQ": component = new NEQ(); break;
                #endregion Compare Components

                #region Counter Components
            case "CTC": component = new CTC(); break;

            case "CTD": component = new CTD(); break;

            case "CTU": component = new CTU(); break;

            case "RES": component = new RES(); break;
                #endregion Counter Components

                #region Math Components
            case "ADD": component = new ADD(); break;

            case "DIV": component = new DIV(); break;

            case "MUL": component = new MUL(); break;

            case "SUB": component = new SUB(); break;

            case "MOV": component = new MOV(); break;
                #endregion Math Components

                #region Analog Components
            case "ADC":
                ADC adc = new ADC();
                adc.Destination = node.Attributes["Destination"].Value;
                component       = adc;
                break;

            case "PWM":
                PWM pwm = new PWM();
                pwm.DudyCycle = node.Attributes["DudyCycle"].Value;
                component     = pwm;
                break;
                #endregion Analog Components

                #region Function Components
            case "ELF":
                ELF elf = new ELF();
                elf.Name  = node.Attributes["Name"].Value;
                elf.Code  = node.InnerText;
                component = elf;
                break;
                #endregion Function Components

            default:
                throw new ArgumentException("Unknow Component", "node");
            }

            component.Comment = node.Attributes["Comment"].Value;

            #region Extra Processing based on Components Base Class
            if (component is NameableComponent)
            {
                (component as NameableComponent).Name = node.Attributes["Name"].Value;
            }

            if (component is CompareComponent)
            {
                (component as CompareComponent).VarA = node.Attributes["VarA"].Value;
                (component as CompareComponent).VarB = node.Attributes["VarB"].Value;
            }
            else if (component is CounterComponent)
            {
                (component as CounterComponent).Limit = node.Attributes["Limit"].Value;
            }
            else if (component is MathComponent)
            {
                (component as MathComponent).Destination = node.Attributes["Destination"].Value;
                (component as MathComponent).VarA        = node.Attributes["VarA"].Value;
                (component as MathComponent).VarB        = node.Attributes["VarB"].Value;
            }
            #endregion Extra Processing based on Components Base Class

            return(component);
        }
Beispiel #7
0
        public void Constants()
        {
            var  TestTable = new LadderDataTable();
            Node PowerRail = new Node();

            PowerRail.LogicLevel = true;

            Trace.WriteLine("Math", "Unit Test");
            Trace.Indent();
            Trace.WriteLine("StartUP", "ADD");
            Trace.Indent();
            ADD add = new ADD();

            add.DataTable   = TestTable;
            add.LeftLide    = PowerRail;
            add.Destination = "Dest";
            add.VarA        = "1";
            add.ValueA      = 3;
            add.VarB        = "2";
            add.ValueB      = 1;
            add.Execute();
            Trace.Unindent();

            Trace.WriteLine("StartUP", "MOV");
            Trace.Indent();
            MOV mov = new MOV();

            mov.DataTable   = TestTable;
            mov.LeftLide    = PowerRail;
            mov.Destination = "Dest";
            mov.VarA        = "0";
            mov.ValueA      = 1;
            mov.Execute();
            Trace.Unindent();
            Trace.Unindent();

            Trace.WriteLine("Counter", "Unit Test");
            Trace.Indent();
            Trace.WriteLine("StartUP", "CTC");
            Trace.Indent();
            CTC ctc = new CTC();

            ctc.DataTable  = TestTable;
            ctc.Name       = "1";
            ctc.Limit      = "2";
            ctc.LimitValue = 3;
            ctc.LeftLide   = PowerRail;
            ctc.Execute();
            Trace.Unindent();

            Trace.WriteLine("StartUP", "CTU");
            Trace.Indent();
            CTU ctu = new CTU();

            ctu.DataTable  = TestTable;
            ctu.Name       = "1";
            ctu.Limit      = "3";
            ctu.LimitValue = 4;
            ctu.LeftLide   = PowerRail;
            ctu.Execute();
            Trace.Unindent();
            Trace.Unindent();

            Trace.WriteLine("Compare", "Unit Test");
            Trace.Indent();
            EQU equ = new EQU();

            equ.DataTable = TestTable;
            equ.LeftLide  = PowerRail;
            equ.VarA      = "3";
            equ.ValueA    = 4;
            equ.VarB      = "4";
            equ.ValueB    = 5;
            equ.Execute();
            Trace.Unindent();

            Assert.AreEqual(2, TestTable.Count);
        }
Beispiel #8
0
        public void Counter()
        {
            #region Startup
            var  TestTable = new LadderDataTable();
            Node PowerRail = new Node();

            CTC ctc = new CTC();
            ctc.Name      = "1";
            ctc.Limit     = "Limit";
            ctc.LeftLide  = PowerRail;
            ctc.DataTable = TestTable;

            CTD ctd = new CTD();
            ctd.Name      = "1";
            ctd.Limit     = "Limit";
            ctd.LeftLide  = PowerRail;
            ctd.DataTable = TestTable;

            CTU ctu = new CTU();
            ctu.Name      = "1";
            ctu.Limit     = "Limit";
            ctu.LeftLide  = PowerRail;
            ctu.DataTable = TestTable;

            RES res = new RES();
            res.Name      = "1";
            res.LeftLide  = PowerRail;
            res.DataTable = TestTable;
            #endregion Startup

            #region CTC
            Trace.WriteLine("CTC", "Unit Test");
            Trace.Indent();

            Trace.WriteLine("StartUP", "CTC");
            Trace.Indent();
            PowerRail.LogicLevel = true;
            ctc.CurrentValue     = 1;
            ctc.LimitValue       = 2;
            res.Execute();
            Trace.Unindent();

            Trace.WriteLine("Input False", "CTC");
            Trace.Indent();
            PowerRail.LogicLevel = false;
            ctc.Execute();
            ctc.Execute();
            ctc.Execute();
            Assert.IsFalse(ctc.InternalState);
            Trace.Unindent();

            Trace.WriteLine("Input True", "CTC");
            Trace.Indent();

            PowerRail.LogicLevel = false;
            ctc.Execute();
            PowerRail.LogicLevel = true;
            ctc.Execute();
            Assert.IsFalse(ctc.InternalState, "Fail First Cycle");

            PowerRail.LogicLevel = false;
            ctc.Execute();
            PowerRail.LogicLevel = true;
            ctc.Execute();
            Assert.IsTrue(ctc.InternalState, "Fail Second Cycle");

            PowerRail.LogicLevel = false;
            ctc.Execute();
            PowerRail.LogicLevel = true;
            ctc.Execute();
            Assert.IsFalse(ctc.InternalState, "Fail Third Cycle");

            PowerRail.LogicLevel = false;
            ctc.Execute();
            PowerRail.LogicLevel = true;
            ctc.Execute();
            Assert.IsFalse(ctc.InternalState, "Fail Fourth Cycle");

            Trace.Unindent();
            Trace.Unindent();
            #endregion CTC

            #region CTD
            Trace.WriteLine("CTD", "Unit Test");
            Trace.Indent();

            Trace.WriteLine("StartUP", "CTD");
            Trace.Indent();
            PowerRail.LogicLevel = true;
            ctc.CurrentValue     = 3;
            ctc.LimitValue       = 1;
            Trace.Unindent();

            Trace.WriteLine("Input False", "CTD");
            Trace.Indent();
            PowerRail.LogicLevel = false;
            ctd.Execute();
            ctd.Execute();
            ctd.Execute();
            Assert.IsFalse(ctc.InternalState);
            Trace.Unindent();

            Trace.WriteLine("Input True", "CTD");
            Trace.Indent();

            PowerRail.LogicLevel = false;
            ctd.Execute();
            PowerRail.LogicLevel = true;
            ctd.Execute();
            Assert.IsTrue(ctd.InternalState, "Fail First Cycle");

            PowerRail.LogicLevel = false;
            ctd.Execute();
            PowerRail.LogicLevel = true;
            ctd.Execute();
            Assert.IsTrue(ctd.InternalState, "Fail Second Cycle");

            PowerRail.LogicLevel = false;
            ctd.Execute();
            PowerRail.LogicLevel = true;
            ctd.Execute();
            Assert.IsFalse(ctd.InternalState, "Fail Third Cycle");

            PowerRail.LogicLevel = false;
            ctd.Execute();
            PowerRail.LogicLevel = true;
            ctd.Execute();
            Assert.IsFalse(ctd.InternalState, "Fail Fourth Cycle");

            Trace.Unindent();
            Trace.Unindent();
            #endregion CTD

            #region CTU
            Trace.WriteLine("CTU", "Unit Test");
            Trace.Indent();

            Trace.WriteLine("StartUP", "CTU");
            Trace.Indent();
            PowerRail.LogicLevel = true;
            ctu.CurrentValue     = 1;
            ctu.LimitValue       = 3;
            res.Execute();
            Trace.Unindent();

            Trace.WriteLine("Input False", "CTU");
            Trace.Indent();
            PowerRail.LogicLevel = false;
            ctu.Execute();
            ctu.Execute();
            ctu.Execute();
            Assert.IsFalse(ctu.InternalState);
            Trace.Unindent();

            Trace.WriteLine("Input True", "CTU");
            Trace.Indent();

            PowerRail.LogicLevel = false;
            ctu.Execute();
            PowerRail.LogicLevel = true;
            ctu.Execute();
            Assert.IsFalse(ctu.InternalState, "Fail First Cycle");

            PowerRail.LogicLevel = false;
            ctu.Execute();
            PowerRail.LogicLevel = true;
            ctu.Execute();
            Assert.IsFalse(ctu.InternalState, "Fail Second Cycle");

            PowerRail.LogicLevel = false;
            ctu.Execute();
            PowerRail.LogicLevel = true;
            ctu.Execute();
            Assert.IsTrue(ctu.InternalState, "Fail Third Cycle");

            PowerRail.LogicLevel = false;
            ctu.Execute();
            Assert.IsFalse(ctu.InternalState, "Fail Fourth Cycle");
            PowerRail.LogicLevel = true;
            ctu.Execute();
            Assert.IsTrue(ctu.InternalState, "Fail Fourth Cycle");

            Trace.Unindent();
            Trace.Unindent();
            #endregion CTU
        }