第一范文网 - 专业文章范例文档资料分享平台

VB串口通信程序代码

来源:用户分享 时间:2025/5/25 1:54:40 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

Err: End Sub

'===============CRC校验子程序===================== Public Function CRC(Brr() As Byte) As Long Dim i As Integer, j As Integer Dim TempVal As Long Dim YWval As Long Dim LSB As Integer

TempVal = &HFFFF&

For i = 0 To UBound(Brr()) TempVal = TempVal Xor Brr(i) For j = 1 To 8

YWval = Int(TempVal / 2) LSB = TempVal Mod 2 If LSB = 1 Then

YWval = YWval Xor &HA001& End If

TempVal = YWval Next j Next i

CRC = TempVal Mod 65536 End Function

扩展的曲线图程序

数据可保存于数据库也可保存于文本文件,各自实现代码不同. 使用TIMER控件定时保存数据代码: Private Sub Timer3_Timer()

If Label5.Caption <> CStr(Time$) Then Label5.Caption = Time$ sum_zj = sum_zj + 1 '校准

If sum_zj >= 60 Then

sum_zj = sum_zj - 60 '每分钟记录一组数据 Adodc1.Recordset.AddNew

Adodc1.Recordset(0) = shiyan_sj(0)

Adodc1.Recordset(1) = Mid(Date$, 3, 2) & Mid(Date$, 6, 2) & Mid(Date$, 9, 2) & \Mid(Time$, 7, 2) '记录time

Adodc1.Recordset(2) = Val(Label3(0).Caption) '记录数据

Adodc1.Recordset(3) = Val(Label3(1).Caption) '记录数据 Adodc1.Recordset.Update End If End If End Sub

只要数据能保存于数据库.曲线图无须保存,通过数据检索画图: Private Sub numChaxun_Click()

Adodc1.ConnectionString = \Source=\

Adodc1.RecordSource = \& \Adodc1.Refresh

zsl = Adodc1.Recordset.RecordCount If zsl > 0 Then

numPrint.Enabled = True

numPrintData.Enabled = True numData.Enabled = True For i = 0 To zsl - 1

quexian(1, i) = Adodc1.Recordset(1) For j = 2 To 9

quexian(j, i) = Adodc1.Recordset(j) Next j

Adodc1.Recordset.MoveNext Next i

Picture2.Height = 6765 Picture1.Visible = False

Text2 = Right(quexian(1, 0), 8)

Text3 = Right(quexian(1, zsl - 1), 8) Text1.SelStart = 8 Text1.SelLength = 2

DataGrid1.Visible = False Adodc1.Visible = False Picture2.Height = 7245 Picture1.Visible = True Picture1.Cls colvb = vbBlue xx = 100 yy = 150 txt = \℃\

wp = xp(colvb, xx, yy, txt) xx = 200 yy = 350 txt = \

wp = xp(colvb, xx, yy, txt) yy = 1350 xx = 200 txt = \

wp = xp(colvb, xx, yy, txt) xx = 200 yy = 2350 txt = \

wp = xp(colvb, xx, yy, txt) yy = 3350 xx = 200 txt = \

wp = xp(colvb, xx, yy, txt) yy = 4350 xx = 200 txt = \

wp = xp(colvb, xx, yy, txt) yy = 5350 xx = 200 txt = \

wp = xp(colvb, xx, yy, txt) xx = 200 yy = 6350 txt = \

wp = xp(colvb, xx, yy, txt) 'Time坐标 colvb = vbRed yy = 6500 xx = 400 txt = \

wp = xp(colvb, xx, yy, txt) xx = 1300 txt = \

wp = xp(colvb, xx, yy, txt) xx = 2200 txt = \

wp = xp(colvb, xx, yy, txt) xx = 3100 txt = \

wp = xp(colvb, xx, yy, txt) xx = 4000 txt = \

wp = xp(colvb, xx, yy, txt) xx = 4900

txt = \

wp = xp(colvb, xx, yy, txt) xx = 5800

txt = \小时\

wp = xp(colvb, xx, yy, txt) xx = 6700 txt = \

wp = xp(colvb, xx, yy, txt) xx = 7600 txt = \

wp = xp(colvb, xx, yy, txt) xx = 8500 txt = \

wp = xp(colvb, xx, yy, txt) xx = 9400 txt = \

wp = xp(colvb, xx, yy, txt) xx = 10300 txt = \

wp = xp(colvb, xx, yy, txt) xx = 11200 txt = \

wp = xp(colvb, xx, yy, txt) '画格

Picture1.DrawWidth = 1 ' = dash Picture1.DrawStyle = 0

Picture1.ForeColor = vbBlue Picture1.DrawStyle = 2 For i = 0 To 12

Picture1.Line (450, 400 + i * 500)-(11300, 400 + i * 500) Next

For i = 0 To 12

Picture1.Line (500 + i * 900, 400)-(500 + i * 900, 6400) Next

Picture1.DrawStyle = 0 For j = 0 To zsl - 2

If Int(j / 30) - j / 30 = 0 Then

Picture1.DrawWidth = 1 ' = dash

Picture1.Line (j * 15 + 470, quexian(6, j) * -20 + 6400)-(j * 15 + 530, quexian(6, j) * -20 + 6400), vbGreen ', BF

Picture1.Line (j * 15 + 500, quexian(6, j) * -20 + 6435)-(j * 15 + 500, quexian(6, j) * -20 + 6435), vbGreen ', BF

Picture1.Line (j * 15 + 470, quexian(7, j) * -20 + 6435)-(j * 15 + 470, quexian(7, j) * -20 + 6435), vbBlue ', BF

搜索更多关于: VB串口通信程序代码 的文档
VB串口通信程序代码.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c1g7zv244tk4x67j2puq9_6.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top