|
54 | 54 | ## reprogram the arduino
|
55 | 55 | ## @item port (read only)
|
56 | 56 | ## the communications port the board is connected to.
|
| 57 | + ## @item baudrate (read only) |
| 58 | + ## the communications baudrate to the board. |
57 | 59 | ## @item board (read only)
|
58 | 60 | ## The name of the board type that the arduino connected to
|
59 | 61 | ## @item libraries (read only)
|
|
84 | 86 | AnalogReference = 5.0;
|
85 | 87 | Board = "";
|
86 | 88 | Port = "";
|
| 89 | + BaudRate = 9600; |
87 | 90 | endproperties
|
88 | 91 |
|
89 | 92 | properties (SetAccess = private, Hidden = true)
|
|
101 | 104 | endif
|
102 | 105 |
|
103 | 106 | this.name = "arduino";
|
| 107 | + c = arduinoio.getBoardConfig(arduinos{1}.board); |
| 108 | + this.BaudRate = c.baudrate; |
104 | 109 | this = __initArduino__ (this, arduinos{1}.port, arduinos{1}.board);
|
105 | 110 | elseif (nargin == 1)
|
106 | 111 | arg0 = varargin{1};
|
|
129 | 134 | endif
|
130 | 135 | port = arduinos{1}.port;
|
131 | 136 | board = arduinos{1}.board;
|
| 137 | + c = arduinoio.getBoardConfig(arduinos{1}.board); |
| 138 | + this.BaudRate = c.baudrate; |
132 | 139 | elseif !ischar (port)
|
133 | 140 | error ("arduino: port must be a string");
|
134 | 141 | endif
|
|
148 | 155 | requiredlibs = {};
|
149 | 156 | forcebuild = false;
|
150 | 157 | forcebuildon = false;
|
| 158 | + |
151 | 159 | for i = 3:2:nargin
|
152 | 160 | propname = tolower (varargin{i});
|
153 | 161 | propvalue = varargin{i+1};
|
|
174 | 182 | error ("arduino: expect forcebuildon to be true or false");
|
175 | 183 | endif
|
176 | 184 | endif
|
| 185 | + if strcmp (propname,"baudrate") |
| 186 | + if !isnumeric(propvalue) |
| 187 | + error ("arduino: expect baudrate to be numeric"); |
| 188 | + else |
| 189 | + this.BaudRate = int32(propvalue); |
| 190 | + if this.BaudRate < 1200 |
| 191 | + error ("arduino: Invalid baudrate"); |
| 192 | + endif |
| 193 | + endif |
| 194 | + endif |
177 | 195 | # older option that probally should remove
|
178 | 196 | if strcmp (propname,"forcebuild")
|
179 | 197 | if islogical (propvalue) || (isnumeric(propvalue) && (propvalue == 1 || propvalue == 0))
|
|
217 | 235 | # free arduino resources, reprom and then reinit
|
218 | 236 | this = __freeArduino__(this);
|
219 | 237 |
|
220 |
| - if !arduinosetup ('libraries', requiredlibs); |
| 238 | + if !arduinosetup ('libraries', requiredlibs, 'baudrate', this.BaudRate) |
221 | 239 | error ("arduinosetup returned a failure, so did not reprogram")
|
222 | 240 | endif
|
223 | 241 |
|
|
0 commit comments