Fixing div by zero in network signal animation code of GP1212 displays.
2 using System.Collections.Generic;
3 using System.ComponentModel;
8 using System.Threading.Tasks;
9 using System.Windows.Forms;
10 using System.ServiceModel;
11 using System.ServiceModel.Channels;
12 using System.Diagnostics;
16 namespace SharpDisplayClient
18 public partial class MainForm : Form
20 public StartParams Params { get; set; }
23 DisplayClient iClient;
25 ContentAlignment Alignment;
26 DataField iTextFieldTop;
34 InitializeComponent();
35 Alignment = ContentAlignment.MiddleLeft;
36 iTextFieldTop = new DataField(0);
42 /// <param name="sender"></param>
43 /// <param name="e"></param>
44 private void MainForm_Load(object sender, EventArgs e)
46 iClient = new DisplayClient(this);
49 //Connect using unique name
50 //string name = DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt");
51 string name = "Client-" + (iClient.ClientCount() - 1);
52 iClient.SetName(name);
53 //Text = Text + ": " + name;
54 Text = "[[" + name + "]] " + iClient.SessionId;
57 textBoxTop.Text = iClient.Name;
58 textBoxBottom.Text = iClient.SessionId;
62 //Parameters where specified use them
63 if (Params.TopText != "")
65 textBoxTop.Text = Params.TopText;
68 if (Params.BottomText != "")
70 textBoxBottom.Text = Params.BottomText;
73 Location = Params.Location;
75 SetBasicLayoutAndText();
82 public delegate void CloseConnectionDelegate();
83 public delegate void CloseDelegate();
88 public void CloseConnectionThreadSafe()
90 if (this.InvokeRequired)
92 //Not in the proper thread, invoke ourselves
93 CloseConnectionDelegate d = new CloseConnectionDelegate(CloseConnectionThreadSafe);
94 this.Invoke(d, new object[] { });
98 //We are in the proper thread
101 string sessionId = iClient.SessionId;
102 Trace.TraceInformation("Closing client: " + sessionId);
104 Trace.TraceInformation("Closed client: " + sessionId);
114 public void CloseThreadSafe()
116 if (this.InvokeRequired)
118 //Not in the proper thread, invoke ourselves
119 CloseDelegate d = new CloseDelegate(CloseThreadSafe);
120 this.Invoke(d, new object[] { });
124 //We are in the proper thread
130 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
132 CloseConnectionThreadSafe();
135 public bool IsClientReady()
137 return (iClient != null && iClient.IsReady());
140 private void buttonAlignLeft_Click(object sender, EventArgs e)
142 Alignment = ContentAlignment.MiddleLeft;
143 textBoxTop.TextAlign = HorizontalAlignment.Left;
144 textBoxBottom.TextAlign = HorizontalAlignment.Left;
147 private void buttonAlignCenter_Click(object sender, EventArgs e)
149 Alignment = ContentAlignment.MiddleCenter;
150 textBoxTop.TextAlign = HorizontalAlignment.Center;
151 textBoxBottom.TextAlign = HorizontalAlignment.Center;
154 private void buttonAlignRight_Click(object sender, EventArgs e)
156 Alignment = ContentAlignment.MiddleRight;
157 textBoxTop.TextAlign = HorizontalAlignment.Right;
158 textBoxBottom.TextAlign = HorizontalAlignment.Right;
161 private void buttonSetTopText_Click(object sender, EventArgs e)
163 //TextField top = new TextField(0, textBoxTop.Text, ContentAlignment.MiddleLeft);
164 iTextFieldTop.Text = textBoxTop.Text;
165 iTextFieldTop.Alignment = Alignment;
166 bool res = iClient.SetField(iTextFieldTop);
170 MessageBox.Show("Create you fields first", "Field update error", MessageBoxButtons.OK, MessageBoxIcon.Error);
176 private void buttonSetText_Click(object sender, EventArgs e)
178 SetBasicLayoutAndText();
181 void SetBasicLayoutAndText()
183 //Set one column two lines layout
184 TableLayout layout = new TableLayout(1, 2);
185 iClient.SetLayout(layout);
188 iClient.CreateFields(new DataField[]
190 new DataField(0, textBoxTop.Text, Alignment),
191 new DataField(1, textBoxBottom.Text, Alignment)
196 private void buttonLayoutUpdate_Click(object sender, EventArgs e)
198 //Define a 2 by 2 layout
199 TableLayout layout = new TableLayout(2,2);
200 //Second column only takes up 25%
201 layout.Columns[1].Width = 25F;
202 //Send layout to server
203 iClient.SetLayout(layout);
206 private void buttonSetBitmap_Click(object sender, EventArgs e)
213 Bitmap bitmap = new Bitmap(x2,y2);
214 Pen blackPen = new Pen(Color.Black, 3);
216 // Draw line to screen.
217 using (var graphics = Graphics.FromImage(bitmap))
219 graphics.DrawLine(blackPen, x1, y1, x2, y2);
220 graphics.DrawLine(blackPen, x1, y2, x2, y1);
223 DataField field = new DataField(0, bitmap);
224 //field.ColumnSpan = 2;
225 iClient.SetField(field);
228 private void buttonBitmapLayout_Click(object sender, EventArgs e)
230 SetLayoutWithBitmap();
234 /// Define a layout with a bitmap field on the left and two lines of text on the right.
236 private void SetLayoutWithBitmap()
238 //Define a 2 by 2 layout
239 TableLayout layout = new TableLayout(2, 2);
240 //First column only takes 25%
241 layout.Columns[0].Width = 25F;
242 //Second column takes up 75%
243 layout.Columns[1].Width = 75F;
244 //Send layout to server
245 iClient.SetLayout(layout);
247 //Set a bitmap for our first field
253 Bitmap bitmap = new Bitmap(x2, y2);
254 Pen blackPen = new Pen(Color.Black, 3);
256 // Draw line to screen.
257 using (var graphics = Graphics.FromImage(bitmap))
259 graphics.DrawLine(blackPen, x1, y1, x2, y2);
260 graphics.DrawLine(blackPen, x1, y2, x2, y1);
263 //Create a bitmap field from the bitmap we just created
264 DataField field = new DataField(0, bitmap);
265 //We want our bitmap field to span across two rows
269 iClient.CreateFields(new DataField[]
272 new DataField(1, textBoxTop.Text, Alignment),
273 new DataField(2, textBoxBottom.Text, Alignment)
278 private void buttonIndicatorsLayout_Click(object sender, EventArgs e)
280 //Define a 2 by 4 layout
281 TableLayout layout = new TableLayout(2, 4);
283 layout.Columns[0].Width = 87.5F;
285 layout.Columns[1].Width = 12.5F;
286 //Send layout to server
287 iClient.SetLayout(layout);
289 //Create a bitmap for our indicators field
295 Bitmap bitmap = new Bitmap(x2, y2);
296 Pen blackPen = new Pen(Color.Black, 3);
298 // Draw line to screen.
299 using (var graphics = Graphics.FromImage(bitmap))
301 graphics.DrawLine(blackPen, x1, y1, x2, y2);
302 graphics.DrawLine(blackPen, x1, y2, x2, y1);
305 //Create a bitmap field from the bitmap we just created
306 DataField indicator1 = new DataField(2, bitmap);
307 //Create a bitmap field from the bitmap we just created
308 DataField indicator2 = new DataField(3, bitmap);
309 //Create a bitmap field from the bitmap we just created
310 DataField indicator3 = new DataField(4, bitmap);
311 //Create a bitmap field from the bitmap we just created
312 DataField indicator4 = new DataField(5, bitmap);
315 DataField textFieldTop = new DataField(0, textBoxTop.Text, Alignment);
316 textFieldTop.RowSpan = 2;
318 DataField textFieldBottom = new DataField(1, textBoxBottom.Text, Alignment);
319 textFieldBottom.RowSpan = 2;
323 iClient.CreateFields(new DataField[]
335 private void buttonUpdateTexts_Click(object sender, EventArgs e)
338 bool res = iClient.SetFields(new DataField[]
340 new DataField(0, textBoxTop.Text, Alignment),
341 new DataField(1, textBoxBottom.Text, Alignment)
346 MessageBox.Show("Create you fields first", "Field update error", MessageBoxButtons.OK, MessageBoxIcon.Error);
351 private void buttonLayoutOneTextField_Click(object sender, EventArgs e)
353 //Set one column two lines layout
354 TableLayout layout = new TableLayout(1, 1);
355 iClient.SetLayout(layout);
358 iClient.CreateFields(new DataField[]
360 new DataField(0, textBoxTop.Text, Alignment)