您的位置:程序门 -> vb -> 控件



高手指点!关于winsock控件接收十六进制数据的问题


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


高手指点!关于winsock控件接收十六进制数据的问题[已结贴,结贴人:xuyan0122]
发表于:2007-04-13 20:38:18 楼主
public   function   strtohex(byval   s   as   string)   as   string
                    on   error   resume   next
                    dim   bytearr()           as   byte
                    bytearr   =   strconv(s,   vbfromunicode)
                    dim   temps           as   string
                    dim   temp           as   byte
                    dim   i           as   long
                    dim   outs           as   string
                    for   i   =   0   to   ubound(bytearr)
                                    temp   =   bytearr(i)
                                    temps   =   hex(temp)
                                    temps   =   right( "00 "   &   temps,   2)
                                    outs   =   outs   &   temps
                    next
                    strtohex   =   outs
    end   function
private   sub   udppeera_dataarrival(byval   bytestotal   as   long)
          dim   strdata   as   string
          dim   inbyte()   as   byte
          dim   i   as   integer
          udppeera.getdata   strdata
          inbyte()   =   strtohex(strdata)
txtoutput.text   =   txtoutput.text   &   cstr( " < < ")   &   cstr(inbyte)
strdata   =   " "

end   sub

以上程序是本人在做通讯测试时用的,vb在接收到十六进制数据之后winsock将其看成是ascii码字符,用strtohex就是将程序收到的字符转换成实际接收十六进制.现在有个问题是,在0~128(即00h~80h)以及255(0ffh)时,可以正确转换,但在81h~0feh这些字符段时无法识别,好象就是我的vb里的ascii码字符就是0~128似的,而不是255个!请问高手问题出在哪里,谢谢先!!!!
发表于:2007-04-13 21:32:561楼 得分:0
对了,那些没有识别的转换后显示的都是00
发表于:2007-04-13 23:28:472楼 得分:0
达人给点提示贝
发表于:2007-04-13 23:28:513楼 得分:0
达人给点提示贝
发表于:2007-04-14 10:26:354楼 得分:20
什么叫十六进制数据?干什么用的?
发表于:2007-04-14 19:41:065楼 得分:0
高手达人快快显灵贝!
发表于:2007-04-14 21:49:156楼 得分:0
private   sub   udppeerb_dataarrival(byval   bytestotal   as   long)
          dim   strdata   as   variant
          dim   inbyte()   as   byte
          udppeerb.getdata   inbyte,   vbbyte
          inbyte   =   hex(strdata)  
          txtoutput.text   =   cstr(inbyte)
end   sub
如果我用上述定义,可以接收十六进制,却只能接收一个字节,超过了会报 "the   datagram   is   too   large   to   fit   into   the   buffer   and   is   truncated ",用了些想处理长度的办法但还是不得法,高人出来指点指点呀
发表于:2007-04-15 13:41:237楼 得分:0
高手怎么不出现呢,难道做的都是ascii码字符之间通讯吗?


快速检索

最新资讯
热门点击