初始化项目
This commit is contained in:
833
BLV_Studio/Test/TestForm1.vb
Normal file
833
BLV_Studio/Test/TestForm1.vb
Normal file
@@ -0,0 +1,833 @@
|
||||
Imports System.Text
|
||||
Imports BLV_Studio.GridModel.DeviceEventModel
|
||||
Imports FlexCell
|
||||
|
||||
Public Class TestForm1
|
||||
|
||||
Enum ComboDropDownON
|
||||
LightingCircuit = 1
|
||||
LightingCircuit0
|
||||
LightingCircuit1
|
||||
LightingCircuit2
|
||||
KeyDev
|
||||
max
|
||||
End Enum
|
||||
Enum ComboDropDownCol
|
||||
devFile = 1
|
||||
Keyval
|
||||
keyName
|
||||
music
|
||||
空改1
|
||||
空改2
|
||||
空改3
|
||||
空改4
|
||||
max
|
||||
End Enum
|
||||
|
||||
Enum CellDrop
|
||||
|
||||
TurnOn = -24116
|
||||
TurnDrown = -23592
|
||||
表示先开后关 = -24080
|
||||
代表先关后开 = -24075
|
||||
'代表调光上 = -23637
|
||||
'代表调光下降 = -23635
|
||||
|
||||
End Enum
|
||||
Public configInfo As ConfigInfoStuct
|
||||
Public basicClass As DeviceObjectClasses
|
||||
Private Sub TestForm1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
||||
|
||||
|
||||
Dim tmpRcuModelFile As String
|
||||
Using dlg As New OpenFileDialog
|
||||
dlg.InitialDirectory = HostDevFNP
|
||||
dlg.Title = "请选择 RCU 模型文件!"
|
||||
dlg.Filter = "RCU模型信息(*.xml)|*.xml"
|
||||
If dlg.ShowDialog <> DialogResult.OK Then
|
||||
MsgBox("未选择 RCU 模型文件!")
|
||||
Me.Close()
|
||||
Return
|
||||
End If
|
||||
tmpRcuModelFile = dlg.FileName
|
||||
End Using
|
||||
initGrid1()
|
||||
DevModeInserfilag = 0
|
||||
DeviceModuleDic = New Dictionary(Of String, DeviceModel)
|
||||
SwitchConfig = New Dictionary(Of String, Dictionary(Of Integer, String))
|
||||
DeleteDevmodedic = New List(Of DeleteDevmodeclass)
|
||||
AddHostDeviceModule(tmpRcuModelFile)
|
||||
|
||||
|
||||
End Sub
|
||||
|
||||
Public DevModeInserfilag As Integer = 0
|
||||
Public Sub initGrid1()
|
||||
Grid1.NewFile()
|
||||
Grid1.Cols = ComboDropDownCol.max
|
||||
Grid1.Rows = 1
|
||||
Grid1.Column(0).Visible = False
|
||||
Grid1.Row(0).Visible = False
|
||||
Grid1.AddItem("")
|
||||
Grid1.AddItem("")
|
||||
Grid1.AddItem("")
|
||||
Grid1.AddItem("")
|
||||
Grid1.Row(ComboDropDownON.LightingCircuit2).Height = 50
|
||||
With Grid1.Range(ComboDropDownON.LightingCircuit, 1, ComboDropDownON.LightingCircuit2, 8)
|
||||
.Merge()
|
||||
.Alignment = AlignmentEnum.CenterCenter
|
||||
End With
|
||||
With Grid1.Cell(ComboDropDownON.LightingCircuit, 1)
|
||||
.Text = "灯光回路"
|
||||
.Locked = True
|
||||
End With
|
||||
|
||||
Grid1.AddItem("")
|
||||
Grid1.Cell(ComboDropDownON.KeyDev, ComboDropDownCol.devFile).Text = "设备地址"
|
||||
Grid1.Cell(ComboDropDownON.KeyDev, ComboDropDownCol.Keyval).Text = "键值"
|
||||
Grid1.Cell(ComboDropDownON.KeyDev, ComboDropDownCol.keyName).Text = "按键名称"
|
||||
Grid1.Cell(ComboDropDownON.KeyDev, ComboDropDownCol.music).Text = "是否需要提示音"
|
||||
Grid1.Cell(ComboDropDownON.KeyDev, ComboDropDownCol.空改1).Text = "是否需要服务调用"
|
||||
Grid1.Cell(ComboDropDownON.KeyDev, ComboDropDownCol.空改2).Text = "取电有效"
|
||||
Grid1.Cell(ComboDropDownON.KeyDev, ComboDropDownCol.空改3).Text = "起夜模式"
|
||||
Grid1.Cell(ComboDropDownON.KeyDev, ComboDropDownCol.空改4).Text = "总开模式"
|
||||
Grid1.Row(ComboDropDownON.KeyDev).Locked = True
|
||||
|
||||
Grid1.Column(2).Locked = True
|
||||
Grid1.FrozenRows = ComboDropDownON.max - 1
|
||||
Grid1.FrozenCols = ComboDropDownCol.max - 1
|
||||
|
||||
'Grid1.Column(3).Locked = True
|
||||
'Grid1.Column(4).Locked = True
|
||||
|
||||
End Sub
|
||||
Public HostDevFNP As String = "C:\BLV_Studio\Data\Model\RCUModel\"
|
||||
Private Sub Grid1_ComboDropDown(Sender As Object, e As Grid.ComboDropDownEventArgs) Handles Grid1.ComboDropDown
|
||||
Grid1.ComboBox(0).Items.Clear()
|
||||
Select Case e.Row
|
||||
'Case ComboDropDownON.HostDev
|
||||
' For Each HostDevFN In IO.Directory.GetFiles(HostDevFNP)
|
||||
' Grid1.ComboBox(0).Items.Add(HostDevFN.Substring(HostDevFNP.Length, HostDevFN.Length - HostDevFNP.Length - 4))
|
||||
' Next
|
||||
Case >= ComboDropDownON.max
|
||||
|
||||
|
||||
|
||||
Console.WriteLine()
|
||||
If Grid1.Cell(ComboDropDownON.LightingCircuit0, Grid1.ActiveCell.Col).Text.Equals("MUSIC") Then
|
||||
Dim fromshow As New MusicArrangement
|
||||
fromshow.basicClass = basicClass
|
||||
If fromshow.ShowDialog() <> DialogResult.OK Then Return
|
||||
Grid1.Cell(Grid1.ActiveCell.Row, Grid1.ActiveCell.Col).Text = fromshow.GmusicVal
|
||||
|
||||
Else
|
||||
For Each index In [Enum].GetValues(GetType(CellDrop))
|
||||
Grid1.ComboBox(0).Items.Add(Chr(index))
|
||||
Next
|
||||
End If
|
||||
|
||||
|
||||
End Select
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub Grid1_CellChange(Sender As Object, e As Grid.CellChangeEventArgs) Handles Grid1.CellChange
|
||||
Select Case e.Row
|
||||
'Case ComboDropDownON.HostDev
|
||||
' If e.Col > 1 Then
|
||||
' SwitchConfig.Clear()
|
||||
' AddHostDeviceModule(HostDevFNP & Grid1.Cell(e.Row, e.Col).Text & ".xml")
|
||||
' End If
|
||||
Case ComboDropDownON.LightingCircuit2
|
||||
If e.Col > 4 And IsRelayflag Then
|
||||
SetRELAYAnotherName(e.Row, e.Col)
|
||||
End If
|
||||
Case > ComboDropDownON.KeyDev
|
||||
If e.Col = 3 And IsRelayflag Then
|
||||
SetkeypadAnotherName(e.Row, e.Col)
|
||||
ElseIf e.Col > 4 And IsRelayflag Then
|
||||
Dim crow As Integer = -1
|
||||
|
||||
Integer.TryParse(Grid1.Cell(e.Row, 2).Text, crow)
|
||||
|
||||
|
||||
Dim keystr As String = Grid1.Cell(e.Row - (crow - 1), 1).Text
|
||||
keystr = $"{keystr}:{crow.ToString }"
|
||||
Dim dic As Dictionary(Of Integer, String) = SwitchConfig.Item(keystr)
|
||||
If dic.ContainsKey(e.Col) And Not String.IsNullOrEmpty(Grid1.Cell(e.Row, e.Col).Text) Then
|
||||
dic.Item(e.Col) = Grid1.Cell(e.Row, e.Col).Text
|
||||
Else
|
||||
dic.Add(e.Col, Grid1.Cell(e.Row, e.Col).Text)
|
||||
End If
|
||||
|
||||
End If
|
||||
End Select
|
||||
|
||||
End Sub
|
||||
|
||||
Public Sub SetRELAYAnotherName(r As Integer, c As Integer)
|
||||
Dim place As Integer = c - 4
|
||||
For Each moduStr In DeviceModuleDic
|
||||
For Each ModuleFre In moduStr.Value.Nodes
|
||||
If ModuleFre.Name.Equals("RELAY") Then
|
||||
If ModuleFre.Nodes.Count < place Then
|
||||
place = place - ModuleFre.Nodes.Count
|
||||
Else
|
||||
ModuleFre.Nodes(place - 1).Name = Grid1.Cell(r, c).Text
|
||||
Exit Sub
|
||||
End If
|
||||
Exit For
|
||||
End If
|
||||
|
||||
Next
|
||||
|
||||
Next
|
||||
End Sub
|
||||
Public Sub SetkeypadAnotherName(r As Integer, c As Integer)
|
||||
Dim place As Integer = r - ComboDropDownON.KeyDev
|
||||
For Each moduStr In DeviceModuleDic
|
||||
For Each ModuleFre In moduStr.Value.Nodes
|
||||
If ModuleFre.Name.Equals("DI") Then
|
||||
If ModuleFre.Nodes.Count < place Then
|
||||
place = place - ModuleFre.Nodes.Count
|
||||
Else
|
||||
If IsRelayflag Then
|
||||
ModuleFre.Nodes(place - 1).Name = Grid1.Cell(r, c).Text
|
||||
Exit Sub
|
||||
End If
|
||||
End If
|
||||
Exit For
|
||||
End If
|
||||
|
||||
Next
|
||||
|
||||
Next
|
||||
End Sub
|
||||
|
||||
|
||||
Public DeviceModuleDic As Dictionary(Of String, DeviceModel)
|
||||
Public Sub AddHostDeviceModule(HostDevicefile As String)
|
||||
Try
|
||||
Dim model As DeviceModel = LoadModelFromXml(HostDevicefile)
|
||||
SwitchConfig.Clear()
|
||||
If DeviceModuleDic.ContainsKey("HostDevice") Then
|
||||
DeviceModuleDic.Item("HostDevice") = model
|
||||
Else
|
||||
DeviceModuleDic.Add("HostDevice", model)
|
||||
End If
|
||||
Catch ex As Exception
|
||||
MsgBox("添加主机失败!")
|
||||
Return
|
||||
End Try
|
||||
ShowRelay()
|
||||
|
||||
'For Each inten In model.Nodes
|
||||
' If inten.Name.Equals("RELAY") Then
|
||||
' Dim hotel = New TreeNode(inten.Name)
|
||||
' For Each Cindten In inten.Nodes
|
||||
' Dim hotelc As New TreeNode(Cindten.Name)
|
||||
' hotel.Nodes.Add(hotelc)
|
||||
' Next
|
||||
' DeviceModuleDic.Nodes.Add(hotel)
|
||||
' Return
|
||||
' Else
|
||||
' Continue For
|
||||
' End If
|
||||
'Next
|
||||
|
||||
End Sub
|
||||
Public Function LoadModelFromXml(path As String) As DeviceModel
|
||||
Return BXmlSerializer.DeserializeFormXml(Of DeviceModel)(path)
|
||||
End Function
|
||||
Public DevModel As String = "C:\BLV_Studio\Data\Model\485Model\"
|
||||
Private Sub ToolStripComboBox1_DropDown(sender As Object, e As EventArgs) Handles ToolStripComboBox1.DropDown
|
||||
ToolStripComboBox1.Items.Clear()
|
||||
For Each HostDevFN In IO.Directory.GetFiles(DevModel)
|
||||
ToolStripComboBox1.Items.Add(HostDevFN.Substring(DevModel.Length, HostDevFN.Length - DevModel.Length - 4))
|
||||
Next
|
||||
End Sub
|
||||
|
||||
Private Sub ToolStripButton1_Click(sender As Object, e As EventArgs) Handles ToolStripButton1.Click
|
||||
Dim model As DeviceModel
|
||||
Try
|
||||
model = LoadModelFromXml(DevModel & ToolStripComboBox1.Text & ".xml")
|
||||
If DeviceModuleDic.ContainsKey("HostDevice") Then
|
||||
If model.Desc.DevInterface.Equals("RS485Polling") Then
|
||||
|
||||
'If DeviceModuleDic.ContainsKey(ToolStripComboBox1.Text) Then
|
||||
'DeviceModuleDic.Item("HostDevice") = model
|
||||
Dim number As Integer = ModuleFrequency(ToolStripComboBox1.Text)
|
||||
'DeviceModuleDic.Add($"{ToolStripComboBox1.Text}_{number}", model)
|
||||
Dim strindex As String = GetindexNumber(ToolStripComboBox1.Text, number)
|
||||
DeviceModuleDic = DeviceModuleDicDiinsertion(DeviceModuleDic, DevModeInserfilag, strindex, model)
|
||||
'Else
|
||||
' ' DeviceModuleDic.Add(ToolStripComboBox1.Text, model)
|
||||
' DeviceModuleDic = DeviceModuleDicDiinsertion(DeviceModuleDic, DevModeInserfilag, $"{ToolStripComboBox1.Text}", model)
|
||||
'End If
|
||||
DevModeInserfilag = DevModeInserfilag + 1
|
||||
Else
|
||||
MsgBox($"添加外设模块失败!")
|
||||
Return
|
||||
End If
|
||||
Else
|
||||
MsgBox($"未添加主机!")
|
||||
Return
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
MsgBox($"加载设备模型错误,{ex.Message}")
|
||||
Return
|
||||
End Try
|
||||
ShowRelay()
|
||||
End Sub
|
||||
|
||||
Public Function GetindexNumber(str As String, index As Integer) As String
|
||||
Dim result As String
|
||||
If DeviceModuleDic.ContainsKey($"{str}:{index}") Then
|
||||
index = index + 1
|
||||
result = GetindexNumber(str, index)
|
||||
Else
|
||||
result = $"{str}:{index}"
|
||||
End If
|
||||
Return result
|
||||
End Function
|
||||
Public Function ModuleFrequency(hfreq As String) As Integer
|
||||
Dim result As Integer = 1
|
||||
Dim str As String = String.Empty
|
||||
Dim strbuff() As String
|
||||
Dim index As Integer = -1
|
||||
For Each moduStr In DeviceModuleDic.Keys
|
||||
If moduStr.Contains(hfreq) Then
|
||||
result = result + 1
|
||||
str = moduStr
|
||||
End If
|
||||
|
||||
Next
|
||||
If str.Length > 0 Then
|
||||
strbuff = str.Split(":")
|
||||
If strbuff.Length > 1 Then
|
||||
Integer.TryParse(strbuff(1), index)
|
||||
End If
|
||||
If index > result Then result = index + 1
|
||||
End If
|
||||
|
||||
Return result
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
Public IsRelayflag As Boolean
|
||||
Public Sub ShowRelay()
|
||||
Dim Startid As Integer = ComboDropDownCol.max
|
||||
Grid1.Cols = ComboDropDownCol.max
|
||||
IsRelayflag = False
|
||||
Dim demoindex As Integer = Startid
|
||||
|
||||
Dim g_Dimming As DeviceChildNodeClass
|
||||
Dim g_RELAY As DeviceChildNodeClass
|
||||
Dim g_DO As DeviceChildNodeClass
|
||||
Dim g_MUSIC As DeviceChildNodeClass
|
||||
|
||||
For Each moduStr In DeviceModuleDic
|
||||
g_Dimming = Nothing
|
||||
g_RELAY = Nothing
|
||||
g_DO = Nothing
|
||||
g_MUSIC = Nothing
|
||||
For Each ModuleFre In moduStr.Value.Nodes
|
||||
' If ModuleFre.Name.Equals("Dimming") OrElse ModuleFre.Name.Equals("RELAY") OrElse ModuleFre.Name.Equals("DO") Then
|
||||
|
||||
'添加继电器列
|
||||
'Grid1.Cols = demoindex + ModuleFre.Nodes.Count
|
||||
'Grid1.Cell(ComboDropDownON.LightingCircuit0, demoindex).Text = ModuleFre.Name
|
||||
'Grid1.Range(ComboDropDownON.LightingCircuit0, demoindex, ComboDropDownON.LightingCircuit0, demoindex + ModuleFre.Nodes.Count - 1).Merge()
|
||||
'Grid1.Range(ComboDropDownON.LightingCircuit, demoindex, ComboDropDownON.LightingCircuit, demoindex + ModuleFre.Nodes.Count - 1).Locked = False
|
||||
'Grid1.Range(ComboDropDownON.LightingCircuit, demoindex, ComboDropDownON.LightingCircuit, demoindex + ModuleFre.Nodes.Count - 1).Merge()
|
||||
'Grid1.Range(ComboDropDownON.LightingCircuit, demoindex, ComboDropDownON.LightingCircuit, demoindex + ModuleFre.Nodes.Count - 1).Locked = True
|
||||
'If moduStr.Key.Equals("HostDevice") Then
|
||||
' Grid1.Cell(ComboDropDownON.LightingCircuit, Startid).Text = moduStr.Value.Name
|
||||
'Else
|
||||
' Grid1.Cell(ComboDropDownON.LightingCircuit, Startid).Text = moduStr.Key
|
||||
'End If
|
||||
|
||||
|
||||
'Grid1.Range(ComboDropDownON.LightingCircuit1, demoindex, ComboDropDownON.LightingCircuit1, demoindex + ModuleFre.Nodes.Count - 1).Locked = True
|
||||
'Grid1.Range(ComboDropDownON.LightingCircuit, Startid, ComboDropDownON.LightingCircuit0, Startid + ModuleFre.Nodes.Count - 1).Alignment = AlignmentEnum.CenterCenter
|
||||
'For i As Integer = 0 To ModuleFre.Nodes.Count - 1
|
||||
' Grid1.Cell(ComboDropDownON.LightingCircuit1, demoindex + i).Text = (i + 1).ToString
|
||||
' Console.WriteLine($"{ModuleFre.Name}_R:{ComboDropDownON.LightingCircuit1.ToString }_C:{Startid + i}_{(i + 1).ToString}")
|
||||
' Grid1.Cell(ComboDropDownON.LightingCircuit2, demoindex + i).Text = ModuleFre.Nodes(i).Name
|
||||
'Next
|
||||
'demoindex = demoindex + ModuleFre.Nodes.Count
|
||||
' End If
|
||||
If ModuleFre.Name.Equals("Dimming") Then
|
||||
g_Dimming = ModuleFre
|
||||
ElseIf ModuleFre.Name.Equals("RELAY") Then
|
||||
g_RELAY = ModuleFre
|
||||
ElseIf ModuleFre.Name.Equals("DO") Then
|
||||
g_DO = ModuleFre
|
||||
ElseIf ModuleFre.Name.Equals("MUSIC") Then
|
||||
g_MUSIC = ModuleFre
|
||||
End If
|
||||
|
||||
Next
|
||||
AddColumnConfig(g_DO, demoindex, Startid, moduStr)
|
||||
AddColumnConfig(g_RELAY, demoindex, Startid, moduStr)
|
||||
AddColumnConfig(g_Dimming, demoindex, Startid, moduStr)
|
||||
AddColumnConfig(g_MUSIC, demoindex, Startid, moduStr)
|
||||
Startid = demoindex
|
||||
Next
|
||||
ShowSwitch()
|
||||
IsRelayflag = True
|
||||
End Sub
|
||||
|
||||
|
||||
Public Sub AddColumnConfig(ModuleFre As DeviceChildNodeClass, ByRef demoindex As Integer, Startid As Integer, moduStr As KeyValuePair(Of String, DeviceModel))
|
||||
'添加继电器列
|
||||
If IsNothing(ModuleFre) OrElse ModuleFre.Nodes.Count = 0 Then Return
|
||||
Grid1.Cols = demoindex + ModuleFre.Nodes.Count
|
||||
Grid1.Cell(ComboDropDownON.LightingCircuit0, demoindex).Text = ModuleFre.Name
|
||||
Grid1.Range(ComboDropDownON.LightingCircuit0, demoindex, ComboDropDownON.LightingCircuit0, demoindex + ModuleFre.Nodes.Count - 1).Merge()
|
||||
Grid1.Range(ComboDropDownON.LightingCircuit, Startid, ComboDropDownON.LightingCircuit, demoindex + ModuleFre.Nodes.Count - 1).Locked = False
|
||||
Grid1.Range(ComboDropDownON.LightingCircuit, Startid, ComboDropDownON.LightingCircuit, demoindex + ModuleFre.Nodes.Count - 1).Merge()
|
||||
Grid1.Range(ComboDropDownON.LightingCircuit, Startid, ComboDropDownON.LightingCircuit, demoindex + ModuleFre.Nodes.Count - 1).Locked = True
|
||||
If moduStr.Key.Equals("HostDevice") Then
|
||||
Grid1.Cell(ComboDropDownON.LightingCircuit, Startid).Text = moduStr.Value.Name
|
||||
Else
|
||||
Grid1.Cell(ComboDropDownON.LightingCircuit, Startid).Text = moduStr.Key
|
||||
End If
|
||||
|
||||
|
||||
Grid1.Range(ComboDropDownON.LightingCircuit1, demoindex, ComboDropDownON.LightingCircuit1, demoindex + ModuleFre.Nodes.Count - 1).Locked = True
|
||||
Grid1.Range(ComboDropDownON.LightingCircuit, Startid, ComboDropDownON.LightingCircuit2, Startid + ModuleFre.Nodes.Count - 1).Alignment = AlignmentEnum.CenterCenter
|
||||
For i As Integer = 0 To ModuleFre.Nodes.Count - 1
|
||||
Grid1.Cell(ComboDropDownON.LightingCircuit1, demoindex + i).Text = (i + 1).ToString
|
||||
Console.WriteLine($"{ModuleFre.Name}_R:{ComboDropDownON.LightingCircuit1.ToString }_C:{Startid + i}_{(i + 1).ToString}")
|
||||
Grid1.Cell(ComboDropDownON.LightingCircuit2, demoindex + i).Text = ModuleFre.Nodes(i).Name
|
||||
Grid1.Cell(ComboDropDownON.LightingCircuit2, demoindex + i).Orientation = TextOrientationEnum.Vertical
|
||||
|
||||
Next
|
||||
demoindex = demoindex + ModuleFre.Nodes.Count
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
|
||||
Public SwitchConfig As Dictionary(Of String, Dictionary(Of Integer, String))
|
||||
Public Sub ShowSwitch()
|
||||
IsRelayflag = False
|
||||
Grid1.AutoRedraw = False
|
||||
Dim rdilenma As String
|
||||
For moduStr As Integer = ComboDropDownON.max To Grid1.Rows - 1
|
||||
Grid1.Row(Grid1.Rows - 1).Delete()
|
||||
Next
|
||||
'SwitchConfig.Clear()
|
||||
Dim rowid As Integer = Grid1.Rows
|
||||
For Each moduStr In DeviceModuleDic
|
||||
|
||||
For Each ModuleFre In moduStr.Value.Nodes
|
||||
If ModuleFre.Name.Equals("DI") Then
|
||||
'添加继电器列
|
||||
|
||||
For i As Integer = 0 To ModuleFre.Nodes.Count - 1
|
||||
Grid1.AddItem("")
|
||||
If i = 0 Then
|
||||
If moduStr.Key.Equals("HostDevice") Then
|
||||
Grid1.Cell(rowid, ComboDropDownCol.devFile).Text = moduStr.Value.Name
|
||||
Else
|
||||
Grid1.Cell(rowid, ComboDropDownCol.devFile).Text = moduStr.Key
|
||||
End If
|
||||
rdilenma = Grid1.Cell(rowid, 1).Text
|
||||
End If
|
||||
|
||||
If Not SwitchConfig.ContainsKey($"{rdilenma}:{i + 1}") Then
|
||||
Dim dic As New Dictionary(Of Integer, String)
|
||||
dic.Add(ComboDropDownCol.music, Chr(CellDrop.TurnOn))
|
||||
dic.Add(ComboDropDownCol.空改2, Chr(CellDrop.TurnOn))
|
||||
SwitchConfig.Add($"{rdilenma}:{i + 1}", dic)
|
||||
End If
|
||||
|
||||
Grid1.Cell(rowid + i, ComboDropDownCol.Keyval).Text = (i + 1).ToString
|
||||
Grid1.Cell(rowid + i, ComboDropDownCol.keyName).Text = ModuleFre.Nodes(i).Name
|
||||
|
||||
Grid1.Cell(rowid + i, ComboDropDownCol.music).Text = Chr(CellDrop.TurnOn)
|
||||
Grid1.Cell(rowid + i, ComboDropDownCol.空改2).Text = Chr(CellDrop.TurnOn)
|
||||
Next
|
||||
|
||||
Grid1.Cell(rowid, 1).WrapText = True
|
||||
Grid1.Range(rowid, 1, Grid1.Rows - 1, ComboDropDownCol.devFile).Merge()
|
||||
Grid1.Range(rowid, 1, Grid1.Rows - 1, ComboDropDownCol.devFile).Locked = True
|
||||
rowid = Grid1.Rows
|
||||
|
||||
End If
|
||||
Next
|
||||
|
||||
Next
|
||||
Grid1.Range(ComboDropDownON.max, ComboDropDownCol.music, Grid1.Rows - 1, Grid1.Cols - 1).Alignment = AlignmentEnum.CenterCenter
|
||||
Grid1.Range(ComboDropDownON.max, ComboDropDownCol.music, Grid1.Rows - 1, Grid1.Cols - 1).CellType = CellTypeEnum.ComboBox
|
||||
|
||||
SetGrid1RowTxt()
|
||||
Grid1.AutoRedraw = True
|
||||
Grid1.Refresh()
|
||||
IsRelayflag = True
|
||||
End Sub
|
||||
|
||||
|
||||
Public Sub SetGrid1RowTxt()
|
||||
Dim rfilename As String
|
||||
Dim keystr As String
|
||||
Dim dic As Dictionary(Of Integer, String)
|
||||
For i As Integer = ComboDropDownON.max To Grid1.Rows - 1
|
||||
If Grid1.Cell(i, 2).Text.Equals("1") Then
|
||||
rfilename = Grid1.Cell(i, 1).Text
|
||||
End If
|
||||
keystr = $"{rfilename}:{Grid1.Cell(i, 2).Text}"
|
||||
dic = SwitchConfig.Item(keystr)
|
||||
For Each node In dic
|
||||
Grid1.Cell(i, node.Key).Text = node.Value
|
||||
Next
|
||||
|
||||
Next
|
||||
|
||||
|
||||
'For Each inten In SwitchConfig
|
||||
' For Each node In inten.Value
|
||||
' Grid1.Cell(inten.Key, node.Key).Text = node.Value
|
||||
' Next
|
||||
'Next
|
||||
End Sub
|
||||
|
||||
Private Sub ToolStripComboBox2_DropDown(sender As Object, e As EventArgs) Handles ToolStripComboBox2.DropDown
|
||||
ToolStripComboBox2.Items.Clear()
|
||||
For Each HostDevFN In IO.Directory.GetFiles(DevModel)
|
||||
ToolStripComboBox2.Items.Add(HostDevFN.Substring(DevModel.Length, HostDevFN.Length - DevModel.Length - 4))
|
||||
Next
|
||||
End Sub
|
||||
|
||||
Private Sub ToolStripButton2_Click(sender As Object, e As EventArgs) Handles ToolStripButton3.Click
|
||||
Dim model As DeviceModel
|
||||
Try
|
||||
model = LoadModelFromXml(DevModel & ToolStripComboBox2.Text & ".xml")
|
||||
If DeviceModuleDic.ContainsKey("HostDevice") Then
|
||||
If model.Desc.DevInterface.Equals("RS485Active") Then
|
||||
|
||||
'If DeviceModuleDic.ContainsKey(ToolStripComboBox2.Text) Then
|
||||
'DeviceModuleDic.Item("HostDevice") = model
|
||||
Dim number As Integer = ModuleFrequency(ToolStripComboBox2.Text)
|
||||
Dim strindex As String = GetindexNumber(ToolStripComboBox2.Text, number)
|
||||
DeviceModuleDic.Add(strindex, model)
|
||||
|
||||
Dim dic As New Dictionary(Of String, String)
|
||||
|
||||
'Else
|
||||
' DeviceModuleDic.Add(ToolStripComboBox2.Text, model)
|
||||
'End If
|
||||
|
||||
Else
|
||||
MsgBox($"添加外设模块失败!")
|
||||
Return
|
||||
End If
|
||||
Else
|
||||
MsgBox($"未添加主机!")
|
||||
Return
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
MsgBox($"加载设备模型错误,{ex.Message}")
|
||||
Return
|
||||
End Try
|
||||
ShowSwitch()
|
||||
End Sub
|
||||
Public Function DeviceModuleDicDiinsertion(dic As Dictionary(Of String, DeviceModel), index As Integer, kstr As String, model As DeviceModel) As Dictionary(Of String, DeviceModel)
|
||||
Dim result As New Dictionary(Of String, DeviceModel)
|
||||
For i As Integer = 0 To dic.Count - 1
|
||||
result.Add(dic.Keys(i), dic.Values(i))
|
||||
If i = index Then
|
||||
result.Add(kstr, model)
|
||||
End If
|
||||
Next
|
||||
Return result
|
||||
End Function
|
||||
Public Function UpdataModuleDicDiinsertion(dic As Dictionary(Of String, DeviceModel)) As Dictionary(Of String, DeviceModel)
|
||||
Dim result As New Dictionary(Of String, DeviceModel)
|
||||
For i As Integer = 0 To dic.Count - 1
|
||||
result.Add(dic.Keys(i), dic.Values(i))
|
||||
Next
|
||||
Return result
|
||||
End Function
|
||||
|
||||
Private Function SetKeyValuePair() As KeyValuePair(Of Integer, String)
|
||||
Dim intKey As Integer = 1
|
||||
Dim strValue As String = "My value"
|
||||
Dim kvp As KeyValuePair(Of Integer, String) = New KeyValuePair(Of Integer, String)(intKey, strValue)
|
||||
Return kvp
|
||||
End Function
|
||||
Private Sub ToolStripButton6_Click(sender As Object, e As EventArgs) Handles ToolStripButton6.Click
|
||||
TestForm1_Load(Nothing, Nothing)
|
||||
End Sub
|
||||
|
||||
Private Sub ToolStripButton5_Click(sender As Object, e As EventArgs) Handles ToolStripButton5.Click
|
||||
If String.IsNullOrEmpty(ShipmentFile) Then
|
||||
ToolStripButton2_Click_1(Nothing, Nothing)
|
||||
Else
|
||||
If IO.File.Exists(ShipmentFile) Then
|
||||
If MsgBox("已存在同名文件是否覆盖?", MsgBoxStyle.OkCancel) = MsgBoxResult.Ok Then
|
||||
Grid1.SaveFile($"{ShipmentFile}")
|
||||
DeleteDevmodedic.Clear()
|
||||
MsgBox($"保存完成:{ShipmentFile}")
|
||||
End If
|
||||
Else
|
||||
Grid1.SaveFile($"{ShipmentFile}")
|
||||
DeleteDevmodedic.Clear()
|
||||
MsgBox($"保存完成:{ShipmentFile}")
|
||||
End If
|
||||
|
||||
End If
|
||||
' IO.Directory.CreateDirectory($"{Application.StartupPath}\Table\")
|
||||
'Grid1.ExportToCSV($"{Application.StartupPath}\Table\{Date.Now.ToString("yyyyMMddHHmmssfff")}.csv", False, False)
|
||||
|
||||
|
||||
End Sub
|
||||
Public ShipmentFile As String
|
||||
Private Sub ToolStripButton4_Click(sender As Object, e As EventArgs) Handles ToolStripButton4.Click
|
||||
Using dlg As New OpenFileDialog
|
||||
dlg.InitialDirectory = Application.StartupPath
|
||||
dlg.Title = "请选择文件!"
|
||||
dlg.Filter = "逻辑表(*.flx)|*.flx"
|
||||
If dlg.ShowDialog <> DialogResult.OK Then Return
|
||||
DeviceModuleDic.Clear()
|
||||
ShipmentFile = dlg.FileName
|
||||
If Not Grid1.OpenFile(ShipmentFile) Then
|
||||
MsgBox("文件损坏,打开失败!")
|
||||
Else
|
||||
UploadDeviceModuleDic()
|
||||
DeleteDevmodedic.Clear()
|
||||
End If
|
||||
End Using
|
||||
End Sub
|
||||
|
||||
|
||||
Public Sub UploadDeviceModuleDic()
|
||||
Dim intlabel As Integer = ComboDropDownON.max
|
||||
Dim col As Integer = 5
|
||||
Dim HostDevicefile As String
|
||||
Dim model As DeviceModel
|
||||
Dim kval As KeyValuePair(Of Integer, Integer)
|
||||
DeviceModuleDic.Clear()
|
||||
SwitchConfig.Clear()
|
||||
DevModeInserfilag = 0
|
||||
Dim filenaem() As String
|
||||
While True
|
||||
If intlabel < Grid1.Rows - 1 Then
|
||||
filenaem = Grid1.Cell(intlabel, 1).Text.Split(":")
|
||||
HostDevicefile = DevModel & filenaem(0) & ".xml"
|
||||
If IO.File.Exists(HostDevicefile) Then
|
||||
model = LoadModelFromXml(HostDevicefile)
|
||||
kval = Analysismodel(model, intlabel, col)
|
||||
DeviceModuleDic.Add(Grid1.Cell(intlabel, 1).Text, model)
|
||||
|
||||
Else
|
||||
'HostDevicefile = $"{HostDevFNP}{Grid1.Cell(intlabel, 1).Text}.xml"
|
||||
HostDevicefile = HostDevFNP & Grid1.Cell(intlabel, 1).Text.Replace("_", "-") & ".xml"
|
||||
|
||||
If IO.File.Exists(HostDevicefile) Then
|
||||
model = LoadModelFromXml(HostDevicefile)
|
||||
kval = Analysismodel(model, intlabel, col)
|
||||
DeviceModuleDic.Add(Grid1.Cell(intlabel, 1).Text, model)
|
||||
Else
|
||||
MsgBox($"加载失败!未找到文件{Grid1.Cell(intlabel, 1).Text}.xml")
|
||||
TestForm1_Load(Nothing, Nothing)
|
||||
Return
|
||||
End If
|
||||
End If
|
||||
|
||||
|
||||
Else
|
||||
Return
|
||||
End If
|
||||
intlabel = kval.Key
|
||||
col = kval.Value
|
||||
End While
|
||||
|
||||
End Sub
|
||||
|
||||
Public Function Analysismodel(model As DeviceModel, row As Integer, col As Integer) As KeyValuePair(Of Integer, Integer)
|
||||
Dim filename As String = Grid1.Cell(row, 1).Text
|
||||
Dim keystr As String
|
||||
For Each inten In model.Nodes
|
||||
If inten.Name.Equals("RELAY") Then
|
||||
For Each node In inten.Nodes
|
||||
node.Name = Grid1.Cell(ComboDropDownON.LightingCircuit2, col).Text
|
||||
col = col + 1
|
||||
Next
|
||||
End If
|
||||
If inten.Name.Equals("DI") Then
|
||||
For Each node In inten.Nodes
|
||||
node.Name = Grid1.Cell(row, 3).Text
|
||||
'添加行数据
|
||||
Dim dic As New Dictionary(Of Integer, String)
|
||||
|
||||
For i As Integer = 5 To Grid1.Cols - 1
|
||||
If Grid1.Cell(row, i).Text.Length > 0 Then
|
||||
dic.Add(i, Grid1.Cell(row, i).Text)
|
||||
End If
|
||||
Next
|
||||
keystr = $"{filename}:{Grid1.Cell(row, 2).Text}"
|
||||
SwitchConfig.Add(keystr, dic)
|
||||
|
||||
row = row + 1
|
||||
Next
|
||||
|
||||
End If
|
||||
|
||||
Next
|
||||
|
||||
Dim ndic As New Dictionary(Of Integer, Integer)
|
||||
ndic.Add(row, col)
|
||||
For Each inten In ndic
|
||||
Return inten
|
||||
Next
|
||||
|
||||
|
||||
|
||||
End Function
|
||||
|
||||
Private Sub ToolStripButton2_Click_1(sender As Object, e As EventArgs) Handles ToolStripButton2.Click
|
||||
Using dlg As New SaveFileDialog
|
||||
|
||||
|
||||
With dlg
|
||||
.InitialDirectory = Application.StartupPath
|
||||
.RestoreDirectory = True
|
||||
.OverwritePrompt = True
|
||||
.AddExtension = True
|
||||
.DefaultExt = ".xml"
|
||||
.Title = "保存文件"
|
||||
.Filter = $"逻辑文件(*.flx)|*.flx"
|
||||
End With
|
||||
If dlg.ShowDialog <> DialogResult.OK Then Return
|
||||
|
||||
Grid1.SaveFile($"{ dlg.FileName }")
|
||||
MsgBox($"文件保存完成:{dlg.FileName}")
|
||||
End Using
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
End Sub
|
||||
Public DeleteDevmodedic As List(Of DeleteDevmodeclass)
|
||||
Private Sub ToolStripButton7_Click(sender As Object, e As EventArgs) Handles ToolStripButton7.Click
|
||||
Dim Deletenode As DeleteDevmodeclass
|
||||
Dim crow As Integer = -1
|
||||
Integer.TryParse(Grid1.Cell(Grid1.ActiveCell.Row, 2).Text, crow)
|
||||
|
||||
Dim filestr As String = Grid1.Cell(Grid1.ActiveCell.Row - crow + 1, 1).Text
|
||||
Dim rownode As String
|
||||
If DeviceModuleDic.ContainsKey(filestr) Then
|
||||
|
||||
Dim Ctrldeletenode As New DeleteDevmodeclass(DeepCopyHelper.DeepCopy(SwitchConfig), DeepCopyHelper.DictionaryCopy(DeviceModuleDic), DevModeInserfilag)
|
||||
|
||||
|
||||
|
||||
DeleteDevmodedic.Add(Ctrldeletenode)
|
||||
If DeviceModuleDic.Item(filestr).Desc.DevInterface.Equals("RS485Polling") Then
|
||||
DevModeInserfilag = DevModeInserfilag - 1
|
||||
End If
|
||||
For Each node In DeviceModuleDic.Item(filestr).Nodes
|
||||
If node.Name.Equals("DI") Then
|
||||
For i As Integer = 0 To node.Nodes.Count - 1
|
||||
rownode = $"{filestr}:{i + 1}"
|
||||
If SwitchConfig.ContainsKey(rownode) Then
|
||||
SwitchConfig.Remove(rownode)
|
||||
End If
|
||||
|
||||
Next
|
||||
|
||||
End If
|
||||
Next
|
||||
DeviceModuleDic.Remove(filestr)
|
||||
|
||||
DeviceModuleDic = UpdataModuleDicDiinsertion(DeviceModuleDic)
|
||||
End If
|
||||
|
||||
|
||||
ShowRelay()
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub ToolStripButton8_Click(sender As Object, e As EventArgs) Handles ToolStripButton8.Click
|
||||
If DeleteDevmodedic.Count > 0 Then
|
||||
Dim linode As DeleteDevmodeclass = DeleteDevmodedic.Item(DeleteDevmodedic.Count - 1)
|
||||
SwitchConfig = linode.G_SwitchConfig
|
||||
DeviceModuleDic = linode.G_DeviceModuleDic
|
||||
DevModeInserfilag = linode.G_DevModeInserfilag
|
||||
DeleteDevmodedic.RemoveAt(DeleteDevmodedic.Count - 1)
|
||||
ShowRelay()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub ToolStripButton9_Click(sender As Object, e As EventArgs) Handles ToolStripButton9.Click
|
||||
Dim lst As New List(Of Byte())
|
||||
|
||||
Dim newTableCompile As New TableCompile
|
||||
Dim configInfoLst As New List(Of Byte())
|
||||
' 编译配置信息
|
||||
Dim tmpInfo() As Byte = newTableCompile.FillConfigInfo(configInfo, DeviceModuleDic.Item("HostDevice").Name).ToArray
|
||||
configInfoLst.Add(tmpInfo)
|
||||
lst.AddRange(configInfoLst.ToArray)
|
||||
|
||||
'编译设备存在
|
||||
Dim deviceExistsDatas As List(Of Byte())
|
||||
Dim OutDevlist As New List(Of Byte)
|
||||
deviceExistsDatas = newTableCompile.FillDeviceExistsData(DeviceModuleDic, SwitchConfig)
|
||||
lst.AddRange(deviceExistsDatas.ToArray)
|
||||
'获取编译的设备动作
|
||||
Dim actibuf As List(Of Byte()) = newTableCompile.FillDeviceObject(DeviceModuleDic, SwitchConfig, Grid1)
|
||||
For Each buf In actibuf
|
||||
lst.Add(buf)
|
||||
Next
|
||||
|
||||
Dim frames As List(Of Byte()) = newTableCompile.FillDataFrames(lst)
|
||||
|
||||
|
||||
|
||||
'编译设备对象动作数据
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Dim filename As String = "C:\Users\Administrator\Desktop\Processform\test.dat"
|
||||
If IO.File.Exists(filename) Then IO.File.Delete(filename)
|
||||
Using steam As New IO.FileStream(filename, IO.FileMode.OpenOrCreate)
|
||||
For Each frame As Byte() In frames
|
||||
steam.Write(frame, 0, frame.Length)
|
||||
Console.WriteLine($"Length:{frame.Length:D4} Data:{BitConverter.ToString(frame).Replace("-", " ")}")
|
||||
Next
|
||||
steam.Flush()
|
||||
steam.Close()
|
||||
End Using
|
||||
Dim filebuff() As Byte = IO.File.ReadAllBytes(filename)
|
||||
Dim ismod As Integer = filebuff.Length Mod 4
|
||||
Dim buff As New List(Of Byte)
|
||||
buff.AddRange(filebuff)
|
||||
For isnum As Integer = 1 To (4 - ismod)
|
||||
buff.Add(0)
|
||||
Next
|
||||
IO.File.WriteAllBytes(filename, buff.ToArray)
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
End Class
|
||||
Public Class DeleteDevmodeclass
|
||||
Public G_SwitchConfig As Dictionary(Of String, Dictionary(Of Integer, String))
|
||||
Public G_DeviceModuleDic As Dictionary(Of String, DeviceModel)
|
||||
Public G_DevModeInserfilag As Integer
|
||||
Sub New(SwitchConfig As Dictionary(Of String, Dictionary(Of Integer, String)), DeviceModuleDic As Dictionary(Of String, DeviceModel), DevModeInserfilag As Integer)
|
||||
G_SwitchConfig = SwitchConfig
|
||||
G_DeviceModuleDic = DeviceModuleDic
|
||||
G_DevModeInserfilag = DevModeInserfilag
|
||||
End Sub
|
||||
End Class
|
||||
Reference in New Issue
Block a user