| 发表于:2007-05-24 17:03:33 楼主 |
毕业设计:用rs-232连接单片机与pc机,用vb将单片机中采集的数据(数据是一个一个采集,有一个数据就按一下“测量”将数据传到pc机上)传到pc机上并用vb编写代码在pc机上显示出来 代码如下:private sub command2_click() dim w as integer with mscomm1 .commport = 1 '使用com1 .setting = "38400,n,8,1 " '设置通信口参数 .inbuffersize = 40 '设置mscomm1接收缓冲区为40字节 .outbuffersize = 4 '设置mscomm1发送缓冲区为2字节 .inputmode = cominputmodebinary '设置接收数据模式为二进制形式 .inputlen = 1 '设置input 一次从接收缓冲读取字节数为1 .sthreshold = 1 '设置output 一次从发送缓冲读取字节数为1 .inbuffercount = 0 '清除接收缓冲区 .outbuffercount = 0 '清除发送缓冲区 maxw = -99 '最大值赋初值 minw = 99 '最小值赋初值 w = 0 '数据个数计数器清零 .rthreshold = 1 '设置接收一个字节产生oncomm事件 if .portopen = false then '判断通信口是否打开 .portopen = true '打开通信口 if err then '错误处理 msgbox "串口通信无效 " exit sub end if end if end with end sub private sub mscomm1_oncomm() dim av as variant dim ab(5) as single select case mscomm1.commevent '判断mscomm1通信事件 case comevreceive '收到rthreshold个字节产生的接收事件 av = mscomm1.input '读取一个接收字节 ab(1) = av(0) '转换保存到字节数据类型数组 if ab(1) = &hf0 then '判断是否为数据开始标志 mscomm1.rthreshold = 0 '关闭oncomm事件接收 do doevents loop until mscomm1.inbuffercount > = 4 '循环等待mscomm1接收缓冲区> =4字节 av = mscomm1.input '读取第二个数据字节(bcd码高位字节) ab(2) = av(0) '转换保存到字节数据类型数组 av = mscomm1.input '读取第三个数据字节(bcd码低位字节) ab(3) = av(0) '转换保存到字节数据类型数组 av = mscomm1.input '读取第四个数据字节(符号位字节) ab(4) = av(0) '转换保存到字节数据类型数组 av = mscomm1.input '读取第四个数据字节(符号位字节) ab(5) = av(0) if ab(5) = &hf0 then '接收到三个字节:ab(2)、ab(3)、ab(4) end if end if mscomm1.rthreshold = 1 mscomm1.inbuffercount = 0 '清除接收缓冲区 end select end sub 运行是发现 编译错误:未找到方法或数据成员 这是什么原因! 我程序错在什么地方了! 该怎样该 ! 第一行就出来黄色警告! 什么原因啊! |
|
|
|
|