if mscomm1.commevent = comevreceive then
s1 = mscomm1.input
if (s1 = chr(&h1b)) and (len(scoms) 》 2) then
scoms = “”
else
if s1 《》 chr(&hd) then
scoms = scoms & s1
else
call mysave(scoms)
end if
end if
end if
end sub
程序过程名:mysave。它的作用:对从下位机(plc)传输到上位机(vb监控软件)的数据进行初始化处理。程序如下:
private sub mysave(scoms as string)
scoms = trim(scoms)
scoms = mid(scoms, 1, 10)
for i = 1 to 8
text1(i).text = mid(scoms, i, 1)
next i
for i = 0 to 1
text2(i).text = mid(scoms, i + 9, 1)
next i
end sub
程序过程名:form_load。它的作用:完成窗体载入时的程序设置。
private sub form_load()
timer1.enabled = true
timer1.interval = 100
with mscomm1
.commport = 1
.settings = “19200,n,8,1”
.inputmode = cominputmodetext
.rthreshold = 1
.inputlen = 1
end with
if mscomm1.portopen = false then
mscomm1.portopen = true
end if
end sub
5 结束语
本文介绍了用可视化编程语言vb实现pc机与s7-200plc之间的数据通讯技术及实现方法,研讨基于自由口通信模式的上下位机通信方式,通过分析其通信流程,开发相应的通信程序,并将其应用于数码显示监控系统中,实现了生产过程的自动控制,还有可视化的操作界面,充分体现了人机交互的优势。实践证明,这种通信方式简单,可靠,实时性好、成本低、便于调试,这种通信方式也可以应用于其它相关的通信场合,具有普遍和现实工程意义。
本文关键字:通信 解决方案,plc技术 - 解决方案