Read serial data directly into Octave

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Read serial data directly into Octave

themattdiaz
Hello,

I am trying to have Octave read data from a serial port and then create a figure with this data. When I run this program all I get is a blank figure with no data on it. Is there any errors in my code below? Please let me know.

Thank you





page_screen_output(0);
page_output_immediately(1);
pkg load instrument-control
close all
clear all
clc
ch1 = serial("COM4", 9600);
set(ch1,"bytesize", 7)
set(ch1,"stopbits", 2);
srl_flush(ch1);
i = 1;
srl_write(ch1, "F");
y=0;
x=0;

READY = yes_or_no ("Ready to test? \n");

 t=0;
 t2=360;
 fig_data = [0,0];
dt = 0.02;
h =figure(2);
b1 = uicontrol (h, "string", "Start Test", "position",[10 0 150 20],"callback","uiresume(h)");
b2 = uicontrol (h, "string", "End Test", "position",[200 0 350 20],"callback","break");

uiwait(h);
tic;
unwind_protect
 while t < t2
sleep (dt)
    srl_write (ch1,"?");
    y_raw = strtrunc(char(srl_read(ch1,11)),7);
    y_serial = -1* str2num(y_raw);
    i = i + 1;

plot(fig_data(:,1),fig_data(:,2));
grid on;
title('90 Degree Peel Test');
xlabel('Time (s) ');
ylabel('Pull Force (lbs)');
t = toc;
fig_data = [fig_data;t,y_serial];

t = t + dt;


endwhile
unwind_protect_cleanup
t_end = t;

csvout =  "Data2.csv";
dlmwrite(csvout,fig_data,",");
result_area_t = area_under_peel_time(fig_data,t_end);
result_area = area_under_peel(fig_data,t_end);
end_unwind_protect
af = num2str(result_area_t);

msgbox(strcat("Chart Area:  ",af,' Pound-Seconds','     Time:',num2str(t_end)));
close(h);
srl_close(ch1)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Read serial data directly into Octave

Doug Stewart-4


On Thu, Aug 10, 2017 at 5:32 PM, themattdiaz <[hidden email]> wrote:
Hello,

I am trying to have Octave read data from a serial port and then create a
figure with this data. When I run this program all I get is a blank figure
with no data on it. Is there any errors in my code below? Please let me
know.

Thank you





page_screen_output(0);
page_output_immediately(1);
pkg load instrument-control
close all
clear all
clc
ch1 = serial("COM4", 9600);
set(ch1,"bytesize", 7)
set(ch1,"stopbits", 2);
srl_flush(ch1);
i = 1;
srl_write(ch1, "F");
y=0;
x=0;

READY = yes_or_no ("Ready to test? \n");

 t=0;
 t2=360;
 fig_data = [0,0];
dt = 0.02;
h =figure(2);
b1 = uicontrol (h, "string", "Start Test", "position",[10 0 150
20],"callback","uiresume(h)");
b2 = uicontrol (h, "string", "End Test", "position",[200 0 350
20],"callback","break");

uiwait(h);
tic;
unwind_protect
 while t < t2
sleep (dt)
    srl_write (ch1,"?");
    y_raw = strtrunc(char(srl_read(ch1,11)),7);
    y_serial = -1* str2num(y_raw);
    i = i + 1;

where is i  used?


 
plot(fig_data(:,1),fig_data(:,2));
grid on;
title('90 Degree Peel Test');
xlabel('Time (s) ');
ylabel('Pull Force (lbs)');
it seems to me that you are using t two different ways
t seems to be a counter from 1 to 360 in steps of dt
but you are using it for the results of toc
which do you want??
I can't run it so these are just some guesses.
  
 
t = toc;
fig_data = [fig_data;t,y_serial];

t = t + dt;


endwhile
unwind_protect_cleanup
t_end = t;

csvout =  "Data2.csv";
dlmwrite(csvout,fig_data,",");
result_area_t = area_under_peel_time(fig_data,t_end);
result_area = area_under_peel(fig_data,t_end);
end_unwind_protect
af = num2str(result_area_t);

msgbox(strcat("Chart Area:  ",af,' Pound-Seconds','
Time:',num2str(t_end)));
close(h);
srl_close(ch1)




--
View this message in context: http://octave.1599824.n4.nabble.com/Read-serial-data-directly-into-Octave-tp4684422.html
Sent from the Octave - General mailing list archive at Nabble.com.

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave



--
DASCertificate for 206392


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Read serial data directly into Octave

Juan Pablo Carbajal-2
In reply to this post by themattdiaz
> I am trying to have Octave read data from a serial port and then create a
> figure with this data.

Check this tutorial using Arduino

http://dwengo.org/node/8410

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Read serial data directly into Octave

Andreas Weber-6
In reply to this post by themattdiaz
Am 10.08.2017 um 23:32 schrieb themattdiaz:
> I am trying to have Octave read data from a serial port and then create a
> figure with this data. When I run this program all I get is a blank figure
> with no data on it. Is there any errors in my code below? Please let me
> know.

Without having the device it's nearly impossible to say...
But for you it's easy to trace this problem. Do you get meaningful data
when using srl_read? Is the problem with reading and interpreting the
data or plotting?

-- Andy

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Read serial data directly into Octave

themattdiaz
Andreas Weber-6 wrote
Am 10.08.2017 um 23:32 schrieb themattdiaz:
> I am trying to have Octave read data from a serial port and then create a
> figure with this data. When I run this program all I get is a blank figure
> with no data on it. Is there any errors in my code below? Please let me
> know.

Without having the device it's nearly impossible to say...
But for you it's easy to trace this problem. Do you get meaningful data
when using srl_read? Is the problem with reading and interpreting the
data or plotting?

-- Andy
It seems when using srl_read I get one of two things: the message "error: serial: Error opening the interface: Access is denied". Or Octave will simply not run the program and will freeze, requiring me to force close it using task manager. Why am I getting the access is denied message? Also what could be causing Octave to freeze in such a manner?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Read serial data directly into Octave

Andreas Weber-6
Am 15.08.2017 um 19:49 schrieb themattdiaz:
> It seems when using srl_read I get one of two things: the message "error:
> serial: Error opening the interface: Access is denied". Or Octave will
> simply not run the program and will freeze, requiring me to force close it
> using task manager. Why am I getting the access is denied message? Also what
> could be causing Octave to freeze in such a manner?

Difficult to say. Are you sure there is a COM4 on your Windows and no
other programm is using it?

I would really suggest to make a loopback (connect Pin2+3 on your SUB-D
9pol connector) and first check if you get an echo. Are you using some
sort of USB to serial adapter?

With the loopback installed, try sending some bytes in Octave (for
example "hello world") and try to read it back.

-- Andy

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Loading...