您的位置:程序门 -> vb -> 资源



求助!请大家帮个忙  告诉我是什么原因!急!!!


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


求助!请大家帮个忙 告诉我是什么原因!急!!!
发表于:2007-05-24 16:29:02 楼主
毕业设计:用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

运行是发现     编译错误:未找到方法或数据类型
这是什么原因!     我程序错在什么地方了!
发表于:2007-05-24 16:36:101楼 得分:0
哪行出错了阿,你设个断点就知道哪里错了
还有阿
comevreceive                 是什么,你定义了
发表于:2007-05-24 16:51:572楼 得分:0
先谢谢!第一行就出现问题了啊   怎么办呢?
发表于:2007-05-24 17:02:083楼 得分:0
哪段代码的第一行出现问题?
发表于:2007-05-24 17:05:014楼 得分:0
private   sub   command2_click()
 
怎么回事啊
发表于:2007-05-24 17:07:255楼 得分:0
你下列代码的
.settings误写为.setting,所以报错
编译错误:未找到方法或数据类型
改写如下:
private   sub   command2_click()
dim   w   as   integer
with   mscomm1
          .commport   =   1                             '使用com1
          .settings   =   "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
发表于:2007-05-24 17:11:456楼 得分:0
真是很感谢!我运行下试试!
发表于:2007-05-24 17:33:157楼 得分:0
mscomm1           控件你有么??
工程--部件
-     microsoft   comm   control   6.0
发表于:2007-05-24 17:40:138楼 得分:0
有啊     现在又出来新问题了   怎么回事啊   出现     实时错误‘8005'   端口已打开      
        “.portopen   =   true               ‘打开通信口”出现错误
发表于:2007-05-24 18:26:249楼 得分:0
if   .portopen   =   false   then   你不是已经判断了么
设置断点看看阿
发表于:2007-05-25 09:09:0610楼 得分:0
private   sub   command2_click()
with   mscomm1
          .commport   =   1                             '使用com1
          .settings   =   "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
          .portopen   =   false   '执行command2_click后关闭com1
    end   with
end   sub
发表于:2007-05-25 10:19:3611楼 得分:0
现在点击“控件按钮”没任何错误,但也没数据显示   没什么反应  

串口已经通了,用别的软件可以把数据读取出来,但我的却行不通,怎么回事啊?

发表于:2007-05-25 11:41:4812楼 得分:0
谁能帮我下啊


快速检索

最新资讯
热门点击