Esempio n. 1
0
        public void Initialize()
        {
            this.MinimumSize = new Size((int)(ZeoStream.SamplesPerSec * 2), 100);

            this.timer = new Stopwatch();

            this.eegLevelToolStripComboBox.SelectedIndex = ZeoSettings.Default.EegLevelSelecteIndex;
            float eegLevel;

            float.TryParse(this.eegLevelToolStripComboBox.Text, out eegLevel);

            this.eegScopePanel.MaxValueDisplay = new float[] { eegLevel };
            this.eegScopePanel.MinValueDisplay = new float[] { -eegLevel };

            if (this.fileNameToolStripComboBox.Items.Count > 0)
            {
                this.fileNameToolStripComboBox.SelectedIndex = 0;
            }

            SoundAlarm.SetVolumes(ZeoSettings.Default.MaxVolume);

            this.freqScopePanel.SamplesPerSecond     = 1.0;
            this.freqScopePanel.NumberOfChannels     = ZeoMessage.FrequencyBinsLength + 2; // Include Impedance and Sound Alarm Volume
            this.freqScopePanel.MaxValueDisplay      = new float[] { 50.0f, 50.0f, 50.0f, 50.0f, 50.0f, 50.0f, 2.0f, 1500.0f, SoundAlarm.MaxVolume + 2000 };
            this.freqScopePanel.MinValueDisplay      = new float[] { 0, 0, 0, 0, 0, 0, 0, 0, SoundAlarm.MinVolume - 200 };
            this.freqScopePanel.GraphColors          = new Color[] { Color.Red, Color.Green, Color.Blue, Color.Cyan, Color.Magenta, Color.Yellow, Color.Coral, Color.FromArgb(80, 80, 80), Color.Brown };
            this.freqScopePanel.LabelFormatStrings   = new string[] { "D: {0:0.00}", "T: {0:0.00}", "A: {0:0.00}", "B1: {0:0.00}", "B2: {0:0.00}", "B3: {0:0.00}", "G: {0:0.00}", "Im: {0:0.0}", "V: {0}" };
            this.freqScopePanel.HorizontalLinesCount = 0;

            // Restore from ZeoSettings
            this.eegLevelToolStripComboBox.SelectedIndex = ZeoSettings.Default.EegLevelSelecteIndex;
            this.WindowState           = ZeoSettings.Default.WindowMaximized == true ? FormWindowState.Maximized : FormWindowState.Normal;
            this.Height                = ZeoSettings.Default.WindowHeight;
            this.Width                 = ZeoSettings.Default.WindowWidth;
            this.freqScopePanel.Height = ZeoSettings.Default.FreqPanelHeight;

            if (ZeoSettings.Default.AlarmEnabled == true)
            {
                this.alarmStateToolStripLabel.Text      = this.alarmOnString;
                this.alarmStateToolStripLabel.ForeColor = Color.DarkGreen;
            }
            else
            {
                this.alarmStateToolStripLabel.Text      = this.alarmOffString;
                this.alarmStateToolStripLabel.ForeColor = SystemColors.ControlText;
            }

            this.LoadFileNames();

            Action <object> comPortsDetect = delegate(object obj)
            {
                Thread.Sleep(50); // sleep to make sure the form is created
                string[] comPorts = Ftdi.GetComPortList();
                this.Invoke(new Action <string[]>(this.ComPortsComboBoxItemsAdd), new object[] { comPorts });
            };

            this.InitBluetoothSpeaker();

            comPortsDetect.BeginInvoke(null, null, null);
        }
Esempio n. 2
0
        public static string[] GetComPortList()
        {
            List <string> comPorts = new List <string>();

            try
            {
                List <FTDeviceInfo> ftdiDevices = new List <FTDeviceInfo>();

                uint         deviceNumber;
                FTStatusCode ftStatus = Ftdi.FT_CreateDeviceInfoList(out deviceNumber);

                if (deviceNumber > 0)
                {
                    FTDeviceInfoNode[] devices = new FTDeviceInfoNode[deviceNumber];

                    for (int k = 0; k < deviceNumber; k++)
                    {
                        devices[k].SerialNumber = new byte[16];
                        devices[k].Description  = new byte[64];
                    }

                    ftStatus = Ftdi.FT_GetDeviceInfoList(devices, ref deviceNumber);

                    for (int k = 0; k < deviceNumber; k++)
                    {
                        FTDeviceInfo ftDeviceInfo = new FTDeviceInfo();
                        ftDeviceInfo.Flags = devices[k].Flags;
                        ftDeviceInfo.Type  = devices[k].Type;
                        ftDeviceInfo.ID    = devices[k].ID;
                        ftDeviceInfo.LocId = devices[k].LocId;

                        ftDeviceInfo.Description  = ASCIIEncoding.ASCII.GetString(devices[k].Description);
                        ftDeviceInfo.Description  = ftDeviceInfo.Description.Substring(0, ftDeviceInfo.Description.IndexOf("\0"));
                        ftDeviceInfo.SerialNumber = ASCIIEncoding.ASCII.GetString(devices[k].SerialNumber);
                        ftDeviceInfo.SerialNumber = ftDeviceInfo.SerialNumber.Substring(0, ftDeviceInfo.SerialNumber.IndexOf("\0"));

                        ftdiDevices.Add(ftDeviceInfo);
                    }

                    foreach (FTDeviceInfo ftdiDevice in ftdiDevices)
                    {
                        string comPort = Ftdi.GetComPortNumber(ftdiDevice.SerialNumber);
                        if (string.IsNullOrEmpty(comPort) == false)
                        {
                            comPorts.Add(comPort);
                        }
                    }
                }
            }
            catch (DllNotFoundException)
            {
            }

            comPorts.Sort();
            return(comPorts.ToArray());
        }
Esempio n. 3
0
        private static string GetComPortNumber(string serialNumber)
        {
            IntPtr       ftHandle = IntPtr.Zero;
            FTStatusCode ftStatus = Ftdi.FT_OpenEx(serialNumber, (uint)FTOpenByFlag.FT_OPEN_BY_SERIAL_NUMBER, ref ftHandle);

            string comNumber = null;

            ftStatus = FTStatusCode.FT_OTHER_ERROR;

            if (ftHandle != IntPtr.Zero)
            {
                int portNumber;
                ftStatus = Ftdi.FT_GetComPortNumber(ftHandle, out portNumber);
                if (ftStatus == FTStatusCode.FT_OK && portNumber > 0)
                {
                    comNumber = "COM" + portNumber.ToString();
                }

                ftStatus = Ftdi.FT_Close(ftHandle);
            }

            return(comNumber);
        }