public WalkControl(PythonConnection connection, double deltaSpeed, double deltaAngle, double deltaFrequency) { this.connection = connection; this.deltaSpeed = deltaSpeed; this.deltaAngle = deltaAngle; this.deltaFrequency = deltaFrequency; }
protected void OnConnectionToggleToggled(object sender, EventArgs e) { bool active = connectionToggle.Active; if (active) { commandConnection = new PythonConnection(ipEntry.Text, userNameEntry.Text, passwordEntry.Text); // Open a separate data connection: // Has to be done before sending prep_code.py as it defines necessary variables for prep_code.py videoChannel = new InputChannel(commandConnection, ipEntry.Text, 4711); using (var sr = new System.IO.StreamReader("prep_code.py")) { String line; while ((line = sr.ReadLine()) != null) { commandConnection.execute(line); } } } else { controlToggle.Active = false; cameraToggle.Active = false; commandConnection.execute("close()"); commandConnection.Dispose(); videoChannel.Dispose(); commandConnection = null; videoChannel = null; } stiffnessToggle.Sensitive = active; cameraToggle.Sensitive = active; ttsButton.Sensitive = active; ipEntry.Sensitive = !active; userNameEntry.Sensitive = !active; passwordEntry.Sensitive = !active; }
public void CheckExecute() { var result = new PythonConnection().ExecuteCommand("print(\"h\")"); Assert.AreEqual("h\r\n", result); }
public PythonInterfaceConnection() { InitializeComponent(); Python = new PythonConnection(); Python.ImportScipyStack(); }
/// <summary> /// Basic anaconda test /// </summary> public static void TestScript01() { //Python script file for test const string fileName = @"TestScript01.py"; var scriptFile = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName)); if (!scriptFile.Exists) { throw new FileNotFoundException("Where is the script?", scriptFile.FullName); } //Setup python environment const string pythonHome = @"C:\Users\Pike\anaconda3"; //<-- Replace it with your own path to anaconda //Compose PATH environment variable var lib = Path.Combine(pythonHome, "Lib"); var dlls = Path.Combine(pythonHome, "DLLs"); var packages = Path.Combine(lib, "site-packages"); var libraryBin = Path.Combine(pythonHome, "Library", "bin"); //Create connection string var stringBuilder = new PythonConnectionStringBuilder { File = scriptFile.FullName, PythonHome = pythonHome, Path = string.Join(";", pythonHome, lib, dlls, packages, libraryBin) }; using (var connection = new PythonConnection()) { connection.ConnectionString = stringBuilder.ConnectionString; connection.Open(); using (var command = connection.CreateCommand()) { //Set query command text. It will be passed to python "query" variable command.CommandText = "Hello from ADO.Net!"; //Set query parameters. It will be passed to python "params" variable command.Parameters.Add(new PythonParameter { ParameterName = "bool", Value = true }); command.Parameters.Add(new PythonParameter { ParameterName = "dt", Value = DateTime.Today }); command.Parameters.Add(new PythonParameter { ParameterName = "double", Value = 1235.0 }); command.Parameters.Add(new PythonParameter { ParameterName = "int", Value = 789 }); command.Parameters.Add(new PythonParameter { ParameterName = "long", Value = 1024L }); command.Parameters.Add(new PythonParameter { ParameterName = "string", Value = "String parameter" }); /* * Python script must have "result" variable of type pandas DataFrame. * This variable data will be transfered to DbDataReader */ using (var reader = command.ExecuteReader()) { var datatable = new DataTable(); datatable.Load(reader); //Print data PrintDataTable(datatable); } } } Console.WriteLine("Done!"); Console.ReadLine(); }
/// <summary> /// Use anaconda virtual environment /// </summary> public static void TestScript05() { //Python script text const string scriptText = @"import pandas as pd query_text = globals()['query'] if 'query' in globals() else None print('Query text is:', query_text) query_params = globals()['params'] if 'params' in globals() else None print('Query parameters:', query_params) result = pd.DataFrame( [[True, 99.0], [True, 56.1], [False, 73.2], [False, 69.3]])" ; //Setup python environment const string pythonHome = @"C:\Users\Pike\anaconda3\envs\Test"; //<-- Replace it with your own path to anaconda virtual environment //Compose PATH environment variable var lib = Path.Combine(pythonHome, "Lib"); var dlls = Path.Combine(pythonHome, "DLLs"); var packages = Path.Combine(lib, "site-packages"); var libraryBin = Path.Combine(pythonHome, "Library", "bin"); //Create connection string var stringBuilder = new PythonConnectionStringBuilder { PythonHome = pythonHome, Path = string.Join(";", pythonHome, lib, dlls, packages, libraryBin) }; using (var connection = new PythonConnection()) { connection.ConnectionString = stringBuilder.ConnectionString; connection.Open(); using (var command = connection.CreateCommand()) { //In this case there is no "query" global variable in python command.CommandText = scriptText; //Set query parameters. It will be passed to python "params" variable command.Parameters.Add(new PythonParameter { ParameterName = "bool", Value = true }); command.Parameters.Add(new PythonParameter { ParameterName = "dt", Value = DateTime.Today }); command.Parameters.Add(new PythonParameter { ParameterName = "double", Value = 1235.0 }); command.Parameters.Add(new PythonParameter { ParameterName = "int", Value = 789 }); command.Parameters.Add(new PythonParameter { ParameterName = "long", Value = 1024L }); command.Parameters.Add(new PythonParameter { ParameterName = "string", Value = "String parameter" }); /* * Python script must have "result" variable of type pandas DataFrame. * This variable data will be transfered to DbDataReader */ using (var reader = command.ExecuteReader()) { var datatable = new DataTable(); datatable.Load(reader); //Print data PrintDataTable(datatable); } } } Console.WriteLine("Done!"); Console.ReadLine(); }
/// <summary> /// Basic python test (environment variables already set by python installer) /// </summary> public static void TestScript04() { //Python script text const string scriptText = @"import pandas as pd query_text = globals()['query'] if 'query' in globals() else None print('Query text is:', query_text) query_params = globals()['params'] if 'params' in globals() else None print('Query parameters:', query_params) result = pd.DataFrame( [[True, 99.0], [True, 56.1], [False, 73.2], [False, 69.3]])" ; //Setup python environment const string pythonHome = @"C:\Python37"; //<-- Replace it with your own path to python 3.7 //Create connection string var stringBuilder = new PythonConnectionStringBuilder //<-- No need to set File property { PythonHome = pythonHome }; using (var connection = new PythonConnection()) { connection.ConnectionString = stringBuilder.ConnectionString; connection.Open(); using (var command = connection.CreateCommand()) { //In this case there is no "query" global variable in python command.CommandText = scriptText; //Set query parameters. It will be passed to python "params" variable command.Parameters.Add(new PythonParameter { ParameterName = "bool", Value = true }); command.Parameters.Add(new PythonParameter { ParameterName = "dt", Value = DateTime.Today }); command.Parameters.Add(new PythonParameter { ParameterName = "double", Value = 1235.0 }); command.Parameters.Add(new PythonParameter { ParameterName = "int", Value = 789 }); command.Parameters.Add(new PythonParameter { ParameterName = "long", Value = 1024L }); command.Parameters.Add(new PythonParameter { ParameterName = "string", Value = "String parameter" }); /* * Python script must have "result" variable of type pandas DataFrame. * This variable data will be transfered to DbDataReader */ using (var reader = command.ExecuteReader()) { var datatable = new DataTable(); datatable.Load(reader); //Print data PrintDataTable(datatable); } } } Console.WriteLine("Done!"); Console.ReadLine(); }
public SimplePythonGraphForm() { InitializeComponent(); Python = new PythonConnection(); Python.ImportScipyStack(); }
public JointControl(PythonConnection connection, string joint, double max, double speed) { this.connection = connection; this.command = String.Format("print startMove(\"{0}\", {1}, {2})", joint, toString(max), toString(speed)); }