Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
326 views
in Technique[技术] by (71.8m points)

java - Send byte array on serial port out put stream

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??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 " " to " ". 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...