📄 frmmain.vb
字号:
Option Strict Off
Option Explicit On
Friend Class frmMain
Inherits System.Windows.Forms.Form
Dim hopen As Integer
Private Sub eepromRdDate_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles eepromRdDate.Click
Dim mDataAddr As Integer
Dim mLen As Integer
'UPGRADE_WARNING: 结构 buffer 中的数组可能需要先初始化才可以使用。 单击以获得更多信息:“ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="814DF224-76BD-4BB4-BFFB-EA359CB9FC48"”
Dim buffer As arrRBuffer
Dim bu() As Byte
mLen = HexToBcd(RdDataLen.Text)
If (RdDataAddr.Text = "") Then
MsgBox("请输入数据单元起始地址!", MsgBoxStyle.Exclamation, "USB2ISP DEMO")
Exit Sub
End If
If (mLen <= 0) Then
MsgBox("请输入读取长度!", MsgBoxStyle.Exclamation, "USB2ISP DEMO")
Exit Sub
End If
mDataAddr = HexToBcd(RdDataAddr.Text)
Dim buff As String
Dim i As Integer
If (mOpen = True) Then
'UPGRADE_WARNING: 未能解析对象 buffer 的默认属性。 单击以获得更多信息:“ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"”
If (USBIO_ReadEEPROM(mIndex, Module1.eepromid, mDataAddr, mLen, buffer)) Then
For i = 0 To mLen - 1
buff = buff & Hex2bit(buffer.buf(i)) & " "
Next i
RdDataBuf.Text = buff
Else
MsgBox("读E2PROM数据失败!", MsgBoxStyle.Exclamation, "USB2ISP DEMO")
End If
RdDataLen.Text = Hex(mLen)
Else
MsgBox("设备未打开!", MsgBoxStyle.Exclamation, "USB2ISP DEMO")
End If
End Sub
Private Sub eepromWrDate_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles eepromWrDate.Click
Dim mData As Byte
Dim mDataAddr As Integer
Dim mLen As Integer
'UPGRADE_WARNING: 结构 buffer 中的数组可能需要先初始化才可以使用。 单击以获得更多信息:“ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="814DF224-76BD-4BB4-BFFB-EA359CB9FC48"”
Dim buffer As arrRBuffer
mLen = HexToBcd((WrDataLen.Text))
If (WrDataAddr.Text = "") Then
MsgBox("请输入数据单元起始地址!", MsgBoxStyle.Exclamation, "USB2ISP DEMO")
Exit Sub
End If
If (mLen <= 0 Or WrDataBuf.Text = "") Then
MsgBox("请输入要写入的数据,长度!", MsgBoxStyle.Exclamation, "USB2ISP DEMO")
Exit Sub
End If
If (mLen > (Len(WrDataBuf.Text) \ 2)) Then '在输入长度和数据长度中取小值
mLen = Len(WrDataBuf.Text) \ 2
End If
mDataAddr = HexToBcd((WrDataAddr.Text))
Call mStrtoVal((WrDataBuf.Text), buffer, mLen) '将输入的十六进制格式字符数据转成数值数据
If (mOpen = True) Then
'UPGRADE_WARNING: 未能解析对象 buffer 的默认属性。 单击以获得更多信息:“ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"”
If (USBIO_WriteEEPROM(mIndex, Module1.eepromid, mDataAddr, mLen, buffer) = False) Then
MsgBox("读E2PROM数据失败!", MsgBoxStyle.Exclamation, "USB2ISP DEMO")
End If
WrDataLen.Text = Hex(mLen)
Else
MsgBox("设备未打开!", MsgBoxStyle.Exclamation, "USB2ISP DEMO")
End If
End Sub
Private Sub eppRead0_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles eppRead0.Click
Dim mLen As Integer
'UPGRADE_WARNING: 结构 buffer 中的数组可能需要先初始化才可以使用。 单击以获得更多信息:“ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="814DF224-76BD-4BB4-BFFB-EA359CB9FC48"”
Dim buffer As arrRBuffer
mLen = HexToBcd((eppLen0.Text))
If (mLen <= 0) Then
MsgBox("请输入读取长度", MsgBoxStyle.Exclamation, "USB2ISP DEMO")
Exit Sub
End If
Dim buff As String
Dim i As Integer
If (mOpen = True) Then
'UPGRADE_WARNING: 未能解析对象 buffer 的默认属性。 单击以获得更多信息:“ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"”
If (USBIO_EppReadData(mIndex, buffer, mLen)) Then
buff = ""
For i = 0 To mLen - 1 Step 1
buff = buff & Hex2bit(buffer.buf(i)) & " "
Next
eppData0.Text = buff
Else
MsgBox("EPP方式读数据失败! ", MsgBoxStyle.Exclamation, "USB2ISP DEMO")
End If
eppLen0.Text = Hex(mLen)
Else
MsgBox("设备未打开!", MsgBoxStyle.Exclamation, "USB2ISP DEMO")
End If
End Sub
Private Sub eppRead1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles eppRead1.Click
Dim mLen As Integer
'UPGRADE_WARNING: 结构 buffer 中的数组可能需要先初始化才可以使用。 单击以获得更多信息:“ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="814DF224-76BD-4BB4-BFFB-EA359CB9FC48"”
Dim buffer As arrRBuffer
mLen = HexToBcd((eppLen1.Text))
If (mLen <= 0) Then
MsgBox("请输入读取数据的长度", MsgBoxStyle.Exclamation, "USB2ISP DEMO")
Exit Sub
End If
Dim buff As String
Dim i As Object
Dim j As Integer
If (mOpen = True) Then
'UPGRADE_WARNING: 未能解析对象 buffer 的默认属性。 单击以获得更多信息:“ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"”
If (USBIO_EppReadAddr(mIndex, buffer, mLen)) Then
j = 0
For i = 0 To mLen - 1
'UPGRADE_WARNING: 未能解析对象 i 的默认属性。 单击以获得更多信息:“ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"”
buff = buff & Hex2bit(buffer.buf(i)) & " "
Next
eppData1.Text = buff
Else
MsgBox("EPP读数据块1失败! ", MsgBoxStyle.Exclamation, "USB2ISP DEMO")
End If
eppLen1.Text = Hex(mLen)
Else
MsgBox("设备未打开!", MsgBoxStyle.Exclamation, "USB2ISP DEMO")
End If
End Sub
'UPGRADE_WARNING: 初始化窗体时可能激发事件 eppromtype.CheckedChanged。 单击以获得更多信息:“ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"”
Private Sub eppromtype_CheckedChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles eppromtype.CheckedChanged
If eventSender.Checked Then
Dim Index As Short = eppromtype.GetIndex(eventSender)
Select Case Index
Case 0
Module1.eepromid = USBIOXDLL.EEPROM_TYPE.ID_24C01
Case 1
Module1.eepromid = USBIOXDLL.EEPROM_TYPE.ID_24C02
Case 2
Module1.eepromid = USBIOXDLL.EEPROM_TYPE.ID_24C04
Case 3
Module1.eepromid = USBIOXDLL.EEPROM_TYPE.ID_24C08
Case 4
Module1.eepromid = USBIOXDLL.EEPROM_TYPE.ID_24C16
Case 5
Module1.eepromid = USBIOXDLL.EEPROM_TYPE.ID_24C32
Case 6
Module1.eepromid = USBIOXDLL.EEPROM_TYPE.ID_24C64
Case 7
Module1.eepromid = USBIOXDLL.EEPROM_TYPE.ID_24C128
Case 8
Module1.eepromid = USBIOXDLL.EEPROM_TYPE.ID_24C256
Case 9
Module1.eepromid = USBIOXDLL.EEPROM_TYPE.ID_24C512
Case 10
Module1.eepromid = USBIOXDLL.EEPROM_TYPE.ID_24C1024
Case 11
Module1.eepromid = USBIOXDLL.EEPROM_TYPE.ID_24C2048
Case 12
Module1.eepromid = USBIOXDLL.EEPROM_TYPE.ID_24C4096
End Select
End If
End Sub
Private Sub eppWrite0_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles eppWrite0.Click
Dim mLen As Integer
'UPGRADE_WARNING: 结构 buffer 中的数组可能需要先初始化才可以使用。 单击以获得更多信息:“ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="814DF224-76BD-4BB4-BFFB-EA359CB9FC48"”
Dim buffer As arrRBuffer
mLen = HexToBcd((eppLen0.Text))
If (mLen <= 0 Or Len(eppData0.Text) = 0) Then
MsgBox("请输入要写的数据,长度!", MsgBoxStyle.Exclamation, "USB2ISP DEMO")
Exit Sub
End If
If (mLen > Len(eppData0.Text) \ 2) Then
mLen = Len(eppData0.Text) \ 2
End If
Call mStrtoVal((eppData0.Text), buffer, mLen) '将输入的十六进制格式字符数据转成数值数据
If (mOpen = True) Then
'UPGRADE_WARNING: 未能解析对象 buffer 的默认属性。 单击以获得更多信息:“ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"”
If (USBIO_EppWriteData(mIndex, buffer, mLen) = False) Then
MsgBox("EPP写数据块0失败!", MsgBoxStyle.Exclamation, "USB2ISP DEMO")
End If
eppLen0.Text = Hex(mLen)
Else
MsgBox("设备未打开!", MsgBoxStyle.Exclamation, "USB2ISP DEMO")
End If
End Sub
Private Sub eppWrite1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles eppWrite1.Click
Dim mLen As Integer
'UPGRADE_WARNING: 结构 buffer 中的数组可能需要先初始化才可以使用。 单击以获得更多信息:“ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="814DF224-76BD-4BB4-BFFB-EA359CB9FC48"”
Dim buffer As arrRBuffer
mLen = HexToBcd((eppLen1.Text))
If (mLen <= 0 Or Len(eppData1.Text) = 0) Then
MsgBox("请输入写数据和长度!", MsgBoxStyle.Exclamation, "USB2ISP DEMO")
Exit Sub
End If
If (mLen > Len(eppData1.Text) \ 2) Then
mLen = Len(eppData1.Text) \ 2
End If
Call mStrtoVal((eppData1.Text), buffer, mLen) '将输入的十六进制格式字符数据转成数值数据
If (mOpen = True) Then
'UPGRADE_WARNING: 未能解析对象 buffer 的默认属性。 单击以获得更多信息:“ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"”
If (USBIO_EppWriteAddr(mIndex, buffer, mLen) = False) Then
MsgBox("EPP写数据块1失败!", MsgBoxStyle.Exclamation, "USB2ISP DEMO")
End If
eppLen1.Text = Hex(mLen)
Else
MsgBox("设备未打开!", MsgBoxStyle.Exclamation, "USB2ISP DEMO")
End If
End Sub
Private Sub evtbtrefresh_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles evtbtrefresh.Click
Dim mBuf(0) As Byte
Dim mLen As Integer
If mOpen = True Then
mLen = 1
If (memadd0(0).Checked = True) Then
If (USBIO_MemReadAddr0(mIndex, mBuf(0), mLen) = False) Then
MsgBox("MEM地址方式读拔码开关状态失败! ", MsgBoxStyle.Exclamation, "USB2ISP DEMO")
Exit Sub
End If
ElseIf (memadd1(1).Checked = True) Then
If (USBIO_MemReadAddr1(mIndex, mBuf(0), mLen) = False) Then
MsgBox("MEM地址方式1读拔码开关状态失败! ", MsgBoxStyle.Exclamation, "USB2ISP DEMO")
Exit Sub
End If
End If
'按钮状态显示
If ((mBuf(0) And 1) = 0) Then
swit(0).CheckState = System.Windows.Forms.CheckState.Checked
Else
swit(0).CheckState = System.Windows.Forms.CheckState.Unchecked
End If
If ((mBuf(0) And 2) = 0) Then
swit(1).CheckState = System.Windows.Forms.CheckState.Checked
Else
swit(1).CheckState = System.Windows.Forms.CheckState.Unchecked
End If
If ((mBuf(0) And 4) = 0) Then
swit(2).CheckState = System.Windows.Forms.CheckState.Checked
Else
swit(2).CheckState = System.Windows.Forms.CheckState.Unchecked
End If
If ((mBuf(0) And 8) = 0) Then
swit(3).CheckState = System.Windows.Forms.CheckState.Checked
Else
swit(3).CheckState = System.Windows.Forms.CheckState.Unchecked
End If
If ((mBuf(0) And 16) = 0) Then
swit(4).CheckState = System.Windows.Forms.CheckState.Checked
Else
swit(4).CheckState = System.Windows.Forms.CheckState.Unchecked
End If
If ((mBuf(0) And 32) = 0) Then
swit(5).CheckState = System.Windows.Forms.CheckState.Checked
Else
swit(5).CheckState = System.Windows.Forms.CheckState.Unchecked
End If
If ((mBuf(0) And 64) = 0) Then
swit(6).CheckState = System.Windows.Forms.CheckState.Checked
Else
swit(6).CheckState = System.Windows.Forms.CheckState.Unchecked
End If
If ((mBuf(0) And 128) = 0) Then
swit(7).CheckState = System.Windows.Forms.CheckState.Checked
Else
swit(7).CheckState = System.Windows.Forms.CheckState.Unchecked
End If
Else
MsgBox("设备未打开!", MsgBoxStyle.Exclamation, "USB2ISP DEMO")
End If
End Sub
Private Sub frmMain_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
mIndex = 0
'SSTab1.TabVisible(0) = False
'SSTab1.TabVisible(1) = False
'SSTab1.TabVisible(2) = False
'SSTab1.TabVisible(3) = False
'SSTab1.TabVisible(1) = False
'SSTab1.TabVisible(4) = False
hopen = USBIO_OpenDevice(mIndex)
If (hopen = INVALID_HANDLE_VALUE) Then
mOpen = False
Else
mOpen = True
End If
'设置设备插拔通知
'UPGRADE_WARNING: 为 AddressOf mUSBIO_NOTIFY_ROUTINE 添加委托 单击以获得更多信息:“ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="E9E157F7-EF0C-4016-87B7-7D7FBBC6EE08"”
If USBIO_SetDeviceNotify(mIndex, vbNullString, AddressOf mUSBIO_NOTIFY_ROUTINE) = False Then
MsgBox("设置设备插拔通知失败", MsgBoxStyle.Exclamation, "USB2ISP DEMO")
End If
enablebtn((mOpen))
End Sub
Private Sub frmMain_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
USBIO_SetDeviceNotify(mIndex, vbNullString, 0)
If (mOpen = True) Then
USBIO_CloseDevice((mIndex))
End If
End Sub
'UPGRADE_WARNING: 初始化窗体时可能激发事件 Led.CheckStateChanged。 单击以获得更多信息:“ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"”
Private Sub Led_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Led.CheckStateChanged
Dim Index As Short = Led.GetIndex(eventSender)
Dim mBuf(0) As Byte
Dim mLen As Integer
If (mOpen = True) Then
mLen = 1
mBuf(0) = CByte((Led(0).CheckState * (2 ^ 7)) + (Led(1).CheckState * (2 ^ 6)) + (Led(2).CheckState * (2 ^ 5)) + (Led(3).CheckState * (2 ^ 4)) + (Led(4).CheckState * (2 ^ 3)) + (Led(5).CheckState * (2 ^ 2)) + (Led(6).CheckState * (2 ^ 1)) + (Led(7).CheckState * (2 ^ 0))) '组合按钮键值
If (memadd0(0).Checked = True) Then '地址0
If (USBIO_MemWriteAddr0(mIndex, mBuf(0), mLen) = False) Then
MsgBox("发送LED状态值失败!", MsgBoxStyle.Exclamation, "USB2ISP DEMO")
End If
ElseIf (memadd1(1).Checked = True) Then
If (USBIO_MemWriteAddr1(mIndex, mBuf(0), mLen) = False) Then
MsgBox("发送LED状态值失败!", MsgBoxStyle.Exclamation, "USB2ISP DEMO")
End If
End If
Else
MsgBox("设备未打开!", MsgBoxStyle.Exclamation, "USB2ISP DEMO")
End If
End Sub
Private Sub memRead0_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles memRead0.Click
Dim mLen As Integer
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -