-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRead_directly_from_Arduino_Octave.m
71 lines (63 loc) · 1.95 KB
/
Read_directly_from_Arduino_Octave.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
% Raphael BOICHOT 11/08/2021 Game Boy printer emulator
% This script directly handle the Arduino from Matlab
% for any question : [email protected]
% for end of transmission, simply reboot the Arduino
clear
clc
disp('-----------------------------------------------------------')
disp('|Beware, this code is for GNU Octave ONLY !!! |')
disp('|Beware, this code is not yet compatible Matlab Mobile !!!|')
disp('|Reboot Arduino to end transmission |')
disp('-----------------------------------------------------------')
pkg load image
pkg load instrument-control
list = serialportlist;
valid_port=[];
protocol_failure=1;
for i =1:1:length(list)
disp(['Testing port ',char(list(i)),'...'])
s = serialport(char(list(i)),'BaudRate',115200);
set(s, 'timeout',2);
flush(s);
response=char(read(s, 100));
if ~isempty(response)
if strcmp(response(4:18),'GAMEBOY PRINTER')
disp(['Arduino detected on port ',char(list(i))])
valid_port=char(list(i));
beep ()
protocol_failure=0;
end
end
clear s
end
if protocol_failure==0
arduinoObj = serialport(valid_port,'baudrate',115200,'timeout',-1); %set the Arduino com port here
%configureTerminator(arduinoObj,"CR/LF");
flush(arduinoObj);
set(arduinoObj, 'timeout',-1);
flag=0;
str='Packet Capture V3';
while flag==0
data = ReadToTermination(arduinoObj);
fprintf(data)
if not(isempty(strfind(data,str)))
flag=1;
end
end
fid=fopen('Entry_file.txt','w');
str='Packet Capture V3';
flag=0;
while flag==0
data = ReadToTermination(arduinoObj);
fprintf(data)
fprintf(fid,'%s\r\n',data);
if not(isempty(strfind(data,str)));
flag=1;
end
end
fclose(fid);
disp('Normal termination, printing the images...')
run Main_Decoder.m
else
disp('Arduino not detected')
end