重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
思路错误,应该是先制作好仪表盘图片,指针图片,使用代码来切换图片
创新互联致力于互联网品牌建设与网络营销,包括网站设计制作、做网站、SEO优化、网络推广、整站优化营销策划推广、电子商务、移动互联网营销等。创新互联为不同类型的客户提供良好的互联网应用定制及解决方案,创新互联核心团队十多年专注互联网开发,积累了丰富的网站经验,为广大企业客户提供一站式企业网站建设服务,在网站建设行业内树立了良好口碑。
代码未考虑校验和:
Option Explicit
Dim strdata As String
Dim bytInput() As Byte
Dim sj(1) As Double
Dim sjData(1) As String
Dim xswz As Integer
Dim xswz1 As Integer
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub MsComm1_OnComm()
Dim intInputLen As Integer
Select Case MSComm1.CommEvent
Case comEvReceive
'接收代码
While MSComm1.InBufferCount
intInputLen = MSComm1.InBufferCount
ReDim bytInput(intInputLen)
bytInput = MSComm1.Input
jieshou
'数据处理
If Mid(strdata, 1, 2) = "AA" And Len(strdata) = 32 Then
Dim j As Integer
Dim binsj As Integer
'For j = 1 To Len(strdata) - 2 Step 2
'binsj = binsj + Val("H" Mid(strdata, j, 2))
'Next
'Print Hex(binsj Mod 256)
Text1 = strdata
xswz = Val("H" Mid(strdata, 15, 2))
xswz1 = Val("H" Mid(strdata, 29, 2))
sj(0) = Val(Mid(strdata, 5, 10)) / (10 ^ xswz)
sj(1) = Val(Mid(strdata, 19, 10)) / (10 ^ xswz1)
sjData(0) = Format(sj(0), "0.0000000")
sjData(1) = Format(sj(1), "0.0000000")
If Mid(strdata, 4, 1) = "0" Then
Text2 = sjData(0)
Else
Text2 = "-" sjData(0)
End If
If Mid(strdata, 18, 1) = "0" Then
Text3 = sjData(1)
Else
Text3 = "-" sjData(1)
End If
Timer1.Enabled = False
strdata = ""
ElseIf Mid(strdata, 1, 2) "AA" Then
strdata = ""
End If
Wend
End Select
End Sub
Public Function jieshou() '接收数据处理为16进制
Dim i As Integer
For i = 0 To UBound(bytInput)
If Len(Hex(bytInput(i))) = 1 Then
strdata = strdata "0" Hex(bytInput(i))
Else
strdata = strdata Hex(bytInput(i))
End If
Next
End Function
Private Sub Form_Load()
MSComm1.Settings = "2400,n,8,1"
MSComm1.CommPort = 1
MSComm1.InputMode = comInputModeBinary
MSComm1.RThreshold = 1
MSComm1.SThreshold = 0
MSComm1.PortOpen = True
Timer1 = 200
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
Dim send(0) As Byte
send(0) = H55
MSComm1.Output = send
End Sub
你把问题想简单点,直接在PANEL空间上使用GD+画指针就行了。算出两点划线还不容易么?用图片的话需要旋转,而且锯齿非常严重@!
如果使用串口通信,可以使用com控件,对串口进行读写操作。关键是要有和仪表通信的接口,另外还要把仪表的数字量信息读上来。可能还要进行A/D转换。