LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LABVIEW SERIAL PROGRAMMING

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

0 Kudos
Message 1 of 9
(3,938 Views)

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 9
(3,928 Views)

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.

0 Kudos
Message 3 of 9
(3,888 Views)

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.

0 Kudos
Message 4 of 9
(3,860 Views)

 

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);

0 Kudos
Message 5 of 9
(3,810 Views)

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 9
(3,779 Views)

Could a producer consumer model using a queue be suitable here?

0 Kudos
Message 7 of 9
(3,774 Views)

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

0 Kudos
Message 8 of 9
(3,668 Views)

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 9 of 9
(3,639 Views)