MATLAB: How to output a binary txt file to serial port in order

orderserial porttxt

hello everyone,
i suffer from a problem that i can`t output my binary txt file line by line (left to right and up to down)to a serial port.
how can i determine the order of binary data in txt to serial port? the following is my matlab code:
ins=serial('COM3','BaudRate',115200);
fopen(ins);
A = fopen('xxxx.txt');
txdata = fread(A,inf,'uint8','ieee-be');
for i = 1:32768
fwrite(ins,txdata(i),'uint8');
end
fclose(ins);
thx

Best Answer

"binary text file" is a contradiction. The file is either line structured or it is not. For text files it makes sense to talk about left to right and top to bottom, but it does not make sense to do that for binary files: for binary files it only makes sense to talk about beginning to end.
The code you used is appropriate for sending, in order, the first 32768 bytes of a binary file to a serial port that does not care about flow control, to be received by a system that is not expecting line terminators. The code is also for the case where there is no structure to the transmission -- structure that might, for example, say "Okay, here is a new image that is 768 by 512, grayscale, 8 bits per pixel".
The 'ieee-be' is misleading because "endian" conversions do not have meaning for individual bytes.