初始化
This commit is contained in:
102
BLV_Studio/Control/FrmMACDialog.vb
Normal file
102
BLV_Studio/Control/FrmMACDialog.vb
Normal file
@@ -0,0 +1,102 @@
|
||||
Imports System.Windows.Forms
|
||||
|
||||
Public Class FrmMACDialog
|
||||
Public FCsConfig As FrmCSeriesConfig
|
||||
Sub New(pathme As FrmCSeriesConfig)
|
||||
|
||||
' 此调用是设计器所必需的。
|
||||
InitializeComponent()
|
||||
FCsConfig = pathme
|
||||
' 在 InitializeComponent() 调用之后添加任何初始化。
|
||||
|
||||
End Sub
|
||||
Private Sub FrmMACDialog_Load(sender As Object, e As EventArgs) Handles Me.Load
|
||||
Label49.Text = LanguageData.StringList(MultiLanguageDAL.StringEnum.MAC)
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
|
||||
Private Sub FrmMACDialog_Shown(sender As Object, e As EventArgs) Handles Me.Shown
|
||||
TextBox5.Text = Nothing
|
||||
TextBox5.Focus() '设置焦点
|
||||
End Sub
|
||||
|
||||
|
||||
Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
|
||||
Dim mac As String = TextBox5.Text
|
||||
If mac = Nothing Then
|
||||
MsgBox($"{LanguageData.StringList(MultiLanguageDAL.StringEnum.PleaseScanTheMACAddress)}!")
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
mac = mac.Replace(" ", "").Replace("-", "").Replace("_", "").Replace(" ", "")
|
||||
If mac.Length <> 12 Then
|
||||
MsgBox($"MAC数据长度不匹配!")
|
||||
Return
|
||||
End If
|
||||
For index = 0 To mac.Length - 1 Step 2
|
||||
Try
|
||||
Dim b1 As Byte = $"&H{mac.Substring(index, 2)}"
|
||||
Catch ex As Exception
|
||||
MsgBox($"MAC数据不合法!")
|
||||
Return
|
||||
End Try
|
||||
Next
|
||||
|
||||
Me.DialogResult = System.Windows.Forms.DialogResult.OK
|
||||
FCsConfig._IsOK = True
|
||||
Me.Close()
|
||||
End Sub
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 显示窗体
|
||||
''' </summary>
|
||||
Public Sub ShowMyDialog()
|
||||
ShowDialog()
|
||||
End Sub
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 获取MAC地址
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Function GetMACAddress() As Byte()
|
||||
Dim data As String = TextBox5.Text
|
||||
data = data.Replace(" ", "").Replace("-", "").Replace("_", "").Replace(" ", "")
|
||||
|
||||
Dim databuff As Byte() = GetStringToDataByte(data)
|
||||
Dim dbyte(3) As Byte
|
||||
Array.Copy(databuff, databuff.Length - 4, dbyte, 0, dbyte.Length)
|
||||
'Console.WriteLine($"MAC取出来的数据:{ByteToString(dbyte)}")
|
||||
|
||||
Return dbyte
|
||||
End Function
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 字符串转换Byte数组
|
||||
''' </summary>
|
||||
''' <param name="data"></param>
|
||||
''' <returns></returns>
|
||||
Public Function GetStringToDataByte(data As String) As Byte()
|
||||
Dim dataList As New List(Of Byte)
|
||||
|
||||
For index As Integer = 0 To data.Length - 1 Step 2
|
||||
dataList.Add($"&H{data.Substring(index, 2)}")
|
||||
Next
|
||||
Console.WriteLine($"取位: {ByteToString(dataList.ToArray)}")
|
||||
|
||||
Return dataList.ToArray
|
||||
End Function
|
||||
|
||||
|
||||
Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
|
||||
Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
|
||||
FCsConfig._IsOK = False
|
||||
Me.Close()
|
||||
End Sub
|
||||
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user