sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #28060
[Question #254105]: How to link an argument of a batch file from visual studio to Sikuli
New question #254105 on Sikuli:
https://answers.launchpad.net/sikuli/+question/254105
Hello,
I wanted to pass a string through a batch file on visual studio and then link it to Sikuli. I managed to path the string on visual studio but i need to import the argument to Sikuli because i am running sikuli through Visual studio. Below you will find the Sikuli and C# Code. I think what is missing is importing something at the beginning but i don't know what is it. Thanks in advance
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Threading.Tasks;
using System.Windows.Forms;
//using dowStepType;
using MySql.Data;
using MySql.Data.MySqlClient;
using System.Data;
using System.ComponentModel;
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] ;*/
/* Process proc = new Process();
proc.StartInfo.FileName = //C:\\Robotron\\Bat-scripts\\Ubenannt.bat;
proc.StartInfo.Arguments = String.Format("Nokia", "Lava", "SL_Menubaum", "End9");
//set the rest of the process settings
proc.Start(); */
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "C:\\Robotron\\Bat-scripts\\Ubenannt.bat";
p.StartInfo.Arguments = String.Format("Nokia", "Lava", "SL_Menubaum", "End9");
/* p.StartInfo.FileName = "Ubenannt.bat"; */
p.Start();
//set the rest of the process settings
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";
StartProgram.StartInfo.FileName = "C:\\Programme\\Sikuli X\\Sikuli-IDE.exe";
//StartProgram.StartInfo.FileName = "java";
//StartProgram.StartInfo.Arguments = "C:\\Robotron\\Sikuli\\sikuli-ide.jar";
//StartProgram.StartInfo.Arguments = "-jar C:\\Robotron\\Sikuli\\sikuli-ide.jar -d 3 -c";
/* Anpassen*/ StartProgram.StartInfo.Arguments = "-r " + "C:\\Robotron\\Execution\\Ubenannt.sikuli" + " --args "+temp;
//StartProgram.StartInfo.Arguments = "-r " + "C:\\Robotron\\Bat-scripts\\Ubenannt.bat";
StartProgram.Start();
// "\\\\10.2.151.142\\c$\\Robotron\\Sikuli\\runIDE.cmd"
// "\\\\10.2.151.142\\c$\\Robotron\\Execution\\1Test.sikuli"
}
}
}
SIKULI CODE
import subprocess
import socket
import sys
doubleClick("tilwblii-1.png")
wait(2)
wait("1394119359860.png",800)
if exists ("1389289136624.png"):
type("\t")
click("1392113044972.png")
#if exists("1395245707711.png"):
# click("1395245707711.png")
#if not exists("1395245707711.png"):
# click("1389618618243.png")
#else:
#popup("COM Problem Occured
# subprocess.call(["java","-jar","C:\\tmp\\ErrorRequest.jar"])
# exit()
click("1389289233893.png")
wait(1)
if exists("1395405604694.png"):
type("\n")
type("\t")
type("\n")
click(Pattern("1389289314060.png").targetOffset(18,7))
# if exists("1395409368599.png"):
# exists("1389617017477.png")
# click("1389617037044.png")
# click("1392803175668.png")
# click("1392803661372.png")
# click(Pattern("1394119959244.png").similar(0.85),1)
wait(3)
# paste("ConfigSSC32newRobot_Touch.cfg")
paste("C:\Robotron\MobileRobotDaten\ConfigSSC32newRobot_Touch.cfg\n")
click("1389617054895.png")
# else:
# popup("Initialisierung Problem Occured")
# subprocess.call(["java","-jar","C:\\tmp\\ErrorRequest.jar"])
# exit()
wait(1)
type("\n")
#type("\t")
type("\n")
#click(Pattern("1389617071904.png").targetOffset(-42,34))
#click(Pattern("1389617085107.png").targetOffset(-44,64))
#click()
click(Pattern("1389617149998.png").targetOffset(0,29))
# click(Pattern("1390402550990.png").similar(0.89))
#Import Parser & subprocess
#Handover of parameters
MenuTreeName = (sys.argv[3])
#MenuTreeName="Robotron"
popup ((MenuTreeName))
#MenuTreeName = input("MenuTreeName ohne CSV")
ans = "notReady" #sockpaste(paste(paste(text)
#.recv(20)
i=0
# Daten in Rios Laden
click("1392111457564.png")
if exists("1392115325686.png"): #L?scht alle Projekte
click("1392115325686.png")
click("1392115311711.png")
click("1392111480732.png")
wait(1)
#paste("C:\Robotron\MobileRobotDaten\"+MenuTreeName+".csv")
#type("\n")
paste(MenuTreeName)
click("1392113026155.png")
type("\n")
wait(1)
#click("1392113044972.png")
type("\n")
wait(1)
#click("1392113065237.png")
type("\n")
#click("1392113078411.png")
#type("\n")
click(Pattern("1392113147925.png").targetOffset(191,-3))
#type("\t")
#type("\n")
#click("1392113191994.png")
type("\t")
type("\t")
type("\t")
type("\n")
click("PPlay.png")
# Program straten
#PORT = 55000
#HOST = '10.2.151.142'
#project = ("<project_select:%s>"&MenuTreeName)
#play = ("project:play>")
#sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#sock.connect((HOST,PORT))
#while ans != ("*Ready*"):
# sock.send("<state>")
# ans = sock.recv(8)
# if i==5000: #Zahl ?berarbeiten
# subprocess.call(["java","-jar","C:\\tmp\\ErrorRequest.jar"])
# exit()
# i= i + 1
#sock.send(project)
#sock.send(play)
#wait(2)
#ans= ("*notReady*")
#while ans != ("*Ready*"):
# sock.send("<state>")
# ans = sock.recv(8)
#sock.close()
#click("1392818470576.png")
#else:
#popup("Virtual COM musst be active")
#subprocess.call(["java","-jar","C:\\tmp\\ErrorRequest.jar"])
# exit()
#Finished Message to scheduler
subprocess.call(["java","-jar","C:\\tmp\\Finished.jar"])
closeApp("cmd.exe")
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.