09-21-2015 04:44 AM
Hi
I am trying RS232 serial communication bw two pc s.I am sending one image from transmitter pc using matlab code and trying to read at 2nd pc using labview VISA read options.I have to read intensity values of pixel eg as 126,86,256 like that and trying to save into a text file using write to text file option.Now i am facing a large delay to store data .Even after my sending programme finsh executing labview is taking lot of time to read each value as a group of string(eg as 125 ,66,256) and writing into text file.Can anyone give me a solution to reduce delay in reading
Thanking you
Sangeetha
09-21-2015 05:01 AM
Code?
What exactly is the data structure? Are you sending ASCII strings or binary data? Does the transmission have a termination character?
Your slow down could also be from the writing to the file. Are you explicitly opening the file before your loop and closing it afterwards? Are you using a Producer/Consumer?
Please supply your code so we can give more informed advice.
09-21-2015 07:55 AM
In addition to what has already been said, I usually start with the Simple Serial example that ships with LabVIEW. Go to Help >> Find Examples and search for it. There it shows the code to send a serial command, wait, then read the response. It is a decent starting point for talking to devices, but it doesn't scale well and there are better designs when you have a terminating character.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
09-21-2015 09:07 AM
Just double checking, you are using the serial port rather than a USB port right?
I know in MATLAB a lot of people in academia tend to write RS232 data via USB.
09-22-2015 12:02 AM
I am using serial port itself .Attaching my matlab code for sending and labview code of serial reading here ..
%PROGRAME TO SEND AN IMAGE THROUGH SERIAL PORT
clc;clear all;close all;
% s=serial('COM1','BAUD',9600);
% data=imread('Tulips.jpg')
data=imread('images.jpg');
s=serial('COM1');
set(s,'BAUD',9600);
set(s,'Parity','none');
set(s,'Databits',8);
set(s,'TimeOut',50);
fopen(s);
% while(1)
for i=20:40
for j=100:110
for k=1:3
data1=num2str(data(i,j,k));
fprintf(s,'%s\n',data1);
disp(data1);
end
end
end;
% set(s,'RequestToSend','on');
% get(s,'ValuesSent');
% get(s,'RequestToSend');
% end
fclose(s);
09-22-2015 05:24 AM
You will want to move your writing of your file to be inside of the loop. Right now you are building up a huge array of strings and finally writing that. That dynamic building of a large array can cause things to be very slow.
So you want to open/create your file before your loop, write to the file inside of the loop, and close the file after the loop.
09-22-2015 05:28 AM
Could a producer consumer model using a queue be suitable here?
10-05-2015 03:14 AM
Sorry for the delay in response sir.I have modified the code as per your suggestion.But still I am not able to get any improvement in speed.Same delay is occuring even if tried with creating file outside loop ,writing iside loop .I am attaching the modified code here.Please see it
10-05-2015 07:41 AM
Since it sounds like you are dealing with a lot of streaming data, the Producer/Consumer is likely the path you want to go with. The idea is to put the File IO (which tends to be slow) into another loop so that you can keep reading your serial port at a decent rate.