Ejemplo n.º 1
0
        public void Run()
        {
            while (true)
            {
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine("You can type read, write, readbyte, writebyte, setsamplerate [number], stop, or exit.");
                Console.WriteLine("(r, w, rb, wb, ssr ###, s, and e for short)");
                if (mLogic16 != null)
                {
                    Console.WriteLine("Logic16 does not support readbyte, writebyte, or write");
                    Console.WriteLine("You can also type setchannels [1,2,3..] and set5volts [true/false]");
                    Console.WriteLine("(sc and s5v for short)");
                }
                Console.WriteLine();
                Console.WriteLine();

                string command = Console.ReadLine();


                if (command == "exit" || command == "e")
                {
                    break;
                }

                if (command == "")
                {
                    continue;
                }

                if ((mLogic == null) && (mLogic16 == null))
                {
                    Console.WriteLine("Sorry, no devices are connected.");
                    continue;
                }

                if (command == "stop" || command == "s")
                {
                    if (mLogic != null)
                    {
                        if (mLogic.IsStreaming() == false)
                        {
                            Console.WriteLine("Sorry, the device is not currently streaming.");
                        }
                        else
                        {
                            mLogic.Stop();
                        }
                    }
                    if (mLogic16 != null)
                    {
                        if (mLogic16.IsStreaming() == false)
                        {
                            Console.WriteLine("Sorry, the device is not currently streaming.");
                        }
                        else
                        {
                            mLogic16.Stop();
                        }
                    }

                    continue;
                }
                if (mLogic != null)
                {
                    if (mLogic.IsStreaming() == true)
                    {
                        Console.WriteLine("Sorry, Logic is already streaming.");
                        continue;
                    }
                }
                if (mLogic16 != null)
                {
                    if (mLogic16.IsStreaming() == true)
                    {
                        Console.WriteLine("Sorry, Logic16 is already streaming.");
                        continue;
                    }
                }

                if (command == "read" || command == "r")
                {
                    if (mLogic != null)
                    {
                        mLogic.ReadStart();
                    }
                    if (mLogic16 != null)
                    {
                        mLogic16.ReadStart();
                    }
                }
                else
                if (command == "write" || command == "w")
                {
                    if (mLogic != null)
                    {
                        mLogic.WriteStart();
                    }
                    if (mLogic16 != null)
                    {
                        Console.WriteLine("Not supported by Logic16");
                    }
                }
                else
                if (command == "readbyte" || command == "rb")
                {
                    if (mLogic != null)
                    {
                        Console.WriteLine("Got value 0x{0:X}", mLogic.GetInput());
                    }
                    if (mLogic16 != null)
                    {
                        Console.WriteLine("Not supported by Logic16");
                    }
                }
                else
                if (command == "writebyte" || command == "wb")
                {
                    if (mLogic != null)
                    {
                        mLogic.SetOutput(mWriteValue);
                        Console.WriteLine("Logic is now outputting 0x{0:X}", mWriteValue);
                        mWriteValue++;
                    }
                    if (mLogic16 != null)
                    {
                        Console.WriteLine("Not supported by Logic16");
                    }
                }
                else
                if (command.StartsWith("setsamplerate") || command.StartsWith("ssr"))
                {
                    List <uint> sample_rates = new List <uint>();
                    if (mLogic != null)
                    {
                        sample_rates = mLogic.GetSupportedSampleRates();
                    }
                    if (mLogic16 != null)
                    {
                        sample_rates = mLogic16.GetSupportedSampleRates();
                    }

                    if (command.IndexOf(" ") == -1)
                    {
                        Console.WriteLine("Avalable sample rates: ");
                        for (int i = 0; i < sample_rates.Count; ++i)
                        {
                            Console.WriteLine(sample_rates[i].ToString());
                        }
                        continue;
                    }

                    uint   new_rate;
                    string num_string = command.Substring(command.IndexOf(" ") + 1);
                    if (uint.TryParse(num_string, out new_rate))
                    {
                        if (sample_rates.IndexOf(new_rate) != -1)
                        {
                            if (mLogic != null)
                            {
                                mLogic.SampleRateHz = new_rate;
                            }
                            if (mLogic16 != null)
                            {
                                mLogic16.SampleRateHz = new_rate;
                            }
                            Console.WriteLine("New Sample Rate: {0}", new_rate);
                        }
                        else
                        {
                            //uint sugested_rate = sample_rates
                            Console.WriteLine("Sample Rate Not supported. Avalable rates: ");
                            for (int i = 0; i < sample_rates.Count; ++i)
                            {
                                Console.WriteLine(sample_rates[i].ToString());
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("Avalable sample rates: ");
                        for (int i = 0; i < sample_rates.Count; ++i)
                        {
                            Console.WriteLine(sample_rates[i].ToString());
                        }
                        continue;
                    }
                }
                if (command.StartsWith("setchannels") || command.StartsWith("sc"))
                {
                    if (mLogic16 == null)
                    {
                        continue;
                    }

                    if (command.IndexOf(" ") != -1)
                    {
                        command = command.Substring(command.IndexOf(" ") + 1);
                    }
                    else
                    {
                        Console.WriteLine("Active Channels: " + string.Join(", ", Array.ConvertAll <uint, String>(mLogic16.CaptureChannels.ToArray(), new Converter <uint, string>(Convert.ToString))));
                        continue;
                    }
                    String[]    strings  = command.Split(',');
                    List <uint> channels = new List <uint>();
                    foreach (String str in strings)
                    {
                        uint channel;
                        if (uint.TryParse(str.Trim(), out channel))
                        {
                            channels.Add(channel);
                        }
                    }
                    if (channels.Count > 0)
                    {
                        mLogic16.CaptureChannels = channels;
                    }
                    else
                    {
                        Console.WriteLine("Invalid Input, please type: setchannels 1, 2, 3, 4");
                    }
                }
                if (command.StartsWith("set5volts") || command.StartsWith("s5v"))
                {
                    if (mLogic16 == null)
                    {
                        continue;
                    }
                    if (command.IndexOf(" ") != -1)
                    {
                        command = command.Substring(command.IndexOf(" ") + 1);
                    }
                    else
                    {
                        if (mLogic16.Use5Volts == true)
                        {
                            Console.WriteLine("I/O voltage: 3.6V to 5.0V");
                        }
                        else
                        {
                            Console.WriteLine("I/O voltage: 1.8V to 3.6V");
                        }
                        continue;
                    }
                    if (command.ToLower().Contains("true"))
                    {
                        mLogic16.Use5Volts = true;
                    }
                    else if (command.ToLower().Contains("false"))
                    {
                        mLogic16.Use5Volts = false;
                    }
                    else
                    {
                        Console.WriteLine("Invalid input please type: set5volts true or set5volts false");
                    }
                }
            }
        }