vb上位机界面如何 实现监控多台下位机

vb上位机界面如何 实现监控多台下位机,第1张

mscom的com口通信和usb通信都会随着传输距离加长减弱信号的,传输距离超过两米效果就差了。

建扮基议你用vb6里的Winsock控件可以实现一台电脑控制下位多台电脑,传输协议有两种旁梁都挺简单的UDP协议和TCP协议运缺运。只要用一个交换机或者集线器再加上网线把这些电脑连接到一起即可。

Winsock控件安装好vb后,在c:\windows\system32文件夹内,叫mswinsck.ocx,把它添加到工具条就可以用了。

在VB6里拽一个Winsock控件到Form上,按F1就可以显示它的使用方法和代码示范例子。

以记事本为例

Public Class Form1

Public Sub ShellAndWait(ByVal ProcessPath As String)

Dim objProcess As System.Diagnostics.Process

Try

objProcess = New System.Diagnostics.Process()

objProcess.StartInfo.FileName = ProcessPath

objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal

objProcess.Start()

objProcess.WaitForExit()

objProcess.Close()

Catch

MessageBox.Show("无法执行文件 " &ProcessPath, "错误")

End Try

End Sub

'监视程序悄好拦就可以了,若果监视别的窗体的话,用SPY++ 找到句柄,配合FindWindowEx,SendMessage根启胡据其属性做

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

ShellAndWait("Notepad.exe")

MessageBox.Show("笔记本被关袜液闭后我才会出现")

End Sub

End Class

窗体代码:Private Sub Form_Load()

Do: CL.Add 0: Loop While CL.Count <100

Set DRW.PictureBox = PIC1

Set DRW.DataCollection = CL

DRW.PicBackground = vbBlack

DRW.PicForeground = vbGreen

DRW.BorderColor = vbRed

DRW.BorderSize = 0

DRW.GridColor = &H808000

DRW.GridVisible = True

LastMoment = Now

LastLogged = Now

LoggingInterval = 60

Set m_objIpHelper = New CIpHelper

Dim a As Long

For a = 1 To m_objIpHelper.Interfaces.Count

cboConnectionType.AddItem m_objIpHelper.Interfaces(a).InterfaceDescription &" "

Next

If Val(GetSetting(App.Title, "Setting", "Connection", 0)) + 1 <= cboConnectionType.ListCount Then

cboConnectionType.ListIndex = Val(GetSetting(App.Title, "Setting", "Connection", 0))

Else

cboConnectionType.ListIndex = 0

End If

End SubPrivate Sub Timer1_Timer()

If DownloadSpeedTop <>0 Then

DownloadSpeedTop = 0

UploadSpeedTop = 0

Else

Timer1.Enabled = False

End If

End SubPrivate Sub tmrUpdate_Timer()

On Error Resume Next'If DateDiff("s", LastMoment, Now) <1 Then Exit SubtmrUpdate.Enabled = False

Dim objInterface As CInterface

Set objInterface = m_objIpHelper.Interfaces(cboConnectionType.ListIndex + 1)lblType = m_objIpHelper.Interfaces(cboConnectionType.ListIndex + 1).InterfaceDescription &" "Dim BytesRecv As Long, BytesSent As Long

BytesRecv = m_objIpHelper.BytesReceived

BytesSent = m_objIpHelper.BytesSentDoEvents

Dim DS As Long, US As Long

DS = BytesRecv - LastRecvBytes

US = BytesSent - LastSentBytes

If DownloadSpeedTop <DS Then DownloadSpeedTop = DS

If UploadSpeedTop <US Then UploadSpeedTop = US

DoEventslblRecv.Caption = Format(BytesRecv / 1024, "###,###,###,###,##0 KB")

lblSent.Caption = Format(BytesSent / 1024, "###,###,###,###,##0 KB")DownloadSpeedAverage = (DownloadSpeedAverage + DS) / 2

UploadSpeedAverage = (UploadSpeedAverage + US) / 2

lblDownloadSpeedTop = "下载速率: " &Format(DownloadSpeedTop / 1024, "###,###,###,###,#0.#0 Kb/S")

lblUploadSpeedTop = "上载速率: " &Format(UploadSpeedTop / 1024, "###,###,###,###,#0.#0 Kb/S")

lblDownloadSpeedAverage = "平均下载速率: " &Format(DownloadSpeedAverage / 1024, "###,###,###,###,#0.#0 Kb/S")

lblUploadSpeedAverage = "平均上载速率: " &Format(UploadSpeedAverage / 1024, "###,###,###,###,#0.#0 Kb/S")'Me.Caption = lblDownloadSpeedTop.Caption &vbNewLine &_

lblUploadSpeedTop.Caption &vbNewLine &_

lblDownloadSpeedAverage.Caption &vbNewLine &_

lblUploadSpeedAverage.Caption

CL.Add Int(Format(DownloadSpeedAverage / 1024, "###,###,###,###,#0.#0")) + 5

DRW.DrawIf DS / 1024 <1 Then

lblDSpeed = Format(DS, "0 BS ")

Else

lblDSpeed = Format(DS / 1024, "0.#0 KBS ")

End If

If US / 1024 <1 Then

lblUSpeed = Format(US, "0 BS ")

Else

lblUSpeed = Format(US / 1024, "0.#0 KBS ")

End IfLastRecvBytes = BytesRecv

LastSentBytes = BytesSent

LastMoment = NowIf m_objIpHelper.Interfaces.Count <>cboConnectionType.ListCount Then

Dim a As Long

cboConnectionType.Clear

For a = 1 To m_objIpHelper.Interfaces.Count

cboConnectionType.AddItem m_objIpHelper.Interfaces(a).InterfaceDescription &" "

Next

If Val(GetSetting(App.Title, "Setting", "Connection", 0)) + 1 <= cboConnectionType.ListCount Then

cboConnectionType.ListIndex = Val(GetSetting(App.Title, "Setting", "Connection", 0))

Else

cboConnectionType.ListIndex = 0

End If

End If

tmrUpdate.Enabled = True

End Sub还有些类模块 你加我QQ发给你 这个字数限制了的


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12450986.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存