思路錯(cuò)誤,應(yīng)該是先制作好儀表盤(pán)圖片,指針圖片,使用代碼來(lái)切換圖片
創(chuàng)新互聯(lián)致力于互聯(lián)網(wǎng)品牌建設(shè)與網(wǎng)絡(luò)營(yíng)銷,包括網(wǎng)站設(shè)計(jì)制作、做網(wǎng)站、SEO優(yōu)化、網(wǎng)絡(luò)推廣、整站優(yōu)化營(yíng)銷策劃推廣、電子商務(wù)、移動(dòng)互聯(lián)網(wǎng)營(yíng)銷等。創(chuàng)新互聯(lián)為不同類型的客戶提供良好的互聯(lián)網(wǎng)應(yīng)用定制及解決方案,創(chuàng)新互聯(lián)核心團(tuán)隊(duì)十多年專注互聯(lián)網(wǎng)開(kāi)發(fā),積累了豐富的網(wǎng)站經(jīng)驗(yàn),為廣大企業(yè)客戶提供一站式企業(yè)網(wǎng)站建設(shè)服務(wù),在網(wǎng)站建設(shè)行業(yè)內(nèi)樹(shù)立了良好口碑。
代碼未考慮校驗(yàn)和:
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
'數(shù)據(jù)處理
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() '接收數(shù)據(jù)處理為16進(jìn)制
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
你把問(wèn)題想簡(jiǎn)單點(diǎn),直接在PANEL空間上使用GD+畫(huà)指針就行了。算出兩點(diǎn)劃線還不容易么?用圖片的話需要旋轉(zhuǎn),而且鋸齒非常嚴(yán)重@!
如果使用串口通信,可以使用com控件,對(duì)串口進(jìn)行讀寫(xiě)操作。關(guān)鍵是要有和儀表通信的接口,另外還要把儀表的數(shù)字量信息讀上來(lái)??赡苓€要進(jìn)行A/D轉(zhuǎn)換。