sending and receiving IMAGE using serial port(USB to serial)

19 views (last 30 days)
Hi friends,
Actually I have an image which need to be transferred via serial port. As my laptop dosent contain serial port i am using USB to serial convertor.I am sending image from one computer other using two USB to serials and null modem. I am doing this for testing purpose and later null modem will be replaced by 8051 controller. I wrote a code for transferring but i am unable to receive data proper control. Please check the below code.
For Transfering
if true
SendData=serial('COM1','BaudRate',256000);
fopen(SendData);
[rows,columns]=size(Encryptedimage);
for k=1:3
for i=1:rows
for j=1:columns
data=num2str(EncryptedImage(i,j,k));
fprintf(SendData, '%c' , '*');
fprintf(SendData, '%s',data);
end
end
end
fclose(SendData);
delete(SendData);
clear SendData;
end
For receiving
if true
recData=serial('COM2','BaudRate',256000);
fopen(recData);
while(1)
Input1=fread(receiveTemp)
if(isempty(Input1))
continue;
else
disp('Value received')
for k=1:3
for i=1:rows
for j=1:columns
Input1=char(Input1);
Input1=sscanf(Input1, '%d');
EncryptedImage1(i,j,k)=Input1;
Input1=fread(receiveTemp);
end
end
end
end
if(i==rows & j==columns & k==3)
break;
end
end
end
Now problem is while receiving Input1 is getting around 120 values at a time. please help me in rectifying this issue.
  34 Comments
Walter Roberson
Walter Roberson on 18 Feb 2018
Use several steps:
  1. read the biomedical image in, which is a step that is independent of any image processing you plan to do
  2. Do whatever image processing is appropriate for your biomedical image for whatever purpose you need, which is a step that is independent of reading the image and is independent of any plans to transmit the image
  3. if the processed image is not already uint8, use typecast() to make a byte stream out of it. This is a step that is independent of reading the image and is independent of whatever image processing you did.
  4. reshape your now uint8 image to a vector
  5. transmit the uint8 vector by LED technology -- which is a step that is independent of everything having to do with calculating which uint8 are going to be transmitted

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 26 Apr 2013
Replace
[rows,columns]=size(Encryptedimage);
with
[rows,columns,bands]=size(Encryptedimage);
In the form of size() that you were using, "columns" would be set to the real columns times the number of bands.
  2 Comments
srikanth
srikanth on 26 Apr 2013
Thanks for correcting me. But still this didnt rectified my problem of serial communication. When i am transferring values to hyper terminal i can see values continuously. But when using Matlab at reception side 'Input1' variable is showing lots of values at a time and matlab is giving error dimension mismatch. Maybe i feel there is some synchronization problem between transition and reception.How to rectify this issue?
Walter Roberson
Walter Roberson on 26 Apr 2013
You know that fread() without a size parameter will try to read until the buffer is full ? http://www.mathworks.com/help/matlab/ref/serial.fread.html
You should also be considering using the 'precision' parameter of fread().
You might want to re-think why it is that you are using the formatted-data function fprintf() to send the data, but are using the binary-data function fread() to read it.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!