您的位置:程序门 -> vb -> 基础类



在vb中,怎样从串口接收缓冲区内取出字节(16进制),然后显示在文本框里?


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


在vb中,怎样从串口接收缓冲区内取出字节(16进制),然后显示在文本框里?[已结贴,结贴人:njlrg]
发表于:2007-03-05 10:01:48 楼主

初学vb,尚未入门,请dx指点、改正:

if   mscomm1.inbuffercount   >   0   then
        text3.text   =   mscomm1.input
        text4.text   =   "接收数据: "   &   text3.text
end   if
发表于:2007-03-05 10:10:501楼 得分:100
定义一个将字节数组的内容转换成十六进制字符串的函数:
function   bytearraytohexstring(abuffer   as   variant)   as   string
        dim   iloop   as   long
        bytearraytohexstring   =   " "
        for   iloop   =   lbound(abuffer)   to   ubound(abuffer)
                bytearraytohexstring   =   bytearraytohexstring   &   right( "0 "   &   hex(abuffer(iloop)),   2)   &   "   "
        next   iloop
        bytearraytohexstring   =   trim(bytearraytohexstring)
end   function


mscomm1需要定义成按字节方式接收数据:

        dim   abuffer()   as   byte
        mscomm1.inputmode   =   cominputmodebinary
        if   mscomm1.inbuffercount   >   0   then
                abuffer   =   mscomm1.input
                text4.text   =   "接收数据: "   &   bytearraytohexstring(abuffer)
        end   if
发表于:2007-03-05 10:44:502楼 得分:0
谢谢楼上,晚间试。


快速检索

最新资讯
热门点击