Serial Print from for loop

1 view (last 30 days)
Brianne Behr
Brianne Behr on 3 Dec 2014
Hi,
I'm trying to send G'Code from a matlab for loop but I keep receiving error messages. I have included my code below which will make much more sense than me trying explaining. Any advice would be greatly appreciated. Thanks!
delete(instrfindall)
prod1 = 'G01 X-2.0 F2';
if true
% code
end
prod2 = 'G01 X-1.0 F.5';
order = {prod1, prod2};
s=serial('/dev/tty.usbmodemfa141'); %open serial port for x/y traverse
set(s,'BaudRate',115200);
fopen(s);
fprintf(s,'G17 G20 G90 G94 G54')
out=fscanf(s)
dims = ndims(order);
for index = 1:dims
fwrite(s,order(index))
%a= order(index) _> tried this.. doesn't work
%fprintf(s,'%c',a)
%fwrite(s,prod2) -> This works
out=fscanf(s)
fprintf(s,'G4 P5') %pause to collect product
out=fscanf(s)
end
fclose(s)

Answers (0)

Community Treasure Hunt

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

Start Hunting!