Send byte array on serial port out put stream

痞子三分冷 提交于 2019-12-13 08:49:35

问题


when I want to send byte array on serial port stream with java,on destination device I receive different result !!!

byte[] sendingPack = new byte[7];
    sendingPack[0] = 0x6E;
    sendingPack[1] = 0x55;
    sendingPack[2] = (byte) 0x0D;
    sendingPack[3] = (byte) (1 & 0x000000FF);
    sendingPack[4] = 0x01;
    sendingPack[5] = 0x0D; 
    sendingPack[6] = (byte) 0xAA;

    getSendBuffer().getOutputStream().write(sendingPack);

sending array : byte[]{0x6E,0x55,0x0D,0x01,0x01,0x0D,0xAA} 
receive result array : 6E 55 0D 0A 01 01 0D 0A AA 

on CodeVisionAVR terminal I receive "0A"!! how can I solve this problem??


回答1:


The terminal is probably in text reading mode and not in binary read mode.

The 0x0A which is inserted after every 0x0D you send is a carriage return conversion.

The terminal converts "\r" to "\r\n". It adds a line feed char to every carriage return.

The terminal converts every 0D to 0D 0A.

This same feature can be found in the ftp protocol. You tell your client how to transfer files: in text or binary mode.



来源:https://stackoverflow.com/questions/34838756/send-byte-array-on-serial-port-out-put-stream

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!