Example #1
0
        /// <summary>
        /// Reset channels to default
        /// </summary>
        public async Task <bool> ResetChannelsToDefaultAsync()
        {
            if (await SettingsLock.WaitAsync(0))
            {
                try
                {
                    Log?.Invoke(this, new LogEventArgs(this, "ResetChannelsToDefaultAsync", $"Resetting channels to defaults", LogLevel.DEBUG));

                    //  send the command to set channel defaults
                    var response = ConfigureBoard("d");
                    Log?.Invoke(this, new LogEventArgs(this, "ResetChannelsToDefaultAsync", $"Response:{response}.", LogLevel.DEBUG));

                    StartSrb1DaisySet = false;
                    StartSrb1CytonSet = false;

                    return(true);
                }
                finally
                {
                    SettingsLock.Release();
                }
            }
            else
            {
                return(false);
            }
        }
Example #2
0
        /// <summary>
        /// Set Board Channels
        /// pass in channel settings for any board channel to set SRB1 and keep the other channel settings unchanged
        /// </summary>
        public async Task <bool> SetImpedanceModeAsync(IEnumerable <int> channels, ICytonChannelSettings settings)
        {
            if (await SettingsLock.WaitAsync(0))
            {
                try
                {
                    Log?.Invoke(this, new LogEventArgs(this, "SetImpedanceModeAsync", $"Setting board impedance {string.Join(",", channels)} to P {settings.LlofP} N {settings.LlofN}.", LogLevel.DEBUG));

                    string settingsString    = "";
                    int    setChannelCounter = 0;
                    foreach (var nextChannel in channels)
                    {
                        setChannelCounter++;
                        settingsString += $"z{nextChannel.ChannelSetCharacter()}{settings.LlofP.BoolCharacter()}{settings.LlofN.BoolCharacter()}Z";
                        if (setChannelCounter > 0)
                        {
                            var response = ConfigureBoard(settingsString);
                            Log?.Invoke(this, new LogEventArgs(this, "SetImpedanceModeAsync", $"Response:{response}.", LogLevel.DEBUG));
                            settingsString    = "";
                            setChannelCounter = 0;
                            await Task.Delay(500);
                        }
                    }

                    if (settingsString.Length > 0)
                    {
                        var response = ConfigureBoard(settingsString);
                        Log?.Invoke(this, new LogEventArgs(this, "SetImpedanceModeAsync", $"Response:{response}.", LogLevel.DEBUG));
                        await Task.Delay(500);
                    }

                    return(true);
                }
                finally
                {
                    SettingsLock.Release();
                }
            }
            else
            {
                Log?.Invoke(this, new LogEventArgs(this, "SetImpedanceModeAsync", $"Another process is busy with the settings.", LogLevel.WARN));
                return(false);
            }
        }
Example #3
0
        /// <summary>
        /// Set Board Channels
        /// </summary>
        public async Task <bool> SetBoardChannelAsync(IEnumerable <int> channels, ICytonChannelSettings settings)
        {
            if (await SettingsLock.WaitAsync(0))
            {
                try
                {
                    Log?.Invoke(this, new LogEventArgs(this, "SetBoardChannelAsync", $"Setting board channels {string.Join(",", channels)} to {settings}.", LogLevel.DEBUG));

                    string settingsString    = "";
                    int    setChannelCounter = 0;
                    foreach (var nextChannel in channels)
                    {
                        setChannelCounter++;
                        settingsString += $"x{nextChannel.ChannelSetCharacter()}{settings.PowerDown.BoolCharacter()}{(int)(settings.Gain)}{(int)(settings.InputType)}{settings.Bias.BoolCharacter()}{settings.Srb2.BoolCharacter()}0X";
                        if (setChannelCounter > 0)
                        {
                            var response = ConfigureBoard(settingsString);
                            Log?.Invoke(this, new LogEventArgs(this, "SetBoardChannelAsync", $"Response:{response}.", LogLevel.DEBUG));
                            settingsString    = "";
                            setChannelCounter = 0;
                            await Task.Delay(500);
                        }
                    }

                    if (settingsString.Length > 0)
                    {
                        var response = ConfigureBoard(settingsString);
                        Log?.Invoke(this, new LogEventArgs(this, "SetBoardChannelAsync", $"Response:{response}.", LogLevel.DEBUG));
                        await Task.Delay(500);
                    }

                    return(true);
                }
                finally
                {
                    SettingsLock.Release();
                }
            }
            else
            {
                Log?.Invoke(this, new LogEventArgs(this, "SetBoardChannelAsync", $"Another process is busy with the settings.", LogLevel.WARN));
                return(false);
            }
        }
Example #4
0
        /// <summary>
        /// Start signal test
        /// </summary>
        public async Task <bool> SetSignalTestModeAsync(TestSignalMode mode)
        {
            if (await SettingsLock.WaitAsync(0))
            {
                try
                {
                    Log?.Invoke(this, new LogEventArgs(this, "SetSignalTestModeAsync", $"Setting board to signal test mode {mode}.", LogLevel.DEBUG));

                    //  send command to enter test mode
                    var response = ConfigureBoard(mode.TestModeCharacter());
                    Log?.Invoke(this, new LogEventArgs(this, "StartSignalTestAsync", $"Response:{response}.", LogLevel.DEBUG));
                    return(true);
                }
                finally
                {
                    SettingsLock.Release();
                }
            }
            else
            {
                Log?.Invoke(this, new LogEventArgs(this, "SetSignalTestModeAsync", $"Another process is busy with the settings.", LogLevel.WARN));
                return(false);
            }
        }
Example #5
0
        /// <summary>
        /// Set SRB1 value for the board
        /// </summary>
        public async Task <bool> SetSrb1Async(ICytonChannelSettings settings, bool connect)
        {
            if (await SettingsLock.WaitAsync(0))
            {
                try
                {
                    Log?.Invoke(this, new LogEventArgs(this, "SetSrb1Async", $"{(connect ? "Connecting" : "Disconnecting")} SRB1 for {(settings.ChannelNumber < 9 ? "Cyton" : "Daisy")}.", LogLevel.DEBUG));

                    string settingsString = FormatSetSrb1String(settings, connect);

                    var response = ConfigureBoard(settingsString);
                    Log?.Invoke(this, new LogEventArgs(this, "SetSrb1Async", $"Response:{response}.", LogLevel.DEBUG));

                    if (settings.ChannelNumber <= 8)
                    {
                        StartSrb1CytonSet = connect;
                    }
                    else if (settings.ChannelNumber > 8)
                    {
                        StartSrb1DaisySet = connect;
                    }


                    return(true);
                }
                finally
                {
                    SettingsLock.Release();
                }
            }
            else
            {
                Log?.Invoke(this, new LogEventArgs(this, "SetSrb1Async", $"Another process is busy with the settings.", LogLevel.WARN));
                return(false);
            }
        }