Form1.frm
资源名称:VBTest.rar [点击查看]
上传用户:hbj111
上传日期:2022-07-30
资源大小:107k
文件大小:9k
源码类别:
串口编程
开发平台:
Visual Basic
- VERSION 5.00
- Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
- Begin VB.Form frmMain
- Caption = "东方数码技术有限公司"
- ClientHeight = 9165
- ClientLeft = 165
- ClientTop = 735
- ClientWidth = 8640
- LinkTopic = "Form1"
- ScaleHeight = 9165
- ScaleWidth = 8640
- StartUpPosition = 3 '窗口缺省
- Begin VB.CheckBox chkStopShow
- Caption = "停止显示"
- Height = 375
- Left = 5640
- TabIndex = 16
- Top = 6960
- Width = 1335
- End
- Begin VB.Timer Timer1
- Left = 7440
- Top = 3600
- End
- Begin VB.CommandButton cmdClearRxData
- Caption = "清空接收数据"
- Height = 375
- Left = 5640
- TabIndex = 15
- Top = 6480
- Width = 1335
- End
- Begin VB.CommandButton cmdClearCount
- Caption = "清除计数"
- Height = 375
- Left = 5640
- TabIndex = 14
- Top = 5160
- Width = 1335
- End
- Begin VB.TextBox txtRxData
- Height = 3255
- Left = 120
- MultiLine = -1 'True
- ScrollBars = 2 'Vertical
- TabIndex = 9
- Top = 5760
- Width = 5415
- End
- Begin VB.CommandButton cmdSend
- Caption = "手工发送"
- Height = 375
- Left = 5640
- TabIndex = 7
- Top = 3240
- Width = 1215
- End
- Begin VB.TextBox txtTimer
- Height = 270
- Left = 6120
- TabIndex = 5
- Text = "1000"
- Top = 2880
- Width = 975
- End
- Begin VB.CheckBox chkAutoSend
- Caption = "自动发送"
- Height = 255
- Left = 5640
- TabIndex = 3
- Top = 2400
- Width = 1815
- End
- Begin VB.TextBox txtTxData
- Height = 2655
- Left = 120
- MultiLine = -1 'True
- ScrollBars = 2 'Vertical
- TabIndex = 2
- Top = 2280
- Width = 5415
- End
- Begin MSComctlLib.ListView ListView1
- Height = 1575
- Left = 120
- TabIndex = 0
- Top = 120
- Width = 7815
- _ExtentX = 13785
- _ExtentY = 2778
- View = 3
- LabelWrap = 0 'False
- HideSelection = 0 'False
- FullRowSelect = -1 'True
- HotTracking = -1 'True
- _Version = 393217
- ForeColor = -2147483640
- BackColor = -2147483643
- BorderStyle = 1
- Appearance = 1
- NumItems = 5
- BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628}
- Key = "ConnectID"
- Text = "ConnectID"
- Object.Width = 2540
- EndProperty
- BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-00C0F0283628}
- SubItemIndex = 1
- Key = "mac"
- Text = "C2000 MAC地址"
- Object.Width = 2540
- EndProperty
- BeginProperty ColumnHeader(3) {BDD1F052-858B-11D1-B16A-00C0F0283628}
- SubItemIndex = 2
- Key = "PeerIP"
- Text = "对方IP地址"
- Object.Width = 2540
- EndProperty
- BeginProperty ColumnHeader(4) {BDD1F052-858B-11D1-B16A-00C0F0283628}
- SubItemIndex = 3
- Key = "PeerPort"
- Text = "对方端口"
- Object.Width = 2540
- EndProperty
- BeginProperty ColumnHeader(5) {BDD1F052-858B-11D1-B16A-00C0F0283628}
- SubItemIndex = 4
- Key = "model"
- Text = "型号"
- Object.Width = 2540
- EndProperty
- End
- Begin VB.Label lblRxCount
- Alignment = 1 'Right Justify
- Caption = "0"
- Height = 255
- Left = 2880
- TabIndex = 13
- Top = 5040
- Width = 1215
- End
- Begin VB.Label lblTxCount
- Alignment = 1 'Right Justify
- Caption = "0"
- Height = 255
- Left = 840
- TabIndex = 12
- Top = 5040
- Width = 1215
- End
- Begin VB.Label Label6
- Caption = "RX:"
- Height = 255
- Left = 2520
- TabIndex = 11
- Top = 5040
- Width = 375
- End
- Begin VB.Label Label5
- Caption = "TX:"
- Height = 255
- Left = 360
- TabIndex = 10
- Top = 5040
- Width = 375
- End
- Begin VB.Label Label4
- Caption = "接收数据:"
- Height = 255
- Left = 240
- TabIndex = 8
- Top = 5400
- Width = 1215
- End
- Begin VB.Label Label3
- Caption = "ms"
- Height = 255
- Left = 7200
- TabIndex = 6
- Top = 2880
- Width = 255
- End
- Begin VB.Label Label2
- Caption = "间隔:"
- Height = 255
- Left = 5640
- TabIndex = 4
- Top = 2880
- Width = 615
- End
- Begin VB.Label Label1
- Caption = "发送数据:"
- Height = 255
- Left = 240
- TabIndex = 1
- Top = 1920
- Width = 1095
- End
- Begin VB.Menu mnuNetwork
- Caption = "网络"
- Begin VB.Menu mnuListen
- Caption = "开始监听..."
- End
- Begin VB.Menu mnuStopListen
- Caption = "停止监听"
- End
- Begin VB.Menu mnuConnect
- Caption = "连接..."
- End
- Begin VB.Menu mnuCloseConnect
- Caption = "关闭连接"
- End
- Begin VB.Menu mnuUseSocket
- Caption = "使用透明Socket"
- End
- Begin VB.Menu mnuSep
- Caption = "-"
- End
- Begin VB.Menu mnuExit
- Caption = "退出"
- End
- End
- End
- Attribute VB_Name = "frmMain"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Private Sub chkAutoSend_Click()
- g_bAutoSend = Not g_bAutoSend
- If g_bAutoSend Then
- txtTimer.Enabled = False
- cmdSend.Enabled = False
- Timer1.Interval = CLng(txtTimer.Text)
- g_AutoSendConnectID = g_SendConnectID
- Else
- txtTimer.Enabled = True
- cmdSend.Enabled = True
- Timer1.Interval = 0
- g_AutoSendConnectID = 0
- End If
- End Sub
- Private Sub cmdClearCount_Click()
- g_lngTxCount = 0
- g_lngRxCount = 0
- lblTxCount.Caption = CStr(g_lngTxCount)
- lblRxCount.Caption = CStr(g_lngRxCount)
- End Sub
- Private Sub cmdClearRxData_Click()
- txtRxData.Text = ""
- End Sub
- Private Sub cmdSend_Click()
- Send g_SendConnectID
- End Sub
- Private Sub Form_Load()
- Dim lRet As Long
- g_AutoSendConnectID = 0
- g_bAutoSend = False
- g_SendConnectID = 0
- g_IsSocket = 0
- g_lngTxCount = 0
- g_lngRxCount = 0
- SetSocket g_IsSocket
- lRet = SetCallback(AddressOf OnAccept, AddressOf OnConnectClose, 0, 0, AddressOf OnReceFromCOM, 0)
- End Sub
- Private Sub Form_Unload(Cancel As Integer)
- StopListen
- CloseAllConnect
- End Sub
- Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem)
- g_SendConnectID = CLng(Item.Tag)
- End Sub
- Private Sub mnuCloseConnect_Click()
- If g_SendConnectID <> 0 Then
- CloseConnect g_SendConnectID
- End If
- End Sub
- Private Sub mnuConnect_Click()
- dlgAddr.Show vbModal
- If dlgAddr.Tag = "1" Then
- OpenConnect CStr(dlgAddr.txtIP), CLng(dlgAddr.txtPort), "0.0.0.0", 0
- End If
- End Sub
- Private Sub mnuExit_Click()
- Unload Me
- End Sub
- Private Sub mnuListen_Click()
- dlgAddr.txtIP.Text = "0.0.0.0"
- dlgAddr.txtPort.Text = "8000"
- dlgAddr.Show vbModal
- If dlgAddr.Tag = "1" Then
- StartListen dlgAddr.txtIP, CLng(dlgAddr.txtPort)
- End If
- End Sub
- Private Sub mnuStopListen_Click()
- StopListen
- End Sub
- Private Sub mnuUseSocket_Click()
- g_IsSocket = Not g_IsSocket
- SetSocket g_IsSocket
- End Sub
- Private Sub Timer1_Timer()
- Send g_AutoSendConnectID
- End Sub