isamel85
Newbie level 6
- Joined
- Nov 6, 2011
- Messages
- 11
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,416
Hello
In fact, I want to acquire a 8-bit binary data on serial port using Matlab (eg 00001100 in binary or 12 decimal). I make a test loop back just sending that data over the port and receive on the same port, knowing that sending code works fine and I checked it by HyperTerminal.
I tried this code for the acquisition in Matlab script:
But I get nothing. Maybe the code missed something.
Please can someone help me to solve this problem?
Thanks in advance for any help.
Best regards,
Isamel
In fact, I want to acquire a 8-bit binary data on serial port using Matlab (eg 00001100 in binary or 12 decimal). I make a test loop back just sending that data over the port and receive on the same port, knowing that sending code works fine and I checked it by HyperTerminal.
I tried this code for the acquisition in Matlab script:
Code dot - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 s=serial('COM1'); % Create a serial port object %Configure property values s.InputBufferSize=50000; s.BaudRate=9600; fopen(s); %open the port % Here the beginning of the reading binary data ----------------------------------------------------------- index = 1; nb_bytes = get(s,'BytesAvailable'); while (index < get(s,'inputBuffersize')) if nb_bytes out= fread(s, nb_bytes,'uint8'); index = index + nb_bytes; end; pause(0.2); end; %End of reading code------------------------------------------------------------------------------------------- %Disconnect and clean up fclose(s); delete(s); clear s;
But I get nothing. Maybe the code missed something.
Please can someone help me to solve this problem?
Thanks in advance for any help.
Best regards,
Isamel
Last edited by a moderator: