📄 form1.vb
字号:
Imports System.Runtime.InteropServices
Public Class Form1
Inherits System.Windows.Forms.Form
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Timer1 As System.Windows.Forms.Timer
Dim x, y, z As Int32
Dim h(8) As Integer
Dim a, times As Int16
Dim rGPBCON As New IntPtr(&H91600010)
Dim rGPBDAT As New IntPtr(&H91600014)
Dim rGPBUP As New IntPtr(&H91600018)
Dim rGPECON As New IntPtr(&H91600040)
Dim rGPEDAT As New IntPtr(&H91600044)
Dim rGPEUP As New IntPtr(&H91600048)
Dim m As Integer
Dim temp As Integer
Dim gz As Integer
Dim tempC As Integer
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
Friend WithEvents TextBox4 As System.Windows.Forms.TextBox
Friend WithEvents TextBox5 As System.Windows.Forms.TextBox
Friend WithEvents TextBox6 As System.Windows.Forms.TextBox
Friend WithEvents TextBox7 As System.Windows.Forms.TextBox
Friend WithEvents TextBox8 As System.Windows.Forms.TextBox
Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Button1 = New System.Windows.Forms.Button
Me.Timer1 = New System.Windows.Forms.Timer
Me.Button2 = New System.Windows.Forms.Button
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.TextBox3 = New System.Windows.Forms.TextBox
Me.TextBox4 = New System.Windows.Forms.TextBox
Me.TextBox5 = New System.Windows.Forms.TextBox
Me.TextBox6 = New System.Windows.Forms.TextBox
Me.TextBox7 = New System.Windows.Forms.TextBox
Me.TextBox8 = New System.Windows.Forms.TextBox
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(24, 112)
Me.TextBox1.Size = New System.Drawing.Size(56, 21)
Me.TextBox1.Text = ""
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(184, 224)
Me.Button1.Size = New System.Drawing.Size(168, 48)
Me.Button1.Text = "Button1"
'
'Timer1
'
Me.Timer1.Interval = 2000
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(176, 32)
Me.Button2.Size = New System.Drawing.Size(168, 48)
Me.Button2.Text = "BB"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(96, 112)
Me.TextBox2.Size = New System.Drawing.Size(64, 21)
Me.TextBox2.Text = ""
'
'TextBox3
'
Me.TextBox3.Location = New System.Drawing.Point(176, 112)
Me.TextBox3.Size = New System.Drawing.Size(56, 21)
Me.TextBox3.Text = ""
'
'TextBox4
'
Me.TextBox4.Location = New System.Drawing.Point(256, 112)
Me.TextBox4.Size = New System.Drawing.Size(64, 21)
Me.TextBox4.Text = ""
'
'TextBox5
'
Me.TextBox5.Location = New System.Drawing.Point(336, 112)
Me.TextBox5.Size = New System.Drawing.Size(64, 21)
Me.TextBox5.Text = ""
'
'TextBox6
'
Me.TextBox6.Location = New System.Drawing.Point(424, 112)
Me.TextBox6.Size = New System.Drawing.Size(48, 21)
Me.TextBox6.Text = ""
'
'TextBox7
'
Me.TextBox7.Location = New System.Drawing.Point(488, 112)
Me.TextBox7.Size = New System.Drawing.Size(56, 21)
Me.TextBox7.Text = ""
'
'TextBox8
'
Me.TextBox8.Location = New System.Drawing.Point(552, 112)
Me.TextBox8.Size = New System.Drawing.Size(64, 21)
Me.TextBox8.Text = ""
'
'Form1
'
Me.Controls.Add(Me.TextBox8)
Me.Controls.Add(Me.TextBox7)
Me.Controls.Add(Me.TextBox6)
Me.Controls.Add(Me.TextBox5)
Me.Controls.Add(Me.TextBox4)
Me.Controls.Add(Me.TextBox3)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox1)
Me.Text = "Form1"
End Sub
Public Shared Sub Main()
Application.Run(New Form1)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = True
a = 0
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
tempC += 1
Timer1.Enabled = False
adc(a)
Button2.Text = "当前通道:" & a & " 总计次数:" & tempC
Select Case a
Case 0
h(a) = (z - 820) * 475 / 3276
If z > 3370 Then gz = gz + 1
If z < 3350 Then gz = gz + 1
'TextBox1.Text = h(a)
TextBox1.Text = z
Case 1
h(a) = (z - 820) * 475 / 3276
If z > 1482 Then gz = gz + 1
If z < 1462 Then gz = gz + 1
'TextBox2.Text = h(a)
TextBox2.Text = z
Case 2
h(a) = (z - 820) * 475 / 3276
If z > 5 Then gz = gz + 1
'TextBox3.Text = h(a)
TextBox3.Text = z
Case 3
h(a) = (z - 820) * 475 / 3276
If z > 5 Then gz = gz + 1
'TextBox4.Text = h(a)
TextBox4.Text = z
Case 4
h(a) = (z - 820) * 475 / 3276
If z > 5 Then gz = gz + 1
'TextBox5.Text = h(a)
TextBox5.Text = z
Case 5
h(a) = (z - 820) * 475 / 3276
If z > 5 Then gz = gz + 1
'TextBox6.Text = h(a)
TextBox6.Text = z
Case 6
h(a) = (z - 820) * 475 / 3276
If z > 5 Then gz = gz + 1
'TextBox7.Text = h(a)
TextBox7.Text = z
Case 7
h(a) = (z - 820) * 475 / 3276
If z > 5 Then gz = gz + 1
'TextBox8.Text = h(a)
TextBox8.Text = z
End Select
a += 1
If a = 8 Then a = 0
'Button2.Text = z
Timer1.Enabled = True
Button1.Text = "出错次数" & gz
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = False
a = 0
End Sub
Private Sub adc(ByVal i As Integer)
x = y = z = 0
temp = &H40 + i
Marshal.WriteInt32(rGPBCON, 0, &H5555) '配置GPB0,1,2,3,4,5,6,7...为输出
Marshal.WriteInt32(rGPBUP, 0, &H0) '全部上拉
Marshal.WriteInt32(rGPECON, 0, &H55555555) '配置GPE0,1,2,3,4,5,6,7...为输出
Marshal.WriteInt32(rGPEUP, 0, &H0) '全部上拉
Marshal.WriteInt32(rGPEDAT, 0, &HFFFF)
For m = 0 To 50
Next
Marshal.WriteInt32(rGPEDAT, 0, &H9000)
For m = 0 To 50
Next
Marshal.WriteInt32(rGPBDAT, 0, temp)
For m = 0 To 200
Next
Marshal.WriteInt32(rGPEDAT, 0, &HFFFF)
For m = 0 To 50
Next
System.Threading.Thread.Sleep(500) '线程阻塞400ms
Marshal.WriteInt32(rGPBCON, 0, &H0) '配置GPB0,1,2,3,4,5,6,7...为输入
Marshal.WriteInt32(rGPBUP, 0, &H0) '全部上拉
Marshal.WriteInt32(rGPEDAT, 0, &HFFFF)
For m = 0 To 50
Next
Marshal.WriteInt32(rGPEDAT, 0, &H5000)
For m = 0 To 100
Next
x = Marshal.ReadInt32(rGPBDAT, 0)
x = x And &HF
For m = 0 To 100
Next
Marshal.WriteInt32(rGPEDAT, 0, &HFFFF)
For m = 0 To 100
Next
System.Threading.Thread.Sleep(500)
Marshal.WriteInt32(rGPEDAT, 0, &HFFFF)
For m = 0 To 50
Next
Marshal.WriteInt32(rGPEDAT, 0, &H4000)
For m = 0 To 100
Next
y = Marshal.ReadInt32(rGPBDAT, 0)
y = y And &HFF
For m = 0 To 200
Next
Marshal.WriteInt32(rGPEDAT, 0, &HFFFF)
For m = 0 To 200
Next
z = x * 256 + y 'AD转换结果
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -