/// <summary> /// This function enables starting the device on all ports on all bricks /// </summary> /// <param name="portFlag">A flag indicating the ports to target. Eg PortNames.A|PortNames.C</param> public async Task Start(OutputPortFlag portFlag = OutputPortFlag.All) { for (int i = 0; i < 4; i++) { await OutputMethods.Start(Brick.Socket, (ChainLayer)i, portFlag); } }
/// <summary> /// This function enables setting the output percentage speed on the device on all ports on all bricks /// This automatically enables speed control, which means the system will automatically adjust the power to keep the specified speed. /// </summary> /// <param name="portFlag">A flag indicating the ports to target. Eg PortNames.A|PortNames.C</param> /// <param name="speed">Specify output speed [-100 – 100 %]</param> public async Task SetSpeed(int speed, OutputPortFlag portFlag = OutputPortFlag.All) { for (int i = 0; i < 4; i++) { await OutputMethods.SetSpeed(Brick.Socket, (ChainLayer)i, portFlag, speed); } }
/// <summary> /// This function enables setting the output percentage power on all ports on all bricks /// </summary> /// <param name="portFlag">A flag indicating the ports to target. Eg PortNames.A|PortNames.C</param> /// <param name="power">Specify output power [-100 – 100 %]</param> public async Task SetPower(int power, OutputPortFlag portFlag = OutputPortFlag.All) { for (int i = 0; i < 4; i++) { await OutputMethods.SetPower(Brick.Socket, (ChainLayer)i, portFlag, power); } }
/// <summary> /// This function sends stop to device on all ports on all bricks /// </summary> /// <param name="portFlag">A flag indicating the ports to target. Eg PortNames.A|PortNames.C</param> /// <param name="brake">Specify break level, [0: Float, 1: Break]</param> public async Task Stop(OutputPortFlag portFlag = OutputPortFlag.All, Brake brake = Brake.Float) { for (int i = 0; i < 4; i++) { await OutputMethods.Stop(Brick.Socket, (ChainLayer)i, portFlag, brake); } }
/// <summary> /// This function enables the program to clear the tacho count used as sensor input on all ports on all bricks /// </summary> /// <param name="portFlag">A flag indicating the ports to target. Eg PortNames.A|PortNames.C</param> public async Task ClearCount(OutputPortFlag portFlag = OutputPortFlag.All) { for (int i = 0; i < 4; i++) { await OutputMethods.ResetTachoCount(Brick.Socket, (ChainLayer)i, portFlag); } }
static void Main(string[] args) { do { // INPUT VALUES Console.Clear(); Console.WriteLine("\nEnter your values' list separated with spaces.\nEx:1 3 4 3 3\n\nINSERT YOUR VALUES:"); float[] inputData = InputMethods.inputArray(); Console.WriteLine("Would you use intervals? Yes(y) No(n): "); bool useIntervals = Console.ReadLine() == "y" ? true : false; // CALCULATING STATISTICS switch (useIntervals) { case true: Console.WriteLine("How long your interval will be? "); int intervalsLength = int.Parse(Console.ReadLine()); Console.Clear(); StatisticsWithIntervals Data1 = new StatisticsWithIntervals(inputData, intervalsLength); Console.WriteLine("Your data would look like:"); OutputMethods.printTable(Data1); break; case false: StatisticsSimple Data2 = new StatisticsSimple(inputData); Console.WriteLine("Your data would look like:"); OutputMethods.printTable(Data2); break; } // OUTPUT VALUES Console.Write("Press <Enter> to make another table...\nPress any other key to exit..."); }while(Console.ReadKey().Key == ConsoleKey.Enter); }
/// <summary> /// This function enables the program to test if a output device is busy on all ports on all bricks /// </summary> public async Task <bool> IsBusy(OutputPortFlag portFlag = OutputPortFlag.All) { for (int i = 0; i < 4; i++) { bool result = await OutputMethods.IsBusy(Brick.Socket, (ChainLayer)i, portFlag); if (result) { return(true); } } return(false); }
/// <summary> /// This function enables synchonizing two motors. /// Synchonization should be used when motors should run as synchrone as possible, for example to achieve a model driving straight. /// Duration is specified in tacho counts. /// Method awaits for tacho counts and method to complete. /// </summary> /// <param name="tachoCounts">Tacho pulses, 0 = Infinite</param> /// <param name="speed">Speed level, [-100 – 100]</param> /// <param name="turnRatio">Turn ratio, [-200 - 200] /// 0 : Motor will run with same power /// 100 : One motor will run with specified power while the other will be close to zero /// 200: One motor will run with specified power forward while the other will run in the opposite direction at the same power level. /// </param> /// <param name="brake">Specify break level, [0: Float, 1: Break]</param> /// <param name="cancellationToken"></param> public async Task StepSyncComplete(int tachoCounts, int speed, int turnRatio = 0, Brake brake = Brake.Float, CancellationToken cancellationToken = default) { int initialTachoCount = await GetTachoCount(); await OutputMethods.StepSync(Brick.Socket, Layer, PortFlag, speed, turnRatio, tachoCounts, brake); if (tachoCounts > 0 && await IsBusy()) // can not wait for indefinite to complete { int tachoCount = 0; DateTime start = DateTime.Now; while (tachoCount < tachoCounts) { int currentTachoCount = await GetTachoCount(); tachoCount = Math.Abs(currentTachoCount - initialTachoCount); int todoTachoCount = tachoCounts - tachoCount; if (todoTachoCount > 0) { double elapsedTime = (DateTime.Now - start).TotalMilliseconds; double tachoCountPerMillisecond = tachoCount / elapsedTime; int delay = (int)Math.Ceiling(todoTachoCount * tachoCountPerMillisecond); if (delay > 0) { try { await Task.Delay(delay, cancellationToken); } catch (TaskCanceledException) { } } } } } }
/// <summary> /// This function enables starting the device /// </summary> protected async Task Start() { await OutputMethods.Start(Socket, Layer, PortFlag); }
/// <summary> /// This function enables setting the output percentage speed on the device. /// This automatically enables speed control, which means the system will automatically adjust the power to keep the specified speed. /// </summary> /// <param name="speed">Specify output speed [-100 – 100 %]</param> protected async Task SetSpeed(int speed) { await OutputMethods.SetSpeed(Socket, Layer, PortFlag, speed); }
/// <summary> /// This function enables setting the output percentage power /// </summary> /// <param name="power">Specify output power [-100 – 100 %]</param> protected async Task SetPower(int power) { await OutputMethods.SetPower(Socket, Layer, PortFlag, power); }
/// <summary> /// This function enables reading current Tacho count of Motor 1 /// </summary> /// <returns>tacho count</returns> public async Task <int> GetTachoCount() { return(await OutputMethods.GetTachoCount(Brick.Socket, Layer, PortName)); }
/// <summary> /// This function enables resetting the tacho count /// </summary> protected async Task Reset() { await OutputMethods.Reset(Socket, Layer, PortFlag); }
/// <summary> /// This function enables reading current Tacho count /// </summary> /// <returns>tacho count</returns> protected async Task <int> GetTachoCount() { return(await OutputMethods.GetTachoCount(Socket, Layer, PortName)); }
/// <summary> /// This function enables specifying a full power cycle in tacho counts. /// The system will automatically adjust the power level to the device to keep the specified output speed. /// RampDown specifies the power ramp up periode in tacho count, /// ContinuesRun specifies the constant power period in tacho counts, /// RampUp specifies the power down period in tacho counts. /// </summary> /// <param name="speed">Specify output speed [-100 – 100]</param> /// <param name="tachoPulsesRampUp">Tacho pulses during ramp up</param> /// <param name="tachoPulsesContinuesRun">Tacho pulses during continues run</param> /// <param name="tachoPulsesRampDown">Tacho pulses during ramp down</param> /// <param name="brake">Specify break level, [0: Float, 1: Break]</param> protected async Task StepSpeed(int speed, int tachoPulsesContinuesRun, int tachoPulsesRampUp = 0, int tachoPulsesRampDown = 0, Brake brake = Brake.Float) { await OutputMethods.StepPower(Socket, Layer, PortFlag, speed, tachoPulsesRampUp, tachoPulsesContinuesRun, tachoPulsesRampDown, brake); }
/// <summary> /// This function enables synchonizing two motors. /// Synchonization should be used when motors should run as synchrone as possible, /// </summary> /// <param name="time">Time in milliseconds, 0 = Infinite</param> /// <param name="speed">Speed level, [-100 – 100]</param> /// <param name="turnRatio">Turn ratio, [-200 - 200] /// 0 : Motors will run with same power /// 100 : One motor will run with specified power while the other will be close to zero /// 200: One motor will run with specified power forward while the other will run in the opposite direction at the same power level. /// </param> /// <param name="brake">Specify break level, [0: Float, 1: Break]</param> public async Task TimeSync(int time, int speed, int turnRatio = 0, Brake brake = Brake.Float) { Speed = speed; await OutputMethods.TimeSync(Brick.Socket, Layer, PortFlag, speed, turnRatio, time, brake); }
/// <summary> /// This function enables synchonizing two motors. /// Synchonization should be used when motors should run as synchrone as possible, for example to achieve a model driving straight. /// Duration is specified in tacho counts. /// </summary> /// <param name="tachoCounts">Tacho pulses, 0 = Infinite</param> /// <param name="speed">Speed level, [-100 – 100]</param> /// <param name="turnRatio">Turn ratio, [-200 - 200] /// 0 : Motor will run with same power /// 100 : One motor will run with specified power while the other will be close to zero /// 200: One motor will run with specified power forward while the other will run in the opposite direction at the same power level. /// </param> /// <param name="brake">Specify break level, [0: Float, 1: Break]</param> public async Task StepSync(int tachoCounts, int speed, int turnRatio = 0, Brake brake = Brake.Float) { Speed = speed; await OutputMethods.StepSync(Brick.Socket, Layer, PortFlag, speed, turnRatio, tachoCounts, brake); }
/// <summary> /// This function enables specifying a full motor power cycle in time. /// The system will automatically adjust the power level to the motor to keep the specified output speed. /// RampUp specifies the power ramp up periode in milliseconds, /// ContinuesRun specifies the constant speed period in milliseconds, /// RampDown specifies the power down period in milliseconds. /// </summary> /// <param name="speed">Specify output speed [-100 – 100]</param> /// <param name="timeRampUp">Time in milliseconds for ramp up</param> /// <param name="timeContinuesRun">Time in milliseconds for continues run</param> /// <param name="timeRampDown">Time in milliseconds for ramp down</param> /// <param name="brake">Specify break level, [0: Float, 1: Break]</param> public async Task TimeSpeed(int speed, int timeContinuesRun, int timeRampUp = 0, int timeRampDown = 0, Brake brake = Brake.Float) { Speed = speed; await OutputMethods.TimeSpeed(Brick.Socket, Layer, PortFlag, speed, timeRampUp, timeContinuesRun, timeRampDown, brake); }
/// <summary> /// This function enables specifying a full power cycle in time. /// RampUp specifies the power ramp up periode in milliseconds, /// ContinuesRun specifies the constant power period in milliseconds, /// RampDown specifies the power down period in milliseconds. /// </summary> /// <param name="power">Specify output power [-100 – 100]</param> /// <param name="timeRampUp">Time in milliseconds for ramp up</param> /// <param name="timeContinuesRun">Time in milliseconds for continues run</param> /// <param name="timeRampDown">Time in milliseconds for ramp down</param> /// <param name="brake">Specify break level, [0: Float, 1: Break]</param> public async Task TimePower(int power, int timeContinuesRun, int timeRampUp = 0, int timeRampDown = 0, Brake brake = Brake.Float) { await OutputMethods.TimePower(Brick.Socket, Layer, PortFlag, power, timeRampUp, timeContinuesRun, timeRampDown, brake); }
/// <summary> /// This function enables specifying a full power cycle in tacho counts. /// RampUp specifies the power ramp up periode in tacho count, /// ContinuesRun specifies the constant power period in tacho counts, /// RampDown specifies the power down period in tacho counts. /// </summary> /// <param name="power">Specify output power [-100 – 100]</param> /// <param name="tachoPulsesContinuesRun">Tacho pulses during continues run</param> /// <param name="tachoPulsesRampUp">Tacho pulses during ramp up</param> /// <param name="tachoPulsesRampDown">Tacho pulses during ramp down</param> /// <param name="brake">Specify break level, [0: Float, 1: Break]</param> public async Task StepPower(int power, int tachoPulsesContinuesRun, int tachoPulsesRampUp = 0, int tachoPulsesRampDown = 0, Brake brake = Brake.Float) { await OutputMethods.StepPower(Brick.Socket, Layer, PortFlag, power, tachoPulsesRampUp, tachoPulsesContinuesRun, tachoPulsesRampDown, brake); }
/// <summary> /// This function sets the polarity of the device. /// </summary> /// <param name="polarity">Polarity -1 : backward 0 : opposite direction 1 : forward</param> protected async Task SetPolarity(Polarity polarity) { await OutputMethods.SetPolarity(Socket, Layer, PortFlag, polarity); }
/// <summary> /// This function enables the program to test if the motors are busy. /// </summary> public async Task <bool> IsBusy() { return(await OutputMethods.IsBusy(Brick.Socket, Layer, PortFlag)); }
/// <summary> /// This function enables the program to test if a output device is busy. /// </summary> protected async Task <bool> IsBusy() { return(await OutputMethods.IsBusy(Socket, Layer, PortFlag)); }
/// <summary> /// This function enables setting the output percentage speed on the motors. /// This automatically enables speed control, which means the system will automatically adjust the power to keep the specified speed. /// </summary> /// <param name="speed">Specify output speed [-100 – 100 %]</param> public async Task SetSpeed(int speed) { Speed = speed; await OutputMethods.SetPower(Brick.Socket, Layer, PortFlag, speed); }
/// <summary> /// This function enables specifying a full power cycle in time. /// The system will automatically adjust the power level to the device to keep the specified output speed. /// RampUp specifies the power ramp up periode in milliseconds, /// ContinuesRun specifies the constant speed period in milliseconds, /// RampDown specifies the power down period in milliseconds. /// </summary> /// <param name="speed">Specify output speed [-100 – 100]</param> /// <param name="timeRampUp">Time in milliseconds for ramp up</param> /// <param name="timeContinuesRun">Time in milliseconds for continues run</param> /// <param name="timeRampDown">Time in milliseconds for ramp down</param> /// <param name="brake">Specify break level, [0: Float, 1: Break]</param> protected async Task TimeSpeed(int speed, int timeContinuesRun, int timeRampUp = 0, int timeRampDown = 0, Brake brake = Brake.Float) { await OutputMethods.TimeSpeed(Socket, Layer, PortFlag, speed, timeRampUp, timeContinuesRun, timeRampDown, brake); }
///<summary> ///Parse input arguments and update the global option variables ///</summary> private static void ParseArgs(string[] args) { // Loop through each entry for (int i = 0; i < args.Length; i++) { if (args[i][0] == '-') { switch (args[i]) { case "-h": case "--help": ShowHelp(); Environment.Exit(1); break; case "-t": OutputType = GetOutputType(args[i + 1]); OutputFunction = GetOutputFunction(args[i + 1]); break; case "-o": OutputMethod = GetOutputMethod(args[i + 1]); break; case "-ab": case "--add-abbreviation": var abbreviation = new Abbreviation( args[i + 1], string.Join(" ", args.Skip(3)), args[i + 2] ); DictionaryManager.AbbreviationDictionary.Add(args[i + 1], abbreviation); new DictionaryManager().Save(DictionaryManager .DictionaryLocation); Environment.Exit(1); break; case "-eb": case "--edit-abbreviation": var editedAbbreviation = new Abbreviation( args[i + 1], string.Join(" ", args.Skip(3)), args[i + 2] ); DictionaryManager.AbbreviationDictionary[args[i + 1]] = editedAbbreviation; Console.WriteLine(editedAbbreviation.Color); new DictionaryManager().Save(DictionaryManager .DictionaryLocation); Environment.Exit(1); break; case "-d": case "--dictionary": DictionaryManager.DictionaryLocation = args[i + 1]; break; case "--generate-dictionary": case "-gd": new DictionaryManager().CreateFromFile(args[i + 1]); break; default: continue; } i++; continue; } InputFiles.Add(args[i]); } }
/// <summary> /// This function enables specifying the output device type /// </summary> protected async Task SetType() { await OutputMethods.SetType(Socket, Layer, PortName, Type); }
/// <summary> /// This function sends stop to device /// </summary> /// <param name="brake">Specify break level, [0: Float, 1: Break]</param> protected async Task Stop(Brake brake = Brake.Float) { await OutputMethods.Stop(Socket, Layer, PortFlag, brake); }
//copy from Outputdevice /// <summary> /// This function enables setting the output percentage power /// </summary> /// <param name="power">Specify output power [-100 – 100 %]</param> public async Task SetPower(int power) { await OutputMethods.SetPower(Brick.Socket, Layer, PortFlag, power); }
public async Task ResetTachoCount() { await OutputMethods.ResetTachoCount(Brick.Socket, Layer, PortFlag); }