Sorry for repeating the question but I have read the references and I don't know why the output is not displayed. It should be something in the index because its giving me out of bounds.. but i don't know how to fix it.. Please have alook..
have a csv file MobileId;MenuTreeView;MenuName;MenuInfo;MenuAction
1042;MP_Menubaum;user_key1;user_key1;PressKey
1042;MP_Menubaum;Wait;1;Wait
1042;MP_Menubaum;TS:Coord;38%55%:0:0;TouchScreen
1042;MP_Menubaum;Wait;2;Wait
and I have the MenuInfo as a List and MenuAction as a List.
I want to get the 38 before the percentage sign in the MenuInfo List and Multiply it by the value called Length, Length is a double List that is defined in another Method..
and get the value 55 in the MenuInfo and multiply it by width (The same procedure as length)
This is what i have done but it gives me out of index....how can i multiply the right value in the L List
I uploaded the code
Loading
VulpesPosted Oct 14, 2014, 9:37 AM
These may not be the latest versions of these methods but they should suffice to point out the changes needed:
Hesham HassaneinPosted Oct 14, 2014, 9:53 AM
Hesham HassaneinPosted Oct 14, 2014, 8:27 AM
VulpesPosted Oct 14, 2014, 8:04 AM
The generatecsv method would then need a bit of extra code to sort out whether it's a 'Wait' line or not and, if it is, insert the appropriate value in the line to the written to the file.
Hesham HassaneinPosted Oct 14, 2014, 7:09 AM
I maean if it found Wait. It just reads the previous line and repeat it and put in the pause column the value inside MenuInfoList[i].-.. Putting the value is not a problem..
but the problem if there were two waits after each other..
if (MenuActionList[i].Contains("Wait")){
* if(!MenuInfoList[i]=0) continue;
* int pause=MenuInfoList[i];
// reading the previous line and repeat it
I can then put the pause inside the csvgenerate method
Hesham HassaneinPosted Oct 14, 2014, 5:33 AM
VulpesPosted Oct 13, 2014, 1:31 PM
This is broadly what I think the generatecsv method should look like now (you don't need the two other 'helper' methods):
Hesham HassaneinPosted Oct 13, 2014, 12:57 PM
VulpesPosted Oct 13, 2014, 12:10 PM
return XX; // remove this line at the end
}
Hesham HassaneinPosted Oct 13, 2014, 11:41 AM
static void addlinecsv(int MobileID) {
List
List
List
// double La=0;
// double Br=0;
// double zz=0;
int a = 4;
string[] buffer = new string[a];
string ProgramPfad = (@"C:\Robotron\MobileRobotDaten\" + MobileID + ".csv");
Menu_Tree(MobileID);
for (int i = 0; i < a;i++ )
{
buffer[i] = (MobileID + ";" + 3 + ";" + 1 + ";" + La + ";" + Br + ";" + zz + ";" + 71 + ";" + -51 + ";" + 30 + ";" + 400 + '\n');
File.AppendAllText(ProgramPfad, buffer[i] + "\r\n");
}
}
Hesham HassaneinPosted Oct 13, 2014, 11:41 AM
The Menu_Tree Method
static List
{
double Lange = 0;
double Breite = 0;
double z = 0;
int countsize = 0;
List
List
List
StreamReader reader = File.OpenText(@"C:\Robotron\Execution\MenuTree.csv");
string line2;
List
List
List
List
while ((line2 = reader.ReadLine()) != null)
{
string[] fields = line2.Split(';');
if (fields.Length != 5) continue;
if (fields[0] == "MobileId") continue;
int id = Convert.ToInt32(fields[0]);
if (id == MobileID)
{
MenuNameList.Add(fields[2]);
MenuInfoList.Add(fields[3]);
MenuActionList.Add(fields[4]);
MenuTreeViewList.Add(fields[1]);
}
}
reader.Close();
if (MenuNameList.Count() > 0)
{
Console.WriteLine("The Corresponding MenuTree Information is: ");
for (int i = 0; i < MenuNameList.Count; i++)
{
Console.WriteLine(" {0} : {1} : {2}: {3}", MenuTreeViewList[i], MenuNameList[i], MenuInfoList[i], MenuActionList[i]);
// Console.WriteLine("Please select the EndKnot you want to choose");
Console.ReadKey();
if (MenuActionList[i].Contains("TouchScreen"))
{
countsize = countsize + 1;
if (MenuInfoList[i].Contains("%")){
string a = MenuInfoList[i];
string[] words = a.Split('%');
List
List
GetLengthWidth (MobileID, out L, out W);
double X=Convert.ToDouble(words[0]);
double Y = Convert.ToDouble(words[1]);
Lange = Math.Abs(L[0]) * X / 100; //X coordinate of the Touchscreen MenuInfo
Breite = Math.Abs(W[0]) * Y / 100; //Y coordinate of the Touchscreen MenuInfo
Console.WriteLine("The corresponding coordinates (X,Y) of the Touch screen "+ words[0]+";"+ words[1]+ "" + "in mm are"+Lange+";"+Breite);
XX.Add(Lange);
YY.Add(Breite);
ZZ.Add(z);
}
}
if (MenuActionList[i].Contains("PressKey"))
{
countsize = countsize + 1;
StreamReader TT = File.OpenText(@"C:\Robotron\Execution\Tastatur.csv");
string line6;
while ((line6 = TT.ReadLine()) != null)
{
string[] fl = line6.Split(';');
if (fl[1] != MobileID.ToString()) continue;
if ((MenuInfoList[i]==fl[2]))
{
Lange = Convert.ToDouble(fl[5]);
Breite = Convert.ToDouble(fl[6]);
z = Convert.ToDouble(fl[7]);
// should get x,y,z
Console.WriteLine("The corresponding coordinate of the button is" + Lange + ";" + Breite + ";" + z);
XX.Add(Lange);
YY.Add(Breite);
ZZ.Add(z);
}
}
TT.Close();
}
}
// Console.WriteLine(countsize);
}
else
Console.WriteLine("There is no corresponding MenuName Information");
Console.ReadKey();
return XX;
}
gives me this csv file
PROJECT;SEQUENCE;STEP;XPOS;YPOS;ZPOS;WRIST;WRISTROT;SPEED;PAUSE
1002;1;1;10;20;30;71;-51;30;400
1002;2;1;20;25;30;71;-51;30;400
1002;3;1;System.Collections.Generic.List`1[System.Double];System.Collections.Generic.List`1[System.Double];System.Collections.Generic.List`1[System.Double];71;-51;30;400
1002;3;1;System.Collections.Generic.List`1[System.Double];System.Collections.Generic.List`1[System.Double];System.Collections.Generic.List`1[System.Double];71;-51;30;400
1002;3;1;System.Collections.Generic.List`1[System.Double];System.Collections.Generic.List`1[System.Double];System.Collections.Generic.List`1[System.Double];71;-51;30;400
1002;3;1;System.Collections.Generic.List`1[System.Double];System.Collections.Generic.List`1[System.Double];System.Collections.Generic.List`1[System.Double];71;-51;30;400
1002;4;1;10;20;30;71;-51;30;400
VulpesPosted Oct 13, 2014, 11:18 AM
The List variables (X, Y and Z say) will be passed in as out parameters. So all you need to do at the top of the Menu_Tree method is to instantiate them:
X = new List
Y = new List
Z = new List
As Lange, Breite and z will no longer be out parameters, you'll need to define them within the method itself:
double Lange = Breite = z = 0;
Now, each time you generate a new set of Lange, Breite and z values, just add them to the appropriate Lists:
X.Add(Lange);
Y.Add(Breite);
Z.Add(z);
There shouldn't be anything else to do and the presence of the Lists won't interfere with the rest of the existing code.
Hesham HassaneinPosted Oct 13, 2014, 11:03 AM
VulpesPosted Oct 13, 2014, 10:47 AM
There's no way around that because, as things stand, the method will always return the same set of values.
Once you have the Lists you should be able to write the whole lot to the file from within a single method using a loop. The fixed lines can be written individually before and after the loop.
Hesham HassaneinPosted Oct 13, 2014, 10:27 AM
Hesham HassaneinPosted Oct 13, 2014, 10:26 AM
what it does is that: it writes the x,y,z of the first presskey it finds and also in one line... It does not begin a new line each time
So, what am trying to do is to make a new line after the value 400 and add the vaalues line by line of the MenuAction according to if its Touchscreen or PressKey and not the first value only and repeating it.. like it does now
// Add Line to csv
static void addlinecsv(int MobileID) {
double La=0;
double Br=0;
double zz=0;
int a = Menu_Tree(MobileID, out La, out Br, out zz);
string[] buffer = new string[a];
string ProgramPfad = (@"C:\Robotron\MobileRobotDaten\" + MobileID + ".csv");
Menu_Tree(MobileID, out La, out Br, out zz);
for (int i = 0; i < a;i++ )
{
buffer[i] = (MobileID + ";" + 3 + ";" + 1 + ";" + La + ";" + Br + ";" + zz + ";" + 71 + ";" + -51 + ";" + 30 + ";" + 400);
File.AppendAllText(ProgramPfad, buffer[i]);
}
}
Hesham HassaneinPosted Oct 13, 2014, 10:11 AM
VulpesPosted Oct 13, 2014, 9:57 AM
I thought at one time you were returning Lists of doubles?
Hesham HassaneinPosted Oct 13, 2014, 9:41 AM
for MobileID 1002
Coordinates of Q in the first press key
Then Coordinates of O in pressKey
Then TS:Coord
Then T in pressKey
so x,yz of each one of those should be written line after line
So what i did is the following..
I made 3 methods the first one is adding the first 2 fixed lines.. The values of these lines are fixed
static void generatecsv(int MobileID)
{
string ProgramPfad = (@"C:\Robotron\MobileRobotDaten\" + MobileID + ".csv");
double La=0;
double Br=0;
double zz=0;
// double Lange = 0;
// double Breite = 0;
// double z = 0;
// int a = Menu_Tree(MobileID, out Lange, out Breite, out z);
Menu_Tree(MobileID, out La, out Br, out zz);
string[] buffer = new string[2];
using (System.IO.StreamWriter file = new System.IO.StreamWriter(ProgramPfad))
{
double x_robot = 10.0; // to be modified when robot works in cm
double y_robot = 20.0; // to be modified when robot works in cm
double z_robot = 30.0; // to be modified when robot works in cm
double x_distance = 10.0; // After Measurements between robot and cradle in cm
double y_distance = 5.0; // After Measurements between robot and cradle in cm
// Convert Lange, Breite, z into cm
file.WriteLine("PROJECT;SEQUENCE;STEP;XPOS;YPOS;ZPOS;WRIST;WRISTROT;SPEED;PAUSE");
buffer[0] = (MobileID + ";" + 1 + ";" + 1 + ";" + x_robot + ";" + y_robot + ";" + z_robot + ";" + 71 + ";" + -51 + ";" + 30 + ";" + 400);
buffer[1] = (MobileID + ";" + 2 + ";" + 1 + ";" + (x_robot + x_distance) + ";" + (y_robot + y_distance) + ";" + z_robot + ";" + 71 + ";" + -51 + ";" + 30 + ";" + 400);
file.WriteLine(buffer[0]);
file.WriteLine(buffer[1]);
}
}
Then The second method is adding lines on the csv file.... This is where i should aadd all the coordinates according to the mobile ID.. but what it does now.,.. It adds only one value which is the value of the first press key
// Add Line to csv
static void addlinecsv(int MobileID) {
string[] buffer = new string[1];
double La=0;
double Br=0;
double zz=0;
string ProgramPfad = (@"C:\Robotron\MobileRobotDaten\" + MobileID + ".csv");
Menu_Tree(MobileID, out La, out Br, out zz);
buffer[0] = (MobileID + ";" + 3 + ";" + 1 + ";" + La + ";" + Br + ";" + zz + ";" + 71 + ";" + -51 + ";" + 30 + ";" + 400);
File.AppendAllText(ProgramPfad, buffer[0]);
}
Then the third method is to finish the csv file by writting a fixed line
static void finishcsv(int MobileID)
{
string[] buffer = new string[1];
double La = 0;
double Br = 0;
double zz = 0;
double x_robot = 10.0; // to be modified when robot works in cm
double y_robot = 20.0; // to be modified when robot works in cm
double z_robot = 30.0; // to be modified when robot works in cm
string ProgramPfad = (@"C:\Robotron\MobileRobotDaten\" + MobileID + ".csv");
Menu_Tree(MobileID, out La, out Br, out zz);
buffer[0] = (MobileID + ";" + 4 + ";" + 1 + ";" + x_robot + ";" + y_robot + ";" + z_robot + ";" + 71 + ";" + -51 + ";" + 30 + ";" + 400);
File.AppendAllText(ProgramPfad, buffer[0]);
}
The problem now is in the second method.. it does not add all the coordinates.. It only adds the first coordinate of the first PressKey.. and the third method does not add anything yet
VulpesPosted Oct 13, 2014, 8:50 AM
Hesham HassaneinPosted Oct 13, 2014, 8:09 AM
Hesham HassaneinPosted Oct 13, 2014, 7:45 AM
Hesham HassaneinPosted Oct 13, 2014, 7:02 AM
Here is the method... but how can i specify to write the data of all the Actions except wait
static void generatecsv(int MobileID)
{
string ProgramPfad = (@"C:\Robotron\MobileRobotDaten\" + MobileID + ".csv");
double La=0;
double Br=0;
double zz=0;
Menu_Tree(MobileID, out La, out Br, out zz);
string[] buffer = new string[5];
using (System.IO.StreamWriter file = new System.IO.StreamWriter(ProgramPfad))
{
double x_robot = 10.0; // to be modified when robot works in cm
double y_robot = 20.0; // to be modified when robot works in cm
double z_robot = 30.0; // to be modified when robot works in cm
double x_distance = 10.0; // After Measurements between robot and cradle in cm
double y_distance = 5.0; // After Measurements between robot and cradle in cm
// Convert Lange, Breite, z into cm
file.WriteLine("PROJECT;SEQUENCE;STEP;XPOS;YPOS;ZPOS;WRIST;WRISTROT;SPEED;PAUSE");
for (int k = 0; k < 4; k++)
{
buffer[k] = (MobileID + ";" + 1 + ";" + 1 + ";" + x_robot + ";" + y_robot + ";" + z_robot + ";" + 71 + ";" + -51 + ";" + 30 + ";" + 400);
buffer[k+1] = (MobileID + ";" + 2 + ";" + 1 + ";" + x_robot + x_distance + ";" + y_robot + y_distance + ";" + z_robot + ";" + 71 + ";" + -51 + ";" + 30 + ";" + 400);
buffer[k+2] = (MobileID + ";" + 3 + ";" + 1 + ";" + La + ";" + Br + ";" + zz + ";" + 71 + ";" + -51 + ";" + 30 + ";" + 400);
buffer[k+3] = (MobileID + ";" + 4 + ";" + 1 + ";" + x_robot + ";" + y_robot + ";" + z_robot + ";" + 71 + ";" + -51 + ";" + 30 + ";" + 400);
file.WriteLine(buffer[k]);
}
}
}
Hesham HassaneinPosted Oct 13, 2014, 4:48 AM
Hesham HassaneinPosted Oct 13, 2014, 4:21 AM
VulpesPosted Oct 10, 2014, 12:15 PM
Hesham HassaneinPosted Oct 10, 2014, 11:58 AM
VulpesPosted Oct 10, 2014, 11:51 AM
On the "PressKey" point, I see that the column before this shows something like 'user_key1'. However, there could be several matches of this in the Tastatur.csv file. So do you want to find all matches or is there some way of identifying a single one which you want?
Also, there's definitely a problem with the code as it stands:
As you already have the relevant columns for MenuTree.csv, you should be iterating through the lines in Tastatur.csv (i.e. TT) looking for a match.
Hesham HassaneinPosted Oct 10, 2014, 11:43 AM
Hesham HassaneinPosted Oct 10, 2014, 11:16 AM
Hesham HassaneinPosted Oct 10, 2014, 10:56 AM
The first if condition is when it finds TouchScreen.. It should display the X,Y of the percentage values.. It does that at the moment
The second if condition is when it finds pressKey.. It should get the X,Y,Z coordinates from another csv file for the corresponding Letter in the column before the Presskey.. I did it but I wanna double check with you..
The third if condition is when it finds Wait.. It should do nothing..
Then after these 3 if conditions it opens a new csv file and writes the x,y,Z in it...
SO ITS NOT IMPORTANT TO DISPLAY THE VALUES AS ITS MORE IMPORTANT TO WRITE THEM IN THE CSV FILE CORRECTLY:: i WAS DISPLAYING IT IN THE FIRST STEP TO SEE IF ITS CORRECT ..
When i copy paste the whole method here it does not work.. I will attach it but please confirm if u received it.. This is my last question for you. I really appreciate ur help...
The method is attached
VulpesPosted Oct 10, 2014, 10:26 AM
If so, would you want to associate some other variable with these values, to identify where they came from, when printing them out?
Hesham HassaneinPosted Oct 10, 2014, 10:20 AM
VulpesPosted Oct 10, 2014, 10:06 AM
If that's the case, then these lines:
Hesham HassaneinPosted Oct 10, 2014, 9:58 AM
Hesham HassaneinPosted Oct 10, 2014, 9:54 AM
VulpesPosted Oct 10, 2014, 9:39 AM
if (MenuNameList.Count() > 0)
{
Console.WriteLine("The Corresponding MenuTree Information is: ");
for (int i = 0; i < MenuNameList.Count; i++)
{
Console.WriteLine(" {0} : {1} : {2}: {3}", MenuTreeViewList[i], MenuNameList[i], MenuInfoList[i], MenuActionList[i]);
// Console.WriteLine("Please select the EndKnot you want to choose");
// Console.ReadKey();
if (MenuActionList.Contains("TouchScreen") && MenuInfoList[i].Contains("%"))
{
string a = MenuInfoList[i];
string[] words = a.Split('%');
List
List
GetLengthWidth(MobileID, out L, out W);
double X=Convert.ToDouble(words[0]);
double Y = Convert.ToDouble(words[1]);
double Lange = Math.Abs(L[i]) * X / 100;
double Breite = Math.Abs(W[i]) * Y / 100;
Console.WriteLine(Lange);
First of all, I wondered whether this line:
if (MenuActionList.Contains("TouchScreen") && MenuInfoList[i].Contains("%"))
should be
if (MenuActionList[i].Contains("TouchScreen") && MenuInfoList[i].Contains("%"))
Secondly, are you wanting here to multiply EVERY member of the Lists, L and W, by X/100 and Y/100 respectively or just the L[i] and W[i] elements?
If it's the latter, are you sure that the 'i' being used here (i.e. the index of the 'TouchScreen' line in the file) will correspond to the 'i' th element of the Lists?
If it doesn't then this could be reason for the error.