Skip to content

Commit 3e27b9b

Browse files
committed
add example to read variables from Dashboard server
1 parent 590ef14 commit 3e27b9b

25 files changed

+127
-32
lines changed

Examples/WindowsDesktop/Components/DashboardServerControl.Designer.cs

Lines changed: 80 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Examples/WindowsDesktop/Components/DashboardServerControl.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void OnOpen() { }
3535
#endregion
3636

3737
// Append command response to the console text area
38-
private void Log(CommandResponse response, string command)
38+
private void Log(CommandResponse response, string command, string messageBefore=null, string messageAfter=null)
3939
{
4040
txtConsole.AppendText(command);
4141
txtConsole.AppendText("()\r\n");
@@ -52,7 +52,9 @@ private void Log(CommandResponse response, string command)
5252
txtConsole.AppendText("FAILED : ");
5353
}
5454

55-
txtConsole.AppendText(response.ToString());
55+
if(messageBefore != null) txtConsole.AppendText(messageBefore);
56+
txtConsole.AppendText(response.ToString() ?? "");
57+
if (messageAfter != null) txtConsole.AppendText(messageAfter);
5658

5759

5860
txtConsole.SelectionBullet = false;
@@ -247,5 +249,25 @@ private void btnRestartSafety_Click(object sender, EventArgs e)
247249
var response = _ur.RestartSafety();
248250
Log(response, "RestartSafety");
249251
}
252+
253+
private void txtSendCustomCommand_Click(object sender, EventArgs e)
254+
{
255+
var response = _ur.SendCustomDashboardCommand(txtCustomCommand.Text);
256+
Log(response, "SendCustomDashboardCommand");
257+
}
258+
259+
private void btnGetVariableValue_Click(object sender, EventArgs e)
260+
{
261+
var response = _ur.GetVariable(txtVariableName.Text);
262+
if(response.Value.Type == GlobalVariableTypes.None)
263+
{
264+
Log(response, "GetVariableValue", $"Variable {txtVariableName.Text} is not declared. ");
265+
}
266+
else
267+
{
268+
Log(response, "GetVariableValue", response.Succeed ? $"{response.Value.Type} {response.Value.Name} = " : "");
269+
}
270+
}
250271
#endregion
272+
251273
}

Examples/WindowsDesktop/Components/PrimaryInterfaceControl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ private void _ur_PopupMessageReceived(object sender, PopupMessageEventArgs e)
2929

3030
private void ShowPopup(string title, string message, bool warning, bool error)
3131
{
32-
Application.OpenForms[0].Invoke(new Action(() =>
32+
MainForm.InvokeOnMainForm(new Action(() =>
3333
{
3434
var popup = new PrimaryInterfacePopup(_ur, title, message, warning, error);
3535

36-
popup.ShowDialog(Application.OpenForms[0]);
36+
popup.ShowDialog(MainForm.Instance);
3737
}));
3838
}
3939

Examples/WindowsDesktop/Components/XmlRpcControl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ private void _ur_OnXmlRpcServerRequest(object sender, XmlRpcEventArg request)
2323
var waitHandle = new AutoResetEvent(false);
2424

2525
// Open dialog in main thread
26-
this.Invoke(new Action(() =>
26+
MainForm.InvokeOnMainForm(new Action(() =>
2727
{
2828
var dlg = new XmlRpcPopup(request, waitHandle);
2929

30-
dlg.ShowDialog(this);
30+
dlg.ShowDialog(MainForm.Instance);
3131
}));
3232

3333
// Wait dialog to close

Examples/WindowsDesktop/MainForm.Designer.cs

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Examples/WindowsDesktop/MainForm.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public partial class MainForm : Form
99
// UR instance that handles connection to the robot
1010
private readonly UR _ur = new UR();
1111

12-
private static MainForm Instance;
12+
public static MainForm Instance { get; private set; }
1313

1414
#region Initialisation
1515
public MainForm()
@@ -166,4 +166,14 @@ public static void Decompile(string fullName)
166166
Instance.SelectNode(node);
167167
control?.Decompile(fullName);
168168
}
169+
170+
public static void InvokeOnMainForm(Delegate action)
171+
{
172+
if (Instance.InvokeRequired)
173+
{
174+
Instance.Invoke(action);
175+
return;
176+
}
177+
action?.DynamicInvoke();
178+
}
169179
}

Examples/WindowsDesktop/MainForm.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w
126126
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
127127
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAABE
128-
CAAAAk1TRnQBSQFMAgEBAgEAARgBAAEYAQABEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
128+
CAAAAk1TRnQBSQFMAgEBAgEAASABAAEgAQABEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
129129
AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
130130
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
131131
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA
138 Bytes
Loading
138 Bytes
Loading
159 Bytes
Loading

0 commit comments

Comments
 (0)