yes the microcontroller is sending packages of 8 Bit + Start/Stop
bits....
The incoming "hex" for example is, as I can see it in Terminal oder
Hterm ....
i want to tranfer the number: 1400 (DEZ)
so the MC sends: 0578 (HEX)
05 78 05 78 05 78 .....
matlab ist tranfering the value of "8 Bits" (05) into the value=5 and
taking the Ascii letter of this value from 5.
how do i read direct the Hex letter of 8 Bits?then i just have to
tranfer HEX (of 16 Bit) into a number...
actually i convert it this way but this is not the best one :-)
bytes = Port1.BytesAvailable;
while bytes ~= 2
bytes = Port1.BytesAvailable;
end
data = fscanf(Port1,'%s' , [1,bytes]);
trans = double(data);
hexwert = dec2hex(trans);
zahlh = hex2dec(hexwert(1,1:2));
zahll = hex2dec(hexwert(2,1:2));
nums(i,1) = (zahlh*256+zahll);
flushinput(Port1);
Post by davePost by Jörn AhrensI send hex values from a microcontroller to matlab.
but matlab is always making ASCII from the Hex bytes!
how do i get the Hex?
i tryied %c,%s....
data = fscanf(Port1,'%s' , [1,bytes])
flushinput(Port1);
disp([int2str(bytes) ' bytes received from COM1: ' data]);
well, actually you only send and receive streams of bits. the bits
get presented to the transmitter in groups of 8 called byted, get
streamed one at a time over the wire, then grouped into bytes again
by the receiver. These bytes get read by matlab... it is then up to
you how you interpret them. i would guess from the above that you
have mixed up your data types... fscanf with either %s or %c is going
to be looking for an ascii character and will give you the single
letter or number character that cooresponds to the bit pattern you
read. to get a proper answer here you will have to post the code
that formats the data for sending, AND the code that does the read
from the port and interprets it in matlab.