1、 ADAM 模块在液位检测中的应用关键词:ADAM4017,ADAM4520,VB 软件,集中液位实时采集 ,实时数据通讯一、概述 山东泉林纸业有限责任公司是一个集制浆、造纸类综合企业,该企业铜版纸生产线所用附料液位监视系统是自行开发的集中液位实时采集系统,生产人员通过中心控制室的电脑屏幕即可得到料罐液位的实时数据,从而决定是否配料。采用此系统还可减少为每个料罐配置一个液位显示仪表而产生的繁琐布线,只要把液位信号线集中铺设到中控室与 ADAM4017 模块连接即可。集中配料,物料通过管道输送到各个料罐,一人可配多种料,减少了人力成本。本文主要讨论 WINXP 操作系统下利用 VB 软件实现研华
2、公司的 ADAM4520 与ADAM4017 的实时数据通讯。2、系统的实现方法数据采集框图本系统要采集 20 种物料的液位,监视画面及电脑与 ADAM4520 的通讯由VB 软件实现,ADAM4017 用于接收 420MA 液位信号, ADAM4520 用于电脑与 ADAM4017 之间数字信号和模拟信号的转换。VB 程序做出监控画面如下:由于篇幅所限现只列出主程序代码如下:Private Sub Command1_Click()Unload Form1End Sub监视电脑ADAM4520ADAM4017 ADAM4017 ADAM4017液位信号 液位信号 液位信号Private Sub
3、 Command2_Click()Form1.WindowState = 1End SubPrivate Sub Command3_Click()Timer1.Enabled = Falsesetup.ShowEnd SubPrivate Sub Command4_Click()Dim freeF As IntegerfreeF = FreeFile()Open “d:gaoddemodival.dat“ For Random As freeF “可以自行设置路径“For i = 1 To 20Put freeF, i, modifyVal(i - 1)Next iClose (freeF)E
4、nd SubPrivate Sub errCode_Change()If MVal(errCode) + 1 = 300 Then errCode = 0End SubPrivate Sub Form_DblClick()Form1.WindowState = 1End SubPrivate Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)If Shift = 7 ThenenabledSetup = 1ElseIf Shift = 6 ThenenabledSetup = 2ElseenabledSetup = 0End IfEnd
5、 SubPrivate Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)enabledSetup = 0End SubPrivate Sub Form_Load()Dim freeF As Integer MI(0) = 1MI(1) = 2MI(2) = 4MII(0) = 6MII(1) = 5MII(2) = 3freeF = FreeFile()Open “d:gaoddemodival.dat“ For Random As freeF路径可自行定义If LOF(freeF) = 0 ThenFor i = 1 To 20modi
6、fyVal(i - 1) = 0Text1(i - 1).Text = modifyVal(i - 1)Put freeF, i, modifyVal(i - 1)Next iElseFor i = 1 To 20Get freeF, i, modifyVal(i - 1)Text1(i - 1).Text = modifyVal(i - 1)Next iEnd IfClose (freeF)Open “com2,9600,8,N,1“ For Random As freeFx = sio_open(PortNum)x = sio_ioctl(PortNum, B9600, BIT_8 + S
7、TOP_1 + P_NONE)x = sio_flush(PortNum, 2)For i = 0 To 2Label14(i) = “ “Label7(i) = “ “Label16(i) = “ “Label17(i) = “ “Next itongxun_ok = 0End SubPrivate Sub Label11_Click()If enabledSetup = 1 ThenmyDelay = myDelay + 100Label12 = myDelayEnd IfEnd SubPrivate Sub Label16_Change(Index As Integer)If MVal(
8、Label16(Index) 9999 Then Label16(Index) = 0End SubPrivate Sub Label17_Change(Index As Integer)If MVal(Label17(Index) 9999 Then Label17(Index) = 0End SubPrivate Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)Dim tempValtempVal = Val(Text1(Index).Text)tempVal = Int(tempVal * 10) / 10If tempV
9、al 3 ThenText1(Index).Text = 0tempVal = 0End IfmodifyVal(Index) = tempValIf KeyAscii = 13 Then Text1(Index).Text = tempValEnd SubPrivate Sub Timer1_Timer()Dim i As Integer, j As IntegerDim x As LongDim checkNum As Long, rwNum As Long -On Error GoTo errchuFor i = 1 To 3x = sio_flush(PortNum, 2)ss = “
10、#“ + Format$(i, “00“)checkNum = 0For j = 1 To 3checkNum = checkNum + Asc(Mid$(ss, j, 1)Next jss = ss + Hex$(checkNum And &HFF) + Chr$(13)x = sio_write(PortNum, ss, Len(ss)BeepWhile x 900000 Thenx = MsgBox(“通讯线路故障,请检查通讯线路,排除故障后请确定,如果确定几次后错误依然存在,请关机后重新启动.“, 64)Exit ForEnd If WendSleep (200)LL = sio_iq
11、ueue(PortNum) If LL = 60 ThenLL = sio_read(PortNum, AA, 60)If LL = 10 ThenreadNUM(i - 1) = 0errCode = MVal(errCode) Or MI(i - 1)End IfLabel17(i - 1) = MVal(Label17(i - 1) + 1End IfNext itongxun_ok = MVal(tongxun_ok) + 1 为组态判断 DDE 驱动程序异常所用Exit Suberrchu:x = MsgBox(“系统错误,请确定,如果确定几次后错误依然存在,请关机后重新启动“, 6
12、4)Resume NextEnd SubPrivate Sub tongxun_ok_Change()If tongxun_ok = 9999 Then tongxun_ok = 0End Sub为实现 ADAM4520 与电脑通过 RS232 接口通讯,另做了一个 DDE 驱动程序,利用了 VB 串口通讯原理,详细代码这里不再列出。 (有需要的朋友可联系我)程序整理编译后,便生成如上监控画面。3、结束语 目前,我公司 3800 生产线附料车间应用此液位采集系统已三年多,平均故障率为零。我公司采用的工控机也为研华产品,其高度的稳定性保证了数据的可靠,方便了生产人员的及时准确掌握生产情况,确保了生产的稳定运行。证明此工程项目的可行性和可用性。 作者:王国庆 qq:57067355 邮编:252800 地址:山东省聊城市高唐县光明东路 15 号泉林集团电仪车间