云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > VB串口通信程序代码

VB串口通信程序代码

  • 62 次阅读
  • 3 次下载
  • 2025/6/17 13:54:00

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串口通信程序代码 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

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

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com