private void buttonOK_Click(object sender, EventArgs e) { StringBuilder resultBuffer = new StringBuilder(R7.STRING_SIZE); StringBuilder email = new StringBuilder(R7.STRING_SIZE); StringBuilder password = new StringBuilder(R7.STRING_SIZE); email.Append(textBoxEmail.Text); password.Append(textBoxPassword.Text); R7.Login(resultBuffer, R7.STRING_SIZE, email, password); //MessageBox.Show("login test" + resultBuffer); int year = 0, month = 0, day = 0; R7.CheckLicense(resultBuffer, ref year, ref month, ref day); if (new DateTime(year, month, day) < DateTime.Now) { //以後當 license 過期時,應該是在這邊跳 FormLogin 出來 //MessageBox.Show("Login not success:" + resultBuffer); if (resultBuffer.Length == 0) { MessageBox.Show("Internet connection to www.openrobot.club is not available!"); } else { MessageBox.Show(resultBuffer.ToString()); } } else { R8.IsLogin = true; this.Close(); } }
public void resetButton() { foreach (Button b in buttons) { b.Dispose(); } buttons.Clear(); buttonsLocationY = buttonStartY; //labels foreach (Label l in labels) { l.Dispose(); } labels.Clear(); //urls functionsURL.Clear(); int functionGroupNum = 0; int functionNum = 0; StringBuilder str = new StringBuilder(R7.STRING_SIZE); StringBuilder str2 = new StringBuilder(R7.STRING_SIZE); functionGroupNum = R8.GetFunctionGroupNum(); //20170124 leo: 加入 BrainVersion R7.GetVersion(str, R7.STRING_SIZE); //addLabel("version:" + str.ToString()); buttonsLocationY += 5; for (int i = 0; i < functionGroupNum; i++) { R8.GetFunctionGroupName(str, R7.STRING_SIZE, i); addLabel(str.ToString());//GroupName functionNum = R8.GetFunctionNumInGroup(i); for (int j = 0; j < functionNum; j++) { R8.GetFunctionName(str, R7.STRING_SIZE, i, j); R8.GetFunctionDoc(str2, R7.STRING_SIZE, i, j); //System.Console.WriteLine("getURL:" + str2); if (isInSearchMode) { if (str.ToString().ToLower().Contains(textBoxSearch.Text.ToLower())) { addButton(str.ToString(), str2.ToString()); } } else { addButton(str.ToString(), str2.ToString()); } } } str.Clear(); str2.Clear(); this.Text = str_Libraries + " " + buttons.Count + " of " + allFunctionCount; return; }
private void loadButtons() { allFunctionCount = 0; //addButton("OpenImage", "OpenImage"); //addButton("SaveImage", "SaveImage"); //addButton("DebugImage", "DebugImage"); //addButton("Binarize", "Binarize"); //20170123 leo : 改為從 function list 的 json 檔案 動態產生 buttonsLocationY = buttonStartY; int functionGroupNum = 0; int functionNum = 0; StringBuilder str = new StringBuilder(R7.STRING_SIZE); StringBuilder str2 = new StringBuilder(R7.STRING_SIZE); functionGroupNum = R8.GetFunctionGroupNum(); //20170124 leo: 加入 BrainVersion R7.GetVersion(str, R7.STRING_SIZE); //addLabel("version:" + str.ToString()); buttonsLocationY += 5; functionURL.Clear(); for (int i = 0; i < functionGroupNum; i++) { R8.GetFunctionGroupName(str, R7.STRING_SIZE, i); addLabel(str.ToString());//GroupName functionNum = R8.GetFunctionNumInGroup(i); for (int j = 0; j < functionNum; j++) { allFunctionCount++; R8.GetFunctionName(str, R7.STRING_SIZE, i, j); R8.GetFunctionDoc(str2, R7.STRING_SIZE, i, j); //System.Console.WriteLine("getURL:" + str2); addButton(str.ToString(), str2.ToString()); //20170603 leo: 增加 "如果 function 有說明 URL ,在右方 function 小視窗中的右下方顯示 help 按鈕。" //所以有url 連結的 name 要存起來 functionURL.Add(str.ToString(), str2.ToString()); } } str.Clear(); str2.Clear(); return; }
private void buttons_MouseDown(object sender, MouseEventArgs e) { if (e.Clicks == 2) { //20170324 leo add 雙擊時切換 function enable //formMain.formFunction.checkBox.Checked = !formMain.formFunction.checkBox.Checked; //20171016 此功能改為[點擊 function block 兩下,執行 debug run 到該 function。] if (formMain.programFilePath == null) { MessageBox.Show("Please save program before run it."); return; } formMain.saveTempFile(); StringBuilder workSpacePathBuffer = new StringBuilder(FormMain.workSpacePath + "\\", R7.STRING_SIZE); int r7h = R7.New(); FileStream sourceFile = new FileStream(formMain.tempProgramFilePath, FileMode.Open); BinaryReader binReader = new BinaryReader(sourceFile); byte[] programFileBytes = new byte[sourceFile.Length + 1]; for (long i = 0; i < sourceFile.Length; i++) { programFileBytes[i] = binReader.ReadByte(); } programFileBytes[sourceFile.Length] = 0; sourceFile.Close(); binReader.Close(); //所以這邊需要 Debug 版 , R7_RunToTargetFunction 多傳一個 isDebug 進去 //.....但是這樣跑的話,會發生 Debug Image 被 Show 出來後,按 Enter 關不掉 (必須一個個視窗按右上角的 x 關閉),估計原因為這邊不會停下來等,所以直接被 R7.Release 了。 //所以在 R7_RunToTargetFunction 裡面加上[如果是 debug 模式則進行 cv::waitKey] int result = R7.RunToTargetFunction(r7h, programFileBytes, new Byte[] { 0 }, FormMain.GetBytes(workSpacePathBuffer.ToString()), formMain.formFunction.function.sn, 1); result = R7.Release(r7h); } else { moveFrom = buttons.IndexOf((Button)sender); (sender as Button).DoDragDrop((sender as Button).Text, DragDropEffects.Move); } return; }
public static void writeProgramXml(string path) { XElement xml = new XElement("program"); //根據 http://stackoverflow.com/questions/27548227/add-new-xelements-with-new-line-in-xdocument-with-preservewhitespace-loadoptions //換行需要自己加... xml.Add(Environment.NewLine); xml.Add(new XElement("version", FormMain.r8.getVersion())); xml.Add(Environment.NewLine); //xml.Add(new XElement("workSpacePath", FormMain.workSpacePath));//20170120 leo: 寫檔時,應該也把 workSpacePath 寫進去 //xml.Add(Environment.NewLine);//20170306 leo: 改為不寫入 workSpacePath xml.Add(new XElement("functionSnMax", FormMain.r8.getFunctionSnMax())); xml.Add(Environment.NewLine); xml.Add(new XElement("variableSnMax", FormMain.r8.getVariableSnMax())); xml.Add(Environment.NewLine); xml.Add(new XElement("functionSnCount", FormMain.r8.getFunctionsCount())); xml.Add(Environment.NewLine); xml.Add(new XElement("variableSnCount", FormMain.r8.getVariablesCount())); xml.Add(Environment.NewLine); XElement functionsXml = new XElement("functions"); xml.Add(functionsXml); xml.Add(Environment.NewLine); functionsXml.Add(Environment.NewLine); int i, j; Function function; XElement functionXml = null; for (i = 0; i < FormMain.r8.getFunctionSnLast(); i++) { function = FormMain.r8.functions[i]; if (function == null) { continue; } functionXml = new XElement("function"); functionXml.Add(Environment.NewLine); functionXml.Add(new XElement("sn", function.sn)); functionXml.Add(Environment.NewLine); functionXml.Add(new XElement("name", function.name)); functionXml.Add(Environment.NewLine); functionXml.Add(new XElement("posY", function.posY)); functionXml.Add(Environment.NewLine); if (function.enable) { functionXml.Add(new XElement("enable", "1")); } else { functionXml.Add(new XElement("enable", "0")); } functionXml.Add(Environment.NewLine); functionXml.Add(new XElement("remark", function.remark)); functionXml.Add(Environment.NewLine); if (R8.HAS_POS) { functionXml.Add(new XElement("posX", function.getPosX())); functionXml.Add(Environment.NewLine); functionXml.Add(new XElement("posY", function.getPosY())); functionXml.Add(Environment.NewLine); } for (j = 0; j < function.parameters.Count; j++) { functionXml.Add(new XElement("variableSn", function.parameters.ElementAt(j).variableSn)); functionXml.Add(Environment.NewLine); } functionsXml.Add(functionXml); functionsXml.Add(Environment.NewLine); } XElement variablesXml = new XElement("variables"); xml.Add(variablesXml); xml.Add(Environment.NewLine); variablesXml.Add(Environment.NewLine); StringBuilder str = new StringBuilder(R7.STRING_SIZE); Variable variable; XElement variableXml = null; for (i = 0; i < FormMain.r8.getVariableSnLast(); i++) { variable = FormMain.r8.variables[i]; if (variable == null) { continue; } variableXml = new XElement("variable"); variableXml.Add(Environment.NewLine); variableXml.Add(new XElement("sn", variable.sn)); variableXml.Add(Environment.NewLine); variableXml.Add(new XElement("name", variable.name)); variableXml.Add(Environment.NewLine); //20170119 leo 今天討論後, type 要改為 string 小寫 //variableXml.Add(new XElement("type", variable.type)); //variableXml.Add(new XElement("type", Enum.GetName(typeof(Variable.VariableType), variable.type).ToLower())); //variableXml.Add(new XElement("type", R8.typeArray[variable.type].ToLower())); R8.GetVariableType(str, R7.STRING_SIZE, variable.type); variableXml.Add(new XElement("type", str)); variableXml.Add(Environment.NewLine); variableXml.Add(new XElement("value", variable.value)); variableXml.Add(Environment.NewLine); variableXml.Add(new XElement("remark", variable.remark)); variableXml.Add(Environment.NewLine); variablesXml.Add(variableXml); variablesXml.Add(Environment.NewLine); } str.Clear(); //xml.Save(path); //20180212 現在這邊要求要加標頭: /* #R7 # -*- coding: utf-8 -*- # R7 version 1.8.6 */ //改用 stream StreamWriter streamWriter = new StreamWriter(path); streamWriter.WriteLine("#!R7"); streamWriter.WriteLine("# -*- coding: utf-8 -*-"); StringBuilder sb = new StringBuilder(1024); R7.GetVersion(sb, 1024); streamWriter.WriteLine("# R7 version " + sb.ToString()); sb.Clear(); xml.Save(streamWriter); streamWriter.Close(); return; }