塑料薄膜膜厚度测量仪:急求:用vb开发电子称问题

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/27 17:52:11
我做的称是到稳态时才取数,因为有时候取的数是没错

但人的因素比较大比如人为的二次过称,或称毛重的时候重复称

这样就造成数据的计算错误了,把第二次当作正式称重的数据了

有什么办法抑制一下么?还有一个问题就是写到数据库里的数据

老是在有了第二组数据后再写入第一组数据

接收的具体代码如下:

Private Sub MSComm1_OnComm()

On Error Resume Next

recive = MSComm1.Input

For i = 0 To UBound(recive)
If begin = 0 Then
If recive(i) = 2 Then '找到开始标识2,设置标志为1
begin = 1
End If
Else
str_Date(int_Jishuqi) = recive(i)
int_Jishuqi = int_Jishuqi + 1 '计数器
If int_Jishuqi > 16 Then '数组下标默认从0开始,,0-16共17个字节的数

begin = 0
int_Jishuqi = 0

If str_Date(1) Mod 3 = 0 Then '

a = CStr(Chr(str_Date(3))) & CStr(Chr(str_Date(4))) & CStr(Chr(str_Date(5))) & CStr(Chr(str_Date(6))) & CStr(Chr(str_Date(7))) & CStr(Chr(str_Date(8)))
If a > 80000 And a < 110000 Then
a1 = a
Text2.Text = CDbl(Round(a1 / 1000, 1))

End If
If a < 80000 And a > 50000 Then
a2 = a
Text3.Text = CDbl(Round(a2 / 1000, 1))

Text4.Text = ((Text2.Text) - (Text3.Text))
a3 = CStr(Text4.Text)

End If

If a3 > 0 Then
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("时间") = lable6.Time
Adodc1.Recordset.Fields("毛重") = a1
Adodc1.Recordset.Fields("皮重") = a2
Adodc1.Recordset.Fields("净重") = a3

End If

For j = 0 To UBound(str_Date)
Text1.Text = Text1.Text + " " + CStr(Hex(str_Date(j))) '显示为16进制数
Next j
End If

End If

End If
Next

End Sub

你的终端程序在接收到数据后,应有传入数据的判别代码和确认代码,完成后方可写入数据库。
写入数据库代码中少了一句更新代码:
If a3 > 0 Then
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("时间") = lable6.Time
Adodc1.Recordset.Fields("毛重") = a1
Adodc1.Recordset.Fields("皮重") = a2
Adodc1.Recordset.Fields("净重") = a3
Adodc1.Recordset.Updata
End If

VB,VB.NET交流
欢迎假如24885035群,请说明意图
代码成就天地人生,程序造就你我辉煌
让我们在程序的路上一起走得更远!