-------------段长
消息头 @      1
消息长 5      1
会话ID 0x0101 2开 0x01       1
关 0x02
private byte at = 0x40;
private byte len=5;
private byte tel=(byte)0x0101;
private byte homeCmd=0;然后放到byteBuffer数组里,再放到STRING里,再转成toCharArray这么写对吗???应该怎么写?

解决方案 »

  1.   

    会话 ID 两个字节是不是太短了一些?这个 ID 应得是唯一的,两个字节的话,只有 65536 个序号。private byte tel=(byte)0x0101;这个肯定不对了,得这样:private byte[] tel= { 0x01, 0x01 };
      

  2.   


    多谢火龙果,那我是不是应该这样改:
    private byte at = 0x40;
    private byte len=5;
    private byte []tel={0x01,0x01};
    private byte []homeCmd={0,0};

    public void convertFromWebCommand(WebCommand webCommand) {
    this.homeCmd[0] = webCommand.getNode();
    this.homeCmd[1] = webCommand.getCmd();
    }

        public byte[] getBuffer(){
        
         byte []buf=new byte[6];
          
         buf[0]=at;
         buf[1]=len;
         buf[2]=tel[0];
         buf[3]=tel[1];
         buf[4]=homeCmd[1];
         buf[5]=0;
        
        
         return buf; 
        
        }
      

  3.   

    0x0302就改成:
    private byte[] tel= { 0x03, 0x02 };是不?