最近在学习编写用上位机来控制plc,从啥也不懂到完成这个,也是经历了一些痛苦,那就顺道写写我的学习过程吧。
选了vb来写是因为它的操作相对来说比较简单,有 MSComm 控件很容易就能够实现。对这个控件就不多讲解了,网上也多的是。下面直接贴我的代码:
首先是窗口程序的初始化:
Private Sub Form_Load()
Dim i As Integer
Combo1.AddItem "9600", 0
Combo1.AddItem "115200", 1
Combo2.AddItem "0", 0
Combo2.AddItem "1", 1
Combo2.AddItem "2", 2
Combo2.AddItem "3", 3
Combo2.AddItem "4", 4
Combo2.AddItem "5", 5
Combo2.AddItem "6", 6
Combo2.AddItem "7", 7
Combo2.AddItem "8", 8
Combo2.AddItem "9", 9
Combo2.AddItem "10", 10
Combo2.AddItem "11", 11
Combo2.AddItem "12", 12
Combo2.AddItem "13", 13
Combo2.AddItem "14", 14
Combo2.AddItem "15", 15
Combo5.AddItem "读取数据", 0
Combo5.AddItem "发送数据", 1
Combo6.AddItem "1", 0
Combo6.AddItem "2", 1
Combo6.AddItem "3", 2
Combo6.AddItem "4", 3
Combo6.AddItem "5", 4
Combo6.AddItem "6", 5
Combo6.AddItem "7", 6
Combo6.AddItem "8", 7
Combo6.AddItem "9", 8
Combo6.AddItem "10", 9
Combo6.AddItem "11", 10
Combo6.AddItem "12", 11
Combo6.AddItem "13", 12
Combo6.AddItem "14", 13
Combo6.AddItem "15", 14
Combo6.Add