-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrmBuilder.vb
More file actions
1530 lines (1354 loc) · 78.2 KB
/
frmBuilder.vb
File metadata and controls
1530 lines (1354 loc) · 78.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Imports System.Windows.Forms
Imports System.IO
Imports System.Web.Script.Serialization
Imports System.Text.RegularExpressions
Imports GaDotNet.Common
Imports GaDotNet.Common.Data
Imports GaDotNet.Common.Helpers
Public Class frmBuilder
Implements CommandFusion.CFPlugin
Public Event AddCommand(sender As CommandFusion.CFPlugin, newCommand As CommandFusion.SystemCommand) Implements CommandFusion.CFPlugin.AddCommand
Public Event AddFeedback(sender As CommandFusion.CFPlugin, newFB As CommandFusion.SystemFeedback) Implements CommandFusion.CFPlugin.AddFeedback
Public Event AddMacro(sender As CommandFusion.CFPlugin, newMacro As CommandFusion.SystemMacro) Implements CommandFusion.CFPlugin.AddMacro
Public Event AddMacros(sender As CommandFusion.CFPlugin, newMacros As List(Of CommandFusion.SystemMacro)) Implements CommandFusion.CFPlugin.AddMacros
Public Event AddScript(sender As CommandFusion.CFPlugin, ScriptRelativePathToProject As String) Implements CommandFusion.CFPlugin.AddScript
Public Event AddSystem(sender As CommandFusion.CFPlugin, newSystem As CommandFusion.JSONSystem) Implements CommandFusion.CFPlugin.AddSystem
Public Event AppendSystem(sender As CommandFusion.CFPlugin, newSystem As CommandFusion.JSONSystem) Implements CommandFusion.CFPlugin.AppendSystem
Public Event EditMacro(sender As CommandFusion.CFPlugin, existingMacro As String, newMacro As CommandFusion.SystemMacro) Implements CommandFusion.CFPlugin.EditMacro
Public Event RequestMacroList(sender As CommandFusion.CFPlugin) Implements CommandFusion.CFPlugin.RequestMacroList
Public Event RequestProjectFileInfo(sender As CommandFusion.CFPlugin) Implements CommandFusion.CFPlugin.RequestProjectFileInfo
Public Event RequestSystemList(sender As CommandFusion.CFPlugin) Implements CommandFusion.CFPlugin.RequestSystemList
Public Event ToggleWindow(sender As CommandFusion.CFPlugin) Implements CommandFusion.CFPlugin.ToggleWindow
Public Event WriteToLog(sender As CommandFusion.CFPlugin, msg As String) Implements CommandFusion.CFPlugin.WriteToLog
Private pathDiscovery As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & Path.DirectorySeparatorChar & "CommandFusion" & Path.DirectorySeparatorChar & "SystemCommander" & Path.DirectorySeparatorChar & "discovery" & Path.DirectorySeparatorChar
Private discoveredDevices As Dictionary(Of String, Object)
Private availableActions As Dictionary(Of String, List(Of Object))
Private ListOfSystems As List(Of CommandFusion.JSONSystem)
Private ListOfSystemTypes As List(Of CommandFusion.JSONSystem)
Private Const NewSystem As String = "Create New System..."
Private Const OnboardSerialPort As String = "On-board"
Private Const CCF As String = "Raw CCF Hex Code"
Private Const GADomain As String = "commandfusion.com"
Private Const GAEventCategory As String = "CFLink Command Builder"
Private Const GACode As String = "UA-1634994-6"
Dim statsMenu As New MenuItem("Send Anonymous Stats")
Private SelectedAction As String = "Ethernet"
Private SelectedDevice As Dictionary(Of String, Object)
Private SelectedModule As Dictionary(Of String, Object)
Private LastSystemName As String = NewSystem
#Region "Plugin Implementation"
Public ReadOnly Property Author As String Implements CommandFusion.CFPlugin.Author
Get
Return "CommandFusion"
End Get
End Property
Public ReadOnly Property Form As Windows.Forms.Form Implements CommandFusion.CFPlugin.Form
Get
Return Me
End Get
End Property
Public Sub DisposePlugin() Implements CommandFusion.CFPlugin.DisposePlugin
End Sub
Public Sub GetProjectFileInfo(ProjectFile As IO.FileInfo) Implements CommandFusion.CFPlugin.GetProjectFileInfo
End Sub
Public Sub Init(menu As Windows.Forms.MainMenu) Implements CommandFusion.CFPlugin.Init
Dim pluginMenu As New MenuItem(Me.Name1)
Dim showHideMenu As New MenuItem("Toggle Window")
statsMenu.Checked = My.Settings.sendStats
AddHandler showHideMenu.Click, AddressOf Me.DoToggleWindow
AddHandler statsMenu.Click, AddressOf Me.DoToggleStats
pluginMenu.MenuItems.Add(showHideMenu)
pluginMenu.MenuItems.Add(statsMenu)
menu.MenuItems.Add(pluginMenu)
' Hide the tab buttons, because we only ever show one tab at a time for a dynamic interface
tabMain.Appearance = TabAppearance.Buttons
tabMain.SizeMode = TabSizeMode.Fixed
tabMain.ItemSize = New Drawing.Size(0, 1)
HideAllTabs()
tabMain.TabPages.Add(tabHelp)
LoadOnboardDatabase()
End Sub
Public Sub DoToggleWindow(ByVal sender As Object, ByVal e As System.EventArgs)
RaiseEvent ToggleWindow(Me)
End Sub
Public Sub DoToggleStats(ByVal sender As Object, ByVal e As System.EventArgs)
If My.Settings.sendStats Then
If MsgBox("Anonymous usage statistics are used to improve our products and no personally identifiable data is tracked." & Environment.NewLine & "Are you sure you want to opt out of sending anonymous usage statistics?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
My.Settings.sendStats = False
statsMenu.Checked = False
End If
Else
MsgBox("Thank you for enabling anonymous usage statistics. We use this data to improve our products and it does not contain any personally identifiable data.")
My.Settings.sendStats = True
statsMenu.Checked = True
End If
End Sub
Public ReadOnly Property Name1 As String Implements CommandFusion.CFPlugin.Name
Get
Return "CFLink Command Builder"
End Get
End Property
Public Sub ProjectSelected(selected As Boolean) Implements CommandFusion.CFPlugin.ProjectSelected
EnableCommandObjects(selected)
RaiseEvent RequestSystemList(Me)
End Sub
Public Sub UpdateMacroList(systemList As List(Of CommandFusion.SystemMacro)) Implements CommandFusion.CFPlugin.UpdateMacroList
End Sub
Public Sub UpdateSystemList(systemList As List(Of CommandFusion.JSONSystem), systemTypes As List(Of CommandFusion.JSONSystem)) Implements CommandFusion.CFPlugin.UpdateSystemList
ListOfSystems = systemList
ListOfSystemTypes = systemTypes
cboSystems.Items.Clear()
cboSystems.Items.Add(NewSystem)
cboSystems.SelectedIndex = 0
If systemList IsNot Nothing Then
For Each aSystem As CommandFusion.JSONSystem In systemList
cboSystems.Items.Add(aSystem.ToString)
If LastSystemName = aSystem.Name Then
cboSystems.SelectedIndex = cboSystems.Items.Count - 1
End If
Next
End If
End Sub
#End Region
Public Function GetSystemByID(ByVal ID As String) As CommandFusion.JSONSystem
Return ListOfSystemTypes.Find(Function(s) s.ID = ID)
End Function
Private Function GetSystem(ByVal name As String) As CommandFusion.JSONSystem
If ListOfSystems Is Nothing Then
Return Nothing
End If
For Each aSystem As CommandFusion.JSONSystem In ListOfSystems
If aSystem.ToString = name Then
Return aSystem
End If
Next
Return Nothing
End Function
Private Function GetDeviceBySerial(ByVal serial As String) As Dictionary(Of String, Object)
If discoveredDevices Is Nothing OrElse Not discoveredDevices.ContainsKey("DeviceList") Then
Return Nothing
End If
For Each aDevice As Dictionary(Of String, Object) In discoveredDevices("DeviceList")
If aDevice.ContainsKey("SerialNo") AndAlso aDevice("SerialNo") = serial Then
Return aDevice
End If
Next
Return Nothing
End Function
Private Sub AddDeviceToAction(ByVal action As String, ByVal device As Dictionary(Of String, Object))
' Only add the device to the action if the device is not already associated with the action
If Not availableActions(action).Contains(device) Then
availableActions(action).Add(device)
End If
End Sub
Private Sub toolStrip_Resize(sender As Object, e As EventArgs) Handles toolStrip.Resize
cboFiles.Width = btnBrowse.Bounds.Left - lblSelectExport.Bounds.Right - 10
End Sub
Private Sub btnBrowse_Click(sender As Object, e As EventArgs) Handles btnBrowse.Click
dlgOpenFile.InitialDirectory = pathDiscovery
If dlgOpenFile.ShowDialog = Windows.Forms.DialogResult.OK Then
cboFiles.Text = dlgOpenFile.FileName
OpenFile(dlgOpenFile.FileName)
End If
End Sub
Private Sub cboFile_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboFiles.SelectedIndexChanged
OpenFile(cboFiles.SelectedItem)
End Sub
Public Sub LogEvent(ByVal eventAction As String, ByVal eventLabel As String)
If My.Settings.sendStats Then
Dim googleEvent As New GoogleEvent(GADomain, GAEventCategory, eventAction, eventLabel)
Dim request As TrackingRequest
request = New RequestFactory(GACode).BuildRequest(googleEvent)
GoogleTracking.FireTrackingEvent(request)
End If
End Sub
Public Sub OpenFile(ByVal theFile As String)
If Not File.Exists(theFile) Then
If File.Exists(pathDiscovery & theFile) Then
theFile = pathDiscovery & theFile
Else
Exit Sub
End If
End If
lblFile.Text = New FileInfo(theFile).Name
' Log event
LogEvent("Loaded Export File", lblFile.Text)
'lblFilenameInfo.Visible = True
Dim contents As String = File.ReadAllText(theFile)
Dim json As New JavaScriptSerializer()
Try
discoveredDevices = json.DeserializeObject(contents)
If Not discoveredDevices.ContainsKey("DeviceList") Then
MsgBox("The device discovery export file is missing required data. Please try exporting from System Commander again.")
Exit Sub
End If
Catch ex As Exception
MsgBox("The device discovery export file is invalid or corrupt. Please try exporting from System Commander again.")
Exit Sub
End Try
' Setup containers for devices and actions
Dim deviceCount As Integer = discoveredDevices("DeviceList").Length
availableActions = New Dictionary(Of String, List(Of Object))
availableActions("Ethernet") = New List(Of Object)
availableActions("Serial") = New List(Of Object)
availableActions("IR") = New List(Of Object)
availableActions("Relay") = New List(Of Object)
availableActions("IO Port") = New List(Of Object)
availableActions("LED") = New List(Of Object)
availableActions("LED Backlight") = New List(Of Object)
For Each aDevice As Dictionary(Of String, Object) In discoveredDevices("DeviceList")
Select Case aDevice("Model")
Case "LANBridge"
AddDeviceToAction("Ethernet", aDevice)
If aDevice.ContainsKey("COMMode") AndAlso aDevice("COMMode") = "232" Then
AddDeviceToAction("Serial", aDevice)
End If
Case "DIN-MOD4", "MOD4"
If aDevice.ContainsKey("COMMode") AndAlso aDevice("COMMode") = "232" Then
AddDeviceToAction("Serial", aDevice)
End If
If aDevice.ContainsKey("Modules") Then
' Loop through the modules
For Each aModule As Dictionary(Of String, Object) In aDevice("Modules")
Select Case aModule("Model")
Case "MOD-IO8"
AddDeviceToAction("IO Port", aDevice)
Case "MOD-IR8"
AddDeviceToAction("IR", aDevice)
Case "MOD-COM4"
AddDeviceToAction("Serial", aDevice)
Case "MOD-LRY8", "MOD-HRY2", "MOD-RY4", "MOD-SSRY4"
AddDeviceToAction("Relay", aDevice)
End Select
Next
End If
Case "CFMini"
If aDevice.ContainsKey("COMMode") AndAlso aDevice("COMMode") = "232" Then
AddDeviceToAction("Serial", aDevice)
End If
AddDeviceToAction("IO Port", aDevice)
AddDeviceToAction("IR", aDevice)
AddDeviceToAction("Relay", aDevice)
Case "IRBlaster"
AddDeviceToAction("IR", aDevice)
Case "SW16"
AddDeviceToAction("LED", aDevice)
AddDeviceToAction("LED Backlight", aDevice)
Case Else
MsgBox("Unknown Model: " & aDevice("Model"))
End Select
Next
UpdateTree()
End Sub
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If Not Directory.Exists(pathDiscovery) Then
Exit Sub
End If
For Each aFile As String In Directory.GetFiles(pathDiscovery, "*.json")
cboFiles.Items.Add(New FileInfo(aFile).Name)
Next
End Sub
Private Sub UpdateTree()
treeDevices.Nodes.Clear()
For Each anAction As String In availableActions.Keys
Dim actionNode As New TreeNode(anAction)
Select Case anAction
Case "Ethernet"
actionNode.ImageIndex = 1
actionNode.SelectedImageIndex = 1
Case "Serial"
actionNode.ImageIndex = 2
actionNode.SelectedImageIndex = 2
Case "IR"
actionNode.ImageIndex = 3
actionNode.SelectedImageIndex = 3
Case "Relay"
actionNode.ImageIndex = 4
actionNode.SelectedImageIndex = 4
Case "IO Port"
actionNode.ImageIndex = 5
actionNode.SelectedImageIndex = 5
Case "LED", "LED Backlight"
actionNode.ImageIndex = 6
actionNode.SelectedImageIndex = 6
Case Else
actionNode.ImageIndex = -1
actionNode.SelectedImageIndex = -1
End Select
For Each aDevice As Dictionary(Of String, Object) In availableActions(anAction)
Dim deviceNode As New TreeNode("[" & Integer2HexString(aDevice("CFLinkID")) & "] " & aDevice("Model") & ", " & aDevice("SerialNo"))
deviceNode.Tag = aDevice
deviceNode.ImageIndex = -1
deviceNode.SelectedImageIndex = -1
deviceNode.NodeFont = New System.Drawing.Font(Me.Font, Drawing.FontStyle.Regular)
actionNode.Nodes.Add(deviceNode)
If aDevice.ContainsKey("Modules") Then
For Each aModule As Dictionary(Of String, Object) In aDevice("Modules")
If anAction.StartsWith(aModule("ModuleType")) Then
Dim moduleNode As New TreeNode(aModule("Model"))
moduleNode.Tag = aModule
moduleNode.ToolTipText = "Module Slot " & aModule("ModuleNumber")
moduleNode.ImageIndex = 6 + aModule("ModuleNumber")
moduleNode.SelectedImageIndex = 6 + aModule("ModuleNumber")
moduleNode.NodeFont = New System.Drawing.Font(Me.Font, Drawing.FontStyle.Regular)
deviceNode.Nodes.Add(moduleNode)
End If
Next
End If
' Force modular controller nodes to expand to show their modules
deviceNode.Expand()
Next
If actionNode.Nodes.Count > 0 Then
treeDevices.Nodes.Add(actionNode)
End If
Next
HideAllTabs()
tabMain.TabPages.Add(tabHelp)
End Sub
Public Sub HideAllTabs()
tabMain.TabPages.Clear()
End Sub
Private Sub treeDevices_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles treeDevices.AfterSelect
If e.Node.Level = 0 Then
SelectedAction = e.Node.Text
Exit Sub
ElseIf e.Node.Level = 1 Then
SelectedAction = e.Node.Parent.Text
InitPanels(e.Node.Tag)
ElseIf e.Node.Level = 2 Then
SelectedAction = e.Node.Parent.Parent.Text
InitPanels(e.Node.Parent.Tag, e.Node.Tag)
End If
treeDevices.Focus()
End Sub
'Private Sub treeDevices_NodeMouseClick(sender As Object, e As TreeNodeMouseClickEventArgs) Handles treeDevices.NodeMouseClick
' If e.Node.Level = 1 Then
' 'SelectedAction = e.Node.Parent.Text
' If e.Node.Nodes.Count > 0 Then
' ' Selected a modular controller node, so select the first node instead
' e.Node.Expand()
' treeDevices.SelectedNode = e.Node.Nodes(0)
' treeDevices.Focus()
' 'InitPanels(e.Node.Tag, e.Node.Nodes(0).Tag)
' End If
' End If
'End Sub
Public Sub InitPanels(ByVal aDevice As Dictionary(Of String, Object), Optional ByVal aModule As Dictionary(Of String, Object) = Nothing)
HideAllTabs()
SelectedDevice = aDevice
SelectedModule = aModule
If aModule Is Nothing Then
If aDevice.ContainsKey("Model") Then
Select Case aDevice("Model")
Case "CFMini"
Select Case SelectedAction
Case "Relay"
tabMain.TabPages.Add(tabRelays)
' 4 relay ports on-board
While dgvPortsRelay.RowCount > 4
dgvPortsRelay.Rows.RemoveAt(dgvPortsRelay.RowCount - 1)
End While
While dgvPortsRelay.RowCount < 4
dgvPortsRelay.Rows.Add(False, PadZero(dgvPortsRelay.RowCount + 1), "OPEN", 0.1)
End While
Case "IO Port"
dgvPortsIO.Rows.Clear()
' Check to see what IO ports are configured as OUTPUTS on this device
For Each aPort As Dictionary(Of String, Object) In aDevice("IOPorts")
If aPort("Mode") > 0 Then
dgvPortsIO.Rows.Add(False, PadZero(aPort("Number")), "OPEN", 0.1)
End If
Next
If dgvPortsIO.RowCount > 0 Then
tabMain.TabPages.Add(tabIO)
Else
lblErrorMsg.Text = "This device does not have any IO ports configured in Output modes. Only output commands can be generated."
tabMain.TabPages.Add(tabError)
End If
Case "Serial"
tabMain.TabPages.Add(tabSerial)
' 1 on-board RS232 port
While dgvPortsSerial.RowCount > 1
dgvPortsSerial.Rows.RemoveAt(dgvPortsSerial.RowCount - 1)
End While
While dgvPortsSerial.RowCount < 1
dgvPortsSerial.Rows.Add(OnboardSerialPort, "")
End While
dgvPortsSerial.Rows(0).Cells(0).Value = OnboardSerialPort
Case "IR"
tabMain.TabPages.Add(tabIR)
' 8 IR ports on board
While dgvPortsIR.RowCount > 8
dgvPortsIR.Rows.RemoveAt(dgvPortsIR.RowCount - 1)
End While
While dgvPortsIR.RowCount < 8
dgvPortsIR.Rows.Add(PadZero(dgvPortsIR.RowCount + 1), CCF)
End While
cboIRPort.Items.Clear()
For i As Integer = 1 To 8
cboIRPort.Items.Add(PadZero(i))
dgvPortsIR.Rows(i - 1).Cells(0).Value = PadZero(i)
Next
cboIRPort.SelectedIndex = 0
End Select
Case "IRBlaster"
Select Case SelectedAction
Case "IR"
tabMain.TabPages.Add(tabIR)
' 2 IR ports on board
While dgvPortsIR.RowCount > 2
dgvPortsIR.Rows.RemoveAt(dgvPortsIR.RowCount - 1)
End While
While dgvPortsIR.RowCount < 2
dgvPortsIR.Rows.Add(PadZero(dgvPortsIR.RowCount + 1), CCF)
End While
dgvPortsIR.Rows(0).Cells(0).Value = "Blaster"
dgvPortsIR.Rows(1).Cells(0).Value = "Emitter"
cboIRPort.Items.Clear()
cboIRPort.Items.AddRange({"Blaster", "Emitter"})
cboIRPort.SelectedIndex = 0
End Select
Case "LANBridge"
Select Case SelectedAction
Case "Serial"
tabMain.TabPages.Add(tabSerial)
' 1 on-board RS232 port
While dgvPortsSerial.RowCount > 1
dgvPortsSerial.Rows.RemoveAt(dgvPortsSerial.RowCount - 1)
End While
While dgvPortsSerial.RowCount < 1
dgvPortsSerial.Rows.Add(OnboardSerialPort, "")
End While
dgvPortsSerial.Rows(0).Cells(0).Value = OnboardSerialPort
Case "Ethernet"
If aDevice.ContainsKey("Slots") Then
tabMain.TabPages.Add(tabEthernet)
' add all communication slots, even disabled ones
While dgvPortsEthernet.RowCount > aDevice("Slots").Length
dgvPortsEthernet.Rows.RemoveAt(dgvPortsEthernet.RowCount - 1)
End While
While dgvPortsEthernet.RowCount < aDevice("Slots").Length
dgvPortsEthernet.Rows.Add("00", "Updating...")
End While
' update each slot details and data field states
Dim i As Integer = 0
For Each aSlot As Dictionary(Of String, Object) In aDevice("Slots")
dgvPortsEthernet.Rows(i).Cells(0).Value = aSlot("Number")
If aSlot("ConnType") = "OFF" Then
dgvPortsEthernet.Rows(i).Cells(1).Value = aSlot("ConnType")
dgvPortsEthernet.Rows(i).Cells(2).ReadOnly = True
dgvPortsEthernet.Rows(i).Cells(2).Style.ForeColor = Drawing.Color.Gray
dgvPortsEthernet.Rows(i).Cells(2).Style.BackColor = Drawing.Color.LightGray
dgvPortsEthernet.Rows(i).Cells(2).Style.SelectionForeColor = Drawing.Color.Gray
dgvPortsEthernet.Rows(i).Cells(2).Style.SelectionBackColor = Drawing.Color.LightGray
Else
dgvPortsEthernet.Rows(i).Cells(1).Value = aSlot("ConnType") & " " & aSlot("ConnMode") & ", " & aSlot("IP") & ":" & aSlot("Port")
dgvPortsEthernet.Rows(i).Cells(2).ReadOnly = False
dgvPortsEthernet.Rows(i).Cells(2).Style.ForeColor = Drawing.SystemColors.ControlText
dgvPortsEthernet.Rows(i).Cells(2).Style.BackColor = Drawing.SystemColors.Window
dgvPortsEthernet.Rows(i).Cells(2).Style.SelectionForeColor = Drawing.SystemColors.HighlightText
dgvPortsEthernet.Rows(i).Cells(2).Style.SelectionBackColor = Drawing.SystemColors.Highlight
End If
i += 1
Next
Else
tabMain.TabPages.Add(tabError)
lblErrorMsg.Text = "An invalid Ethernet device was selected (missing Ethernet slot configurations)."
End If
End Select
Case "DIN-MOD4", "MOD4"
Select Case SelectedAction
Case "Serial"
tabMain.TabPages.Add(tabSerial)
' 1 on-board RS232 port
While dgvPortsSerial.RowCount > 1
dgvPortsSerial.Rows.RemoveAt(dgvPortsSerial.RowCount - 1)
End While
While dgvPortsSerial.RowCount < 1
dgvPortsSerial.Rows.Add(OnboardSerialPort, "")
End While
dgvPortsSerial.Rows(0).Cells(0).Value = OnboardSerialPort
End Select
Case "SW16"
tabMain.TabPages.Add(tabLED)
Select Case SelectedAction
Case "LED Backlight"
'Me.Text = "Build Backlight LED Command"
' Add the backlight LED ports
While dgvPortsLED.RowCount > 4
dgvPortsLED.Rows.RemoveAt(dgvPortsLED.RowCount - 1)
End While
While dgvPortsLED.RowCount < 4
dgvPortsLED.Rows.Add(False, PadZero(dgvPortsLED.RowCount + 1), "OFF", 1.0, 0, 100, 1.0, 1.0, 0)
End While
Case Else
'Me.Text = "Build LED Command"
' Add the LED ports
While dgvPortsLED.RowCount > 16
dgvPortsLED.Rows.RemoveAt(dgvPortsLED.RowCount - 1)
End While
While dgvPortsLED.RowCount < 16
dgvPortsLED.Rows.Add(False, PadZero(dgvPortsLED.RowCount + 1), "OFF", 1.0, 0, 100, 1.0, 1.0, 0)
End While
End Select
End Select
End If
Else
Select Case SelectedAction
Case "Relay"
tabMain.TabPages.Add(tabRelays)
' Show the correct number of relay ports based on the module properties
While dgvPortsRelay.RowCount > aModule("NumPorts")
dgvPortsRelay.Rows.RemoveAt(dgvPortsRelay.RowCount - 1)
End While
While dgvPortsRelay.RowCount < aModule("NumPorts")
dgvPortsRelay.Rows.Add(False, PadZero(dgvPortsRelay.RowCount + 1), "OPEN", 0.1)
End While
Case "IO Port"
dgvPortsIO.Rows.Clear()
' Check to see what IO ports are configured as OUTPUTS on this device
For Each aPort As Dictionary(Of String, Object) In aModule("Ports")
If aPort("Mode") > 0 Then
dgvPortsIO.Rows.Add(False, PadZero(aPort("Number")), "OPEN", 0.1)
End If
Next
If dgvPortsIO.RowCount > 0 Then
tabMain.TabPages.Add(tabIO)
Else
lblErrorMsg.Text = "This module does not have any IO ports configured in Output modes. Only output commands can be generated."
tabMain.TabPages.Add(tabError)
End If
Case "Serial"
dgvPortsSerial.Rows.Clear()
' Check to see what Serial ports are configured
For Each aPort As Dictionary(Of String, Object) In aModule("Ports")
If aPort("Mode") > 0 Then
dgvPortsSerial.Rows.Add(PadZero(aPort("Number")), "")
End If
Next
If dgvPortsSerial.RowCount > 0 Then
tabMain.TabPages.Add(tabSerial)
Else
lblErrorMsg.Text = "This module does not have any serial ports configured in Output modes. Serial ports configured as 'OFF' will be ignored."
tabMain.TabPages.Add(tabError)
End If
Case "IR"
tabMain.TabPages.Add(tabIR)
' Show the correct number of IR ports based on the module properties
While dgvPortsIR.RowCount > aModule("NumPorts")
dgvPortsIR.Rows.RemoveAt(dgvPortsIR.RowCount - 1)
End While
While dgvPortsIR.RowCount < aModule("NumPorts")
dgvPortsIR.Rows.Add(PadZero(dgvPortsIR.RowCount + 1), CCF)
End While
cboIRPort.Items.Clear()
For i As Integer = 1 To aModule("NumPorts")
cboIRPort.Items.Add(PadZero(i))
dgvPortsIR.Rows(i - 1).Cells(0).Value = PadZero(i)
Next
cboIRPort.SelectedIndex = 0
End Select
End If
End Sub
#Region "ETHERNET"
Private Sub btnGenerateEthernet_Click(sender As Object, e As EventArgs) Handles btnGenerateEthernet.Click
' Loop through ethernet slots
Dim dataString As String = ""
Dim commandName As String = ""
Dim found As Boolean = False
For i As Integer = 0 To dgvPortsEthernet.Rows.Count - 1
If dgvPortsEthernet.Rows(i).Cells(1).Value <> "OFF" AndAlso dgvPortsEthernet.Rows(i).Cells(2).Value <> "" Then
If found Then
MsgBox("Only one ethernet slot command can be built at a time. The command has been generated for the first slot in the list only." & Environment.NewLine & _
"If you want to create commands for additional slots, please define them individually before adding to your project.")
Exit For
Else
' slot has data to send, so add it to the command string
commandName &= "-SLOT" & dgvPortsEthernet.Rows(i).Cells(0).Value
dataString &= PadZero(dgvPortsEthernet.Rows(i).Cells(0).Value) & ":" & dgvPortsEthernet.Rows(i).Cells(2).Value
found = True
End If
End If
Next
' Check that at least one slot was used to send data
If dataString = "" Then
MsgBox("You must enter data for at least one ethernet slot to generate the CFLink command.")
Exit Sub
End If
txtCommandValue.Text = BuildCFLinkCommandRAW(SelectedDevice("CFLinkID"), "TLANSND", dataString)
txtCommandName.Text = SelectedDevice("Model") & "-" & Integer2HexString(SelectedDevice("CFLinkID")) & "_ETH" & commandName
' Log event
LogEvent("Generated Command", "Ethernet")
End Sub
#End Region
#Region "LED"
Private Sub dgvPortsLED_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles dgvPortsLED.CellValueChanged
If dgvPortsLED.CurrentCell IsNot Nothing Then
If dgvPortsLED.CurrentCell.ColumnIndex = 2 Then
' Dropdown list change
If e IsNot Nothing Then
dgvPortsLED.SuspendLayout()
End If
Select Case dgvPortsLED.CurrentCell.Value.ToString
Case "OFF", "ON", "TOGGLE"
For i As Integer = 3 To 8
dgvPortsLED.CurrentRow.Cells(i).ReadOnly = True
dgvPortsLED.CurrentRow.Cells(i).Style.ForeColor = Drawing.Color.Gray
dgvPortsLED.CurrentRow.Cells(i).Style.BackColor = Drawing.Color.LightGray
dgvPortsLED.CurrentRow.Cells(i).Style.SelectionForeColor = Drawing.Color.Gray
dgvPortsLED.CurrentRow.Cells(i).Style.SelectionBackColor = Drawing.Color.LightGray
Next
Case "PULSE"
dgvPortsLED.CurrentRow.Cells(3).ReadOnly = False
dgvPortsLED.CurrentRow.Cells(3).Style.ForeColor = Drawing.SystemColors.ControlText
dgvPortsLED.CurrentRow.Cells(3).Style.BackColor = Drawing.SystemColors.Window
dgvPortsLED.CurrentRow.Cells(3).Style.SelectionForeColor = Drawing.SystemColors.HighlightText
dgvPortsLED.CurrentRow.Cells(3).Style.SelectionBackColor = Drawing.SystemColors.Highlight
For i As Integer = 4 To 8
dgvPortsLED.CurrentRow.Cells(i).ReadOnly = True
dgvPortsLED.CurrentRow.Cells(i).Style.ForeColor = Drawing.Color.Gray
dgvPortsLED.CurrentRow.Cells(i).Style.BackColor = Drawing.Color.LightGray
dgvPortsLED.CurrentRow.Cells(i).Style.SelectionForeColor = Drawing.Color.Gray
dgvPortsLED.CurrentRow.Cells(i).Style.SelectionBackColor = Drawing.Color.LightGray
Next
Case "BLINK", "DIM"
dgvPortsLED.CurrentRow.Cells(3).ReadOnly = True
dgvPortsLED.CurrentRow.Cells(3).Style.ForeColor = Drawing.Color.Gray
dgvPortsLED.CurrentRow.Cells(3).Style.BackColor = Drawing.Color.LightGray
dgvPortsLED.CurrentRow.Cells(3).Style.SelectionForeColor = Drawing.Color.Gray
dgvPortsLED.CurrentRow.Cells(3).Style.SelectionBackColor = Drawing.Color.LightGray
For i As Integer = 4 To 8
dgvPortsLED.CurrentRow.Cells(i).ReadOnly = False
dgvPortsLED.CurrentRow.Cells(i).Style.ForeColor = Drawing.SystemColors.ControlText
dgvPortsLED.CurrentRow.Cells(i).Style.BackColor = Drawing.SystemColors.Window
dgvPortsLED.CurrentRow.Cells(i).Style.SelectionForeColor = Drawing.SystemColors.HighlightText
dgvPortsLED.CurrentRow.Cells(i).Style.SelectionBackColor = Drawing.SystemColors.Highlight
Next
Case "RAMP"
For i As Integer = 3 To 4
dgvPortsLED.CurrentRow.Cells(i).ReadOnly = False
dgvPortsLED.CurrentRow.Cells(i).Style.ForeColor = Drawing.SystemColors.ControlText
dgvPortsLED.CurrentRow.Cells(i).Style.BackColor = Drawing.SystemColors.Window
dgvPortsLED.CurrentRow.Cells(i).Style.SelectionForeColor = Drawing.SystemColors.HighlightText
dgvPortsLED.CurrentRow.Cells(i).Style.SelectionBackColor = Drawing.SystemColors.Highlight
Next
For i As Integer = 5 To 8
dgvPortsLED.CurrentRow.Cells(i).ReadOnly = True
dgvPortsLED.CurrentRow.Cells(i).Style.ForeColor = Drawing.Color.Gray
dgvPortsLED.CurrentRow.Cells(i).Style.BackColor = Drawing.Color.LightGray
dgvPortsLED.CurrentRow.Cells(i).Style.SelectionForeColor = Drawing.Color.Gray
dgvPortsLED.CurrentRow.Cells(i).Style.SelectionBackColor = Drawing.Color.LightGray
Next
End Select
If e IsNot Nothing Then
dgvPortsLED.ResumeLayout()
dgvPortsLED.Refresh()
End If
End If
End If
End Sub
Private Sub dgvPortsLED_CurrentCellDirtyStateChanged(sender As Object, e As EventArgs) Handles dgvPortsLED.CurrentCellDirtyStateChanged
dgvPortsLED.CommitEdit(DataGridViewDataErrorContexts.CurrentCellChange)
End Sub
Private Sub dgvPortsLED_EditingControlShowing(ByVal sender As Object, ByVal e As DataGridViewEditingControlShowingEventArgs) Handles dgvPortsLED.EditingControlShowing
If dgvPortsLED.CurrentCell.ColumnIndex > 2 Then
Dim txtEdit As TextBox = e.Control
'remove any existing handler
RemoveHandler txtEdit.KeyPress, AddressOf txtEditLED_Keypress
AddHandler txtEdit.KeyPress, AddressOf txtEditLED_Keypress
End If
End Sub
Private Sub txtEditLED_Keypress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
'Test for numeric value or backspace in first column
If dgvPortsLED.CurrentCell.ColumnIndex = 3 Or dgvPortsLED.CurrentCell.ColumnIndex = 6 Or dgvPortsLED.CurrentCell.ColumnIndex = 7 Then
If IsNumeric(e.KeyChar.ToString()) _
Or e.KeyChar = ChrW(Keys.Back) _
Or e.KeyChar = "." Then
e.Handled = False 'if numeric display
Else
e.Handled = True 'if non numeric don't display
End If
ElseIf dgvPortsLED.CurrentCell.ColumnIndex = 4 Or dgvPortsLED.CurrentCell.ColumnIndex = 5 Or dgvPortsLED.CurrentCell.ColumnIndex = 8 Then
If IsNumeric(e.KeyChar.ToString()) _
Or e.KeyChar = ChrW(Keys.Back) Then
e.Handled = False 'if numeric display
Else
e.Handled = True 'if non numeric don't display
End If
End If
End Sub
Private Sub dgvPortsLED_CellValidating(sender As Object, e As DataGridViewCellValidatingEventArgs) Handles dgvPortsLED.CellValidating
Try
If dgvPortsLED.CurrentCell.ColumnIndex = 6 Or dgvPortsLED.CurrentCell.ColumnIndex = 7 Then
' Pulse time change
If dgvPortsLED.CurrentCell.Value.ToString = "" OrElse dgvPortsLED.CurrentCell.Value.ToString < 0.1 Then
MsgBox("A minimum of 0.1 seconds is required.")
dgvPortsLED.CurrentCell.Value = 0.1
e.Cancel = True
ElseIf dgvPortsLED.CurrentCell.Value.ToString = "" OrElse dgvPortsLED.CurrentCell.Value.ToString > 999.9 Then
MsgBox("A maximum of 999.9 seconds is allowed.")
dgvPortsLED.CurrentCell.Value = 999.9
e.Cancel = True
End If
ElseIf dgvPortsLED.CurrentCell.ColumnIndex = 4 Or dgvPortsLED.CurrentCell.ColumnIndex = 5 Then
' min or max level change
If dgvPortsLED.CurrentCell.Value.ToString = "" OrElse (dgvPortsLED.CurrentCell.Value.ToString < 0 Or dgvPortsLED.CurrentCell.Value.ToString > 100) Then
MsgBox("LED levels must be within the range 0 to 100.")
e.Cancel = True
ElseIf dgvPortsLED.CurrentCell.ColumnIndex = 5 AndAlso dgvPortsLED.CurrentCell.Value.ToString = 0 Then
MsgBox("LED max level must be above 0 (zero).")
e.Cancel = True
ElseIf Integer.Parse(dgvPortsLED.CurrentRow.Cells(5).Value.ToString) < Integer.Parse(dgvPortsLED.CurrentRow.Cells(4).Value.ToString) Then
MsgBox("LED max level must be greater than the LED min value.")
e.Cancel = True
End If
End If
Catch ex As NullReferenceException
End Try
End Sub
Private Sub btnGenerateLED_Click(sender As Object, e As EventArgs) Handles btnGenerateLED.Click
' Loop through selected LED ports
Dim dataString As String = ""
Dim commandName As String = ""
For i As Integer = 0 To dgvPortsLED.Rows.Count - 1
If dgvPortsLED.Rows(i).Cells(0).Value = True Then
' port is selected, so add it to the command string, with its config details
dataString &= "|P" & PadZero(dgvPortsLED.Rows(i).Cells(1).Value) & ":"
Select Case dgvPortsLED.Rows(i).Cells(2).Value.ToString
Case "OFF"
dataString &= "0"
Case "ON"
dataString &= "1"
Case "TOGGLE"
dataString &= "T"
Case "PULSE"
dataString &= "P:" & PadZero(dgvPortsLED.Rows(i).Cells(3).Value.ToString * 10, 4)
Case "BLINK"
dataString &= "B:" & PadZero(dgvPortsLED.Rows(i).Cells(4).Value.ToString, 3) & ":" & PadZero(dgvPortsLED.Rows(i).Cells(5).Value.ToString, 3) & ":" & PadZero(dgvPortsLED.Rows(i).Cells(6).Value.ToString * 10, 4) & ":" & PadZero(dgvPortsLED.Rows(i).Cells(7).Value.ToString * 10, 4) & ":" & PadZero(dgvPortsLED.Rows(i).Cells(8).Value.ToString, 4)
Case "DIM"
dataString &= "D:" & PadZero(dgvPortsLED.Rows(i).Cells(4).Value.ToString, 3) & ":" & PadZero(dgvPortsLED.Rows(i).Cells(5).Value.ToString, 3) & ":" & PadZero(dgvPortsLED.Rows(i).Cells(6).Value.ToString * 10, 4) & ":" & PadZero(dgvPortsLED.Rows(i).Cells(7).Value.ToString * 10, 4) & ":" & PadZero(dgvPortsLED.Rows(i).Cells(8).Value.ToString, 4)
Case "RAMP"
dataString &= "R:" & PadZero(dgvPortsLED.Rows(i).Cells(4).Value.ToString, 3) & ":" & PadZero(dgvPortsLED.Rows(i).Cells(3).Value.ToString * 10, 4)
End Select
commandName &= "_" & dgvPortsLED.Rows(i).Cells(2).Value.ToString & "-P" & PadZero(dgvPortsLED.Rows(i).Cells(1).Value)
End If
Next
' Check that at least one LED port was selected
If dataString = "" Then
MsgBox("You must select at least one LED port to manipulate via it's checkbox.")
Exit Sub
End If
' Remove leading pipe char
dataString = dataString.Substring(1)
txtCommandName.Text = SelectedDevice("Model") & "-" & Integer2HexString(SelectedDevice("CFLinkID")) & "_LED" & commandName
txtCommandValue.Text = BuildCFLinkCommandRAW(SelectedDevice("CFLinkID"), IIf(SelectedAction <> "LED", "TSWXBKL", "TSWXLED"), dataString)
' Log event
LogEvent("Generated Command", "LED")
End Sub
#End Region
#Region "RELAY"
Private Sub dgvPorts_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles dgvPortsRelay.CellValueChanged
Try
If dgvPortsRelay.CurrentCell IsNot Nothing Then
If e.ColumnIndex = 2 Then
' Dropdown list change
If dgvPortsRelay.CurrentCell.Value.ToString = "PULSE" Then
dgvPortsRelay.CurrentRow.Cells(3).ReadOnly = False
dgvPortsRelay.CurrentRow.Cells(3).Style.ForeColor = Drawing.SystemColors.ControlText
dgvPortsRelay.CurrentRow.Cells(3).Style.BackColor = Drawing.SystemColors.Window
dgvPortsRelay.CurrentRow.Cells(3).Style.SelectionForeColor = Drawing.SystemColors.HighlightText
dgvPortsRelay.CurrentRow.Cells(3).Style.SelectionBackColor = Drawing.SystemColors.Highlight
Else
dgvPortsRelay.CurrentRow.Cells(3).ReadOnly = True
dgvPortsRelay.CurrentRow.Cells(3).Style.ForeColor = Drawing.Color.Gray
dgvPortsRelay.CurrentRow.Cells(3).Style.BackColor = Drawing.Color.LightGray
dgvPortsRelay.CurrentRow.Cells(3).Style.SelectionForeColor = Drawing.Color.Gray
dgvPortsRelay.CurrentRow.Cells(3).Style.SelectionBackColor = Drawing.Color.LightGray
End If
End If
End If
Catch ex As NullReferenceException
End Try
End Sub
Private Sub dgvPortsRelay_CurrentCellDirtyStateChanged(sender As Object, e As EventArgs) Handles dgvPortsRelay.CurrentCellDirtyStateChanged
If dgvPortsRelay.CurrentCell.ColumnIndex = 2 Then
dgvPortsRelay.CommitEdit(DataGridViewDataErrorContexts.CurrentCellChange)
End If
End Sub
Private Sub dgvPortsRelay_EditingControlShowing(ByVal sender As Object, ByVal e As DataGridViewEditingControlShowingEventArgs) Handles dgvPortsRelay.EditingControlShowing
If dgvPortsRelay.CurrentCell.ColumnIndex > 2 Then
Dim txtEdit As TextBox = e.Control
'remove any existing handler
RemoveHandler txtEdit.KeyPress, AddressOf txtEditRelay_Keypress
AddHandler txtEdit.KeyPress, AddressOf txtEditRelay_Keypress
End If
End Sub
Private Sub txtEditRelay_Keypress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
'Test for numeric value or backspace in first column
If dgvPortsRelay.CurrentCell.ColumnIndex = 3 Then
If IsNumeric(e.KeyChar.ToString()) _
Or e.KeyChar = ChrW(Keys.Back) _
Or e.KeyChar = "." Then
e.Handled = False 'if numeric display
Else
e.Handled = True 'if non numeric don't display
End If
End If
End Sub
Private Sub dgvPortsRelay_CellValidating(sender As Object, e As DataGridViewCellValidatingEventArgs) Handles dgvPortsRelay.CellValidating
Try
If dgvPortsRelay.CurrentCell.ColumnIndex = 3 Then
' Pulse time change
If dgvPortsRelay.CurrentCell.Value.ToString = "" OrElse dgvPortsRelay.CurrentCell.Value.ToString < 0.1 Then
MsgBox("A minimum of 0.1 seconds is required for relay pulsing.")
dgvPortsRelay.CurrentCell.Value = 0.1
e.Cancel = True
ElseIf dgvPortsRelay.CurrentCell.Value.ToString > 999.9 Then
MsgBox("A maximum of 999.9 seconds is allowed for relay pulsing.")
dgvPortsRelay.CurrentCell.Value = 999.9
e.Cancel = True
End If
End If
Catch ex As NullReferenceException
End Try
End Sub
Private Sub btnGenerateRelay_Click(sender As Object, e As EventArgs) Handles btnGenerateRelay.Click
' Loop through selected relay ports
Dim dataString As String = ""
Dim commandName As String = ""
For i As Integer = 0 To dgvPortsRelay.Rows.Count - 1
If dgvPortsRelay.Rows(i).Cells(0).Value = True Then
' port is selected, so add it to the command string, with its config details
dataString &= "|P" & PadZero(dgvPortsRelay.Rows(i).Cells(1).Value) & ":"
Select Case dgvPortsRelay.Rows(i).Cells(2).Value.ToString
Case "OPEN"
dataString &= "0"
Case "CLOSE"
dataString &= "1"
Case "TOGGLE"
dataString &= "T"
Case "PULSE"
dataString &= "P:" & PadZero(dgvPortsRelay.Rows(i).Cells(3).Value.ToString * 10, 5)
End Select
commandName &= "_" & dgvPortsRelay.Rows(i).Cells(2).Value.ToString & "-P" & PadZero(dgvPortsRelay.Rows(i).Cells(1).Value)
End If
Next
' Check that at least one relay port was selected
If dataString = "" Then
MsgBox("You must select at least one relay port to manipulate via it's checkbox.")
Exit Sub
End If
If SelectedModule Is Nothing Then
dataString = dataString.Substring(1)
Else
Dim moduleString As String = "M" & SelectedModule("ModuleNumber")
dataString = moduleString & dataString
commandName = "_" & moduleString & commandName
End If
txtCommandName.Text = SelectedDevice("Model") & "-" & Integer2HexString(SelectedDevice("CFLinkID")) & "_RELAYS" & commandName
txtCommandValue.Text = BuildCFLinkCommandRAW(SelectedDevice("CFLinkID"), "TRLYSET", dataString)
' Log event
LogEvent("Generated Command", "Relay")
End Sub
#End Region
#Region "SERIAL"
Private Sub btnGenerateSerial_Click(sender As Object, e As EventArgs) Handles btnGenerateSerial.Click
' Loop through selected serial ports
Dim dataString As String = ""
Dim commandName As String = ""
For i As Integer = 0 To dgvPortsSerial.Rows.Count - 1
If dgvPortsSerial.Rows(i).Cells(1).Value <> "" Then
' port has data to send, so add it to the command string
If SelectedDevice("Model").ToString.EndsWith("MOD4") AndAlso dgvPortsSerial.Rows(i).Cells(0).Value <> OnboardSerialPort Then
dataString &= "|P" & PadZero(dgvPortsSerial.Rows(i).Cells(0).Value) & ":"
commandName &= "-P" & PadZero(dgvPortsSerial.Rows(i).Cells(0).Value)
Else
commandName &= "-ONBOARD"
End If
dataString &= dgvPortsSerial.Rows(i).Cells(1).Value
End If
Next
' Check that at least one relay port was selected
If dataString = "" Then
MsgBox("You must enter data for at least one serial port to generate the CFLink command.")
Exit Sub
End If
If SelectedModule Is Nothing Then
txtCommandValue.Text = BuildCFLinkCommandRAW(SelectedDevice("CFLinkID"), "TCFXSPW", dataString)
Else
Dim moduleString As String = "M" & SelectedModule("ModuleNumber")
dataString = moduleString & dataString
commandName = "_" & moduleString & commandName
txtCommandValue.Text = BuildCFLinkCommandRAW(SelectedDevice("CFLinkID"), "TCOMSPW", dataString)
End If
txtCommandName.Text = SelectedDevice("Model") & "-" & Integer2HexString(SelectedDevice("CFLinkID")) & "_SERIAL" & commandName
' Log event
LogEvent("Generated Command", "Serial")
End Sub
#End Region
#Region "IO"
Private Sub dgvPortsIO_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles dgvPortsIO.CellValueChanged
Try
If dgvPortsIO.CurrentCell IsNot Nothing Then
If e.ColumnIndex = 2 Then
' Dropdown list change
If dgvPortsIO.CurrentCell.Value.ToString = "PULSE" Then
dgvPortsIO.CurrentRow.Cells(3).ReadOnly = False
dgvPortsIO.CurrentRow.Cells(3).Style.ForeColor = Drawing.SystemColors.ControlText
dgvPortsIO.CurrentRow.Cells(3).Style.BackColor = Drawing.SystemColors.Window
dgvPortsIO.CurrentRow.Cells(3).Style.SelectionForeColor = Drawing.SystemColors.HighlightText
dgvPortsIO.CurrentRow.Cells(3).Style.SelectionBackColor = Drawing.SystemColors.Highlight
Else
dgvPortsIO.CurrentRow.Cells(3).ReadOnly = True
dgvPortsIO.CurrentRow.Cells(3).Style.ForeColor = Drawing.Color.Gray
dgvPortsIO.CurrentRow.Cells(3).Style.BackColor = Drawing.Color.LightGray
dgvPortsIO.CurrentRow.Cells(3).Style.SelectionForeColor = Drawing.Color.Gray
dgvPortsIO.CurrentRow.Cells(3).Style.SelectionBackColor = Drawing.Color.LightGray