预览加载中,请您耐心等待几秒...
1/10
2/10
3/10
4/10
5/10
6/10
7/10
8/10
9/10
10/10

亲,该文档总共19页,到这已经超出免费预览范围,如果喜欢就直接下载吧~

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

串口数据采集及曲线动态显示这个程序主要用到了串口通信和曲线画图主要控件Msomm控件一个,两个timer控件,textbox控件,combo控件,picture控件,command控件二.实现的功能能1.串口采集数据2.用曲线动态显示数据3.显示时间4.鼠标点击读数(确定所点击位置的横纵坐标)三.界面四.程序DimTAsVariantDimcAsVariantDimYAsIntegerPrivateDeclareSubSleepLib"kernel32"(ByValdwMillisecondsAsLong)'API,用sleep实现延时'延时函数Functiondelay(number)CallSleep(number)DoEventsEndFunctionPrivateSubCombo1_Click()'选择端口IfCombo1.Text="COM1"ThenMSComm1.CommPort=1ElseIfCombo1.Text="COM2"ThenMSComm1.CommPort=2ElseIfCombo1.Text="COM3"ThenMSComm1.CommPort=3ElseIfCombo1.Text="COM4"ThenMSComm1.CommPort=4ElseMSComm1.CommPort=5EndIfEndSubPrivateSubCommand3_Click()'停止采集Timer2.Enabled=FalseMSComm1.PortOpen=FalseCommand2.Caption="打开串口"EndSubPrivateSubForm_Load()'初始化MSComm1.Settings="9600,N,8,1"MSComm1.InputMode=0MSComm1.RThreshold=1MSComm1.SThreshold=0MSComm1.InBufferSize=1024MSComm1.OutBufferSize=512MSComm1.InBufferCount=0MSComm1.OutBufferCount=0Combo1.AddItem"COM1"Combo1.AddItem"COM2"Combo1.AddItem"COM3"Combo1.AddItem"COM4"Combo1.AddItem"COM5"Picture1.Scale(-100,100)-(100,-100)Command1.Caption="采集数据"Command2.Caption="打开串口"Timer1.Interval=1000Timer2.Interval=1000Timer2.Enabled=FalseEndSubPrivateSubCommand2_Click()IfCommand2.Caption="打开串口"ThenMSComm1.PortOpen=TrueCommand2.Caption="关闭串口"ElseIfCommand2.Caption="关闭串口"ThenMSComm1.PortOpen=FalseCommand2.Caption="打开串口"EndIfEndSubPrivateSubMSComm1_OnComm()'触发事件IfMSComm1.InBufferCount>0ThenText4.Text=MSComm1.Inputc=Val(Text4.Text)delay(20)EndIfEndSubPrivateSubdraw()Picture1.FontSize="15"'设置字体大小Picture1.DrawWidth=1Picture1.ForeColor=QBColor(12)Picture1.ClsPicture1.Line(-88,-88)-(-88,88)'纵坐标Picture1.Line(-89,86)-(-88,88)'纵坐标箭头及y值Picture1.Line(-87,86)-(-88,88)Picture1.PSet(-86,88)Picture1.Print"y"Picture1.Line(-88,0)-(88,0)'横坐标Picture1.Line(86,1)-(88,0)'横坐标箭头及x值Picture1.Line(86,-2)-(88,0)Picture1.PSet(88,-1)Picture1.Print"x"Picture1.DrawWidth=4Picture1.FontSize=8ForY=-80To80Step10Picture1.PSet(-88,Y)Picture1.Print(Y)NextYT=-88Timer2.Enabled=TrueEndSubPrivateSubPicture1_MouseDOWN(ButtonAsInteger,Shif