📄 www2.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form3
Caption = "data"
ClientHeight = 4380
ClientLeft = 4425
ClientTop = 3120
ClientWidth = 7680
LinkTopic = "Form3"
MDIChild = -1 'True
ScaleHeight = 4380
ScaleWidth = 7680
WindowState = 2 'Maximized
Begin VB.TextBox Text6
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 4200
MaxLength = 2
TabIndex = 9
Top = 1920
Width = 735
End
Begin VB.TextBox Text5
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 3360
MaxLength = 2
TabIndex = 8
Top = 1920
Width = 735
End
Begin VB.TextBox Text4
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 2520
MaxLength = 2
TabIndex = 7
Top = 1920
Width = 735
End
Begin VB.TextBox Text3
Height = 1575
Left = 1800
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 17
TabStop = 0 'False
Top = 2520
Width = 3135
End
Begin MSCommLib.MSComm MSComm1
Left = 6600
Top = 2640
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
End
Begin VB.CommandButton Command2
Caption = "返回"
Height = 495
Left = 5280
TabIndex = 11
Top = 2760
Width = 1215
End
Begin VB.ComboBox Combo4
Height = 300
ItemData = "www2.frx":0000
Left = 3840
List = "www2.frx":000A
TabIndex = 5
Text = "自动"
Top = 1200
Width = 1215
End
Begin VB.TextBox Text2
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 1800
MaxLength = 2
TabIndex = 6
Top = 1920
Width = 615
End
Begin VB.CommandButton Command1
Caption = "写"
Height = 495
Left = 5280
TabIndex = 10
Top = 1920
Width = 1215
End
Begin VB.ComboBox Combo3
Height = 300
ItemData = "www2.frx":001A
Left = 5280
List = "www2.frx":0024
TabIndex = 2
Text = "write"
Top = 480
Width = 1215
End
Begin VB.ComboBox Combo2
Height = 300
ItemData = "www2.frx":0035
Left = 3240
List = "www2.frx":0051
TabIndex = 1
Text = "1"
Top = 480
Width = 1215
End
Begin VB.ComboBox Combo1
Height = 300
ItemData = "www2.frx":006D
Left = 960
List = "www2.frx":007A
TabIndex = 0
Text = "1"
Top = 480
Width = 1215
End
Begin VB.TextBox Text1
Height = 270
Left = 2400
MaxLength = 3
TabIndex = 4
Top = 1200
Width = 615
End
Begin VB.Label Label7
Caption = "数据显示:"
Height = 255
Left = 720
TabIndex = 18
Top = 2640
Width = 975
End
Begin VB.Label Label6
Caption = "数据输入:"
Height = 255
Left = 720
TabIndex = 16
Top = 2040
Width = 975
End
Begin VB.Label Label5
Caption = "个数据"
Height = 255
Left = 3000
TabIndex = 15
Top = 1200
Width = 615
End
Begin VB.Label Label4
Caption = "选择第"
Height = 255
Left = 1800
TabIndex = 14
Top = 1200
Width = 615
End
Begin VB.Label Label3
Caption = "读写:"
Height = 255
Left = 4560
TabIndex = 13
Top = 480
Width = 615
End
Begin VB.Label Label2
Caption = "PORT:"
Height = 255
Left = 2520
TabIndex = 12
Top = 480
Width = 495
End
Begin VB.Label Label1
Caption = "FPGA:"
Height = 255
Left = 360
TabIndex = 3
Top = 480
Width = 495
End
End
Attribute VB_Name = "Form3"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Option Base 1
Dim sent() As Byte '接收var中的值
Dim oleExcel As Object
Dim a As Integer, coordinate As Integer, data As String '定义坐标
Private Sub Combo3_Click()
If Combo3.ListIndex = 1 Then
Command1.Caption = "读"
Else
Command1.Caption = "写"
End If
End Sub
Private Sub Combo4_Click()
If Combo4.ListIndex = 1 Then
Text1.Enabled = True
Else
' Text1.Enabled = False
End If
End Sub
Private Sub Command1_Click()
Dim i As Integer, s As String
If Command1.Caption = "写" Then
If Val(Text1.Text) > 255 Then
MsgBox "输入范围溢出", 48, "提示"
Text1.SetFocus
Exit Sub
End If
s = Text2.Text & Text4.Text & Text5.Text & Text6.Text
If Len(s) < 8 Then
MsgBox "请输入完整8位数据", 48, "提示"
Text2.SetFocus
Exit Sub
End If
Else
s = "00000000"
End If
If Not MSComm1.PortOpen Then
MSComm1.PortOpen = True '打开通信端口
End If
MSComm1.Output = "d"
MSComm1.OutBufferCount = 0
ReDim sent(7)
sent(1) = Combo1.Text
sent(2) = Combo2.Text
If Combo3.ListIndex = 1 Then
sent(3) = 2
Else
sent(3) = 1
End If
If Combo4.ListIndex = 1 Then
sent(4) = 2
' Text1.Enabled = True
Else
sent(4) = 1
Text1.Enabled = False
End If
If Len(Text1) < 3 Then
Text1.Text = String(3 - Len(Text1), "0") & Text1.Text
End If
For i = 5 To 7
sent(i) = Asc(Mid(Text1.Text, i - 4, 1))
Next i
MSComm1.Output = sent
MSComm1.OutBufferCount = 0
ReDim sent(9)
For i = 1 To 8
sent(i) = Asc(Mid(UCase(s), i, 1))
Next i
sent(9) = Asc(vbCrLf)
MSComm1.Output = sent
MSComm1.OutBufferCount = 0
End Sub
Private Sub Command2_Click()
Call Form_Unload(27)
End Sub
Private Sub Form_Load()
Static comnum As Integer
comnum = InputBox("请输入串口号", "", "1")
With MSComm1
.CommPort = comnum '设置Com2为通信端口
.Settings = "9600,N,8,1" '设置通信端口参数 9600赫兹、无校验、8个数据位、1个停止位.(这里需要进一步说明的是:.Setting=”BBBB,P,D,S”。
'含义是:B:Baud Rate(波特率);P:Parity(奇偶);D:Data Bit;S:Stop Bit)
.InBufferSize = 1024 '设置缓冲区接收数据为1024字节
.OutBufferSize = 512
.InputMode = comInputModeText '设置数据接收模式为16进制形式
.InputLen = 1 '设置Input一次从接收缓冲读取字节数为1
.RThreshold = 1 '设置接收一个字节就产生OnComm事件
.OutBufferCount = 0 '清空发送缓冲区
.InBufferCount = 0 '滑空接收缓冲
.OutBufferCount = 0 '清空发送缓冲区
.InBufferCount = 0 '滑空接收缓冲区
End With
End Sub
Private Sub MSComm1_OnComm()
' DelayTime ‘用来延续时间
Static j As Integer
Dim b As String
b = CStr(MSComm1.Input)
If b = Chr(13) Then
Text3.Text = Text3.Text & vbCrLf
j = 0
If Command1.Caption = "读" Then Call inputxls
coordinate = 0
data = ""
Else:
If b = ":" Then j = j + 1
If j = 0 Then
coordinate = coordinate * 10 + Val(b)
ElseIf j = 1 Then
j = j + 1
ElseIf j = 2 Then
data = data & b
End If
Text3.Text = Text3.Text & b
End If
End Sub
Private Sub inputxls()
'Print coordinate
Dim i, j, X, Y As Integer
Set oleExcel = CreateObject("Excel.Application")
oleExcel.Visible = False
oleExcel.WindowState = 1
' 打开文件
oleExcel.Workbooks.Open FileName:=App.Path & "\data.xls"
X = Int(coordinate / 1024) - 1
Y = Int((coordinate Mod 1024) / 4) + 1
oleExcel.Worksheets("sheet1").Cells(Y + 1, X * 3 - 1) = data
oleExcel.ActiveWorkbook.Save
oleExcel.ActiveWorkbook.Close
oleExcel.Quit
End Sub
Private Sub Form_Unload(Cancel As Integer)
Form1.Show
Form1.Enabled = True
If MSComm1.PortOpen Then
MSComm1.PortOpen = False '打开通信端口
End If
Unload Form3
'End
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 8 Then
KeyAscii = 8
ElseIf KeyAscii < 48 Or KeyAscii > 57 Then
KeyAscii = 0
End If
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
Dim i As Integer
If KeyAscii = 8 Then
KeyAscii = 8
ElseIf KeyAscii < 48 Or (KeyAscii > 57 And KeyAscii < 65) Or (KeyAscii > 70 And KeyAscii < 97) Or KeyAscii > 102 Then
KeyAscii = 0
ElseIf Len(Text2.Text) = 1 Then
Text4.SetFocus
End If
End Sub
Private Sub Text4_KeyPress(KeyAscii As Integer)
Dim i As Integer
If KeyAscii = 8 Then
KeyAscii = 8
If Len(Text4) = 0 Then Text2.SetFocus
ElseIf KeyAscii < 48 Or (KeyAscii > 57 And KeyAscii < 65) Or (KeyAscii > 70 And KeyAscii < 97) Or KeyAscii > 102 Then
KeyAscii = 0
ElseIf Len(Text4.Text) = 1 Then
Text5.SetFocus
End If
End Sub
Private Sub Text5_KeyPress(KeyAscii As Integer)
Dim i As Integer
If KeyAscii = 8 Then
KeyAscii = 8
If Len(Text5) = 0 Then Text4.SetFocus
ElseIf KeyAscii < 48 Or (KeyAscii > 57 And KeyAscii < 65) Or (KeyAscii > 70 And KeyAscii < 97) Or KeyAscii > 102 Then
KeyAscii = 0
ElseIf Len(Text5.Text) = 1 Then
Text6.SetFocus
End If
End Sub
Private Sub Text6_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
KeyAscii = 0
Call Command1_Click
End If
If KeyAscii = 8 Then
KeyAscii = 8
If Len(Text6) = 0 Then Text5.SetFocus
ElseIf KeyAscii < 48 Or (KeyAscii > 57 And KeyAscii < 65) Or (KeyAscii > 70 And KeyAscii < 97) Or KeyAscii > 102 Then
KeyAscii = 0
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -