sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #27993
[Question #254005]: Calling Sikuli from my C# Code
New question #254005 on Sikuli:
https://answers.launchpad.net/sikuli/+question/254005
Hello,
I developed a C# Code that should be able to connect to the sikuli to run a specific program that tests mobile devices. when i run the C# Code... It displays the following "trying to connect to sikuli-IDE.exe" and then nothing happens..,. where does the problem exist?..
Here is my C# Code. I am running it on Visual Studio 2013. Thanks in advance
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
///using dowStepType;
using MySql.Data;
using MySql.Data.MySqlClient;
using System.Data;
using System.Diagnostics;
// using java.io.IOException;
// using java.io.File;
// using java.io.FileWriter;
//http://msdn.microsoft.com/en-us/library/8bh11f1k.aspx
namespace WindowsFormsApplication1
{
static class Program
{
/// <summary>
/// Der Haupteinstiegspunkt f?r die Anwendung.
/// </summary>
[STAThread]
static void Main(/*string[] args*/)
{
/* string VRB = args[0] ;*/
string vendor = "Nokia"; //"Nokia"; Appel_IPhone 4\IP_DOW\Reference\1_ShowCase_MenuTree
string model = "Lava"; //"Lava";
string Menutree = "SL_Menubaum"; //"SL_Menubaum";
string EndNote = "End9"; //"End2";
string device = vendor + "_" + model;
double Breite = 0;
double L?nge = 0;
DataTable dt = new DataTable();
/* Picture Path*/ string PicturePath;
///Debug.WriteLine("heeeey");
LoadCsv(device, Menutree, EndNote);
dt = GetCoord(dt, device, Menutree, EndNote);
/* Picture Path*/ GetLaengeBreite(dt, out L?nge, out Breite, out PicturePath);
GenerateCsv(dt, device, Menutree, EndNote, L?nge, Breite, PicturePath);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new Form1());
}
static void GetLaengeBreite(DataTable dt, out double L?nge, out double Breite,out string PicturePath)
{
int i = 0;
while (dt.Rows[i].ItemArray[0].ToString().Contains("End"))
{
i++;
}
string Path = dt.Rows[i].ItemArray[2].ToString();
PicturePath = "Y:\\Mobile_Data\\" + Path ;
//MySqlConnection conn = new MySqlConnection("server=10.2.151.147;port=3306;database=test;uid=root;pwd=service");
//conn.Open();
System.Drawing.Image img = System.Drawing.Image.FromFile(PicturePath);
Breite = img.Width;
L?nge = img.Height;
/// System.Diagnostics.Debug.WriteLine();
//conn.Close();
/*"@C:\\*/
//\\10.2.151.147\MobileRobot6\Mobile_Data\ "\\\\10.2.151.147\MobileRobot6\Mobile_Data\";
//L?nge = 5.5;
//Breite = 5.5;
}
static DataTable GetCoord(DataTable dt, string objectundertest, string testarea, string EndNote)
{
MySqlConnection conn = new MySqlConnection("server=10.2.151.147;port=3306;database=test;uid=root;pwd=service");
conn.Open();
//string query = "SELECT MenuInfo FROM test.menutree WHERE MenuTreeView='" + testarea + "' AND MenuName='TS:Coord' AND MenuImage LIKE '%" + objectundertest + "%' ";
string query = "SELECT MenuName, MenuInfo, MenuImage FROM test.menutree WHERE MenuTreeView = '" + testarea + "' AND (MenuName = 'TS:Coord' AND MenuImage LIKE '%" + objectundertest + "%') OR (MenuName LIKE 'End%' AND MenuTreeView = '" + testarea + "') AND MobileId = (SELECT MobileId FROM test.menutree WHERE MenuTreeView = '" + testarea + "' AND MenuImage LIKE '%" + objectundertest + "%' LIMIT 1)";
//DataTable dt = new DataTable();
MySqlDataAdapter adptr = new MySqlDataAdapter(query, conn);
adptr.Fill(dt);
//GenerateCsv(objectundertest, testarea, EndNote, dt);
conn.Close();
///Console.WriteLine("hello");
return (dt);
}
static void GenerateCsv(DataTable dt, string device, string Menutree, string EndNote, double L?nge, double Breite, string PicturePath)
{
string ProgramPfad = (@"C:\Robotron\MobileRobotDaten\" + device + "_" + Menutree + "_" + EndNote + ".csv");
using (System.IO.StreamWriter file = new System.IO.StreamWriter(ProgramPfad))
{
file.WriteLine("PROJECT;SEQUENCE;STEP;XPOS;YPOS;ZPOS;WRIST;WRISTROT;SPEED;PAUSE");
int a = 1;
int b = 1;
string[] buffer = new string[dt.Rows.Count];
for (int i = 0; i < (3* dt.Rows.Count); i++)
{
string end = dt.Rows[i].ItemArray[0].ToString();
string Prozent = dt.Rows[i].ItemArray[1].ToString();
try{
if (!end.Contains("End"))
{
Prozent = Calculate(Prozent, L?nge, Breite);
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
if (end.Contains(EndNote))
{
foreach (string strg in buffer)
{
file.WriteLine(strg);
}
/* Picture Path*/ file.WriteLine(PicturePath);
break;
}
/* Anpassen Z*/ buffer[b-1] = (device + ";" + a + ";" + 1 + ";" + Prozent + ";" + "3" + ";" + 71 + ";" + -51 + ";" + 40 + ";" + 400);
b++;
/* Anpassen Z*/ buffer[b - 1] = (device + ";" + a + ";" + 2 + ";" + Prozent + ";" + "1,1" + ";" + 71 + ";" + -51 + ";" + 10);
b++;
/* Anpassen Z*/ buffer[b - 1] = (device + ";" + a + ";" + 3 + ";" + Prozent + ";" + "3" + ";" + 71 + ";" + -51 + ";" + 25 + ";" + 100);
a++;
b++;
if (end.Contains("End"))
{
Array.Clear(buffer, 0, buffer.Length);
a = 1;
b = 1;
}
}
}
}
static string Calculate(string Prozent, double L?nge, double Breite)
{
double x = Convert.ToDouble(Prozent.Substring(0, 2));
double y = Convert.ToDouble(Prozent.Substring(3, 2));
/* Anpassen*/ double Umrechnung = 1;
/* Anpassen*/ double Faktor = 1;
double distance_x = 26;
double distance_y = 15.5;
/* Anpassen*/ x = (Breite/Umrechnung)*(x/100)*Faktor + distance_x;
/* Anpassen*/ y = (L?nge /Umrechnung)*(y/100)*Faktor + distance_y;
/* Anpassen Z */
Prozent = x + ";" + y;
return(Prozent);
}
static void LoadCsv(string device, string Menutree, string EndNote)
{
Process StartProgram = new Process();
string temp = device + "_" + Menutree + "_" + EndNote+".csv";
//string tmp = Menutree + ".csv";
/* Anpassen*/ StartProgram.StartInfo.FileName = "C:\\Robotron\\Sikuli\\runIDE.cmd";
/* Anpassen*/ StartProgram.StartInfo.Arguments = "-r " + "C:\\Robotron\\Execution\\Ubenannt.sikuli" + " --args "+temp;
StartProgram.Start();
// "\\\\10.2.151.142\\c$\\Robotron\\Sikuli\\runIDE.cmd"
// "\\\\10.2.151.142\\c$\\Robotron\\Execution\\1Test.sikuli"
}
}
}
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.