Blockly.JavaScript.ORDER_COMMA) || '0';
var e = Blockly.JavaScript.valueToCode(block, 'E',
Blockly.JavaScript.ORDER_COMMA) || '0';
- return `await deviceMoveTo(${a}, ${b}, ${c}, ${d}, ${e});\n`
+ return `if (!await deviceMoveTo(${a}, ${b}, ${c}, ${d}, ${e})) return false;\n`
};
Blockly.JavaScript['gripper'] = block => {
var f = Blockly.JavaScript.valueToCode(block, 'F',
Blockly.JavaScript.ORDER_COMMA) || '0';
- return `await deviceGripper(${f});\n`
+ return `if (!await deviceGripper(${f})) return false;\n`
};
Blockly.JavaScript['delay'] = block => {
var millisecs = Blockly.JavaScript.valueToCode(block, 'millisecs',
Blockly.JavaScript.ORDER_COMMA) || '0';
- return `await deviceDelay(${millisecs});\n`
+ return `if (!await deviceDelay(${millisecs})) return false;\n`
};
var blockly_stop = false;
Blockly.JavaScript.INFINITE_LOOP_TRAP =
- 'await deviceDelay(0);\n'
+ 'if (!await deviceDelay(0)) return false;\n'
var toolbox = document.getElementById('toolbox');
var blocklyArea = document.getElementById('blocklyArea');
var deviceMoveTo = async (a, b, c, d, e) => {
if (blockly_stop) {
- console.log('stop in deviceMoveTo()')
- throw new Error('stopped')
- console.log('can\'t get here')
+ console.log('stop in deviceMoveTo()');
+ return false;
}
- console.assert(!blockly_stop, '!blockly_stop')
- await move_axes([500, 500, 500, 500, 500], [a, b, c, d, e])
+ await move_axes([500, 500, 500, 500, 500], [a, b, c, d, e]);
+ return true;
}
var deviceGripper = async f => {
if (blockly_stop) {
console.log('stop in deviceGripper()')
- throw new Error('stopped')
- console.log('can\'t get here')
+ return false;
}
- console.assert(!blockly_stop, '!blockly_stop')
- await move_axis(5, 500, f)
+ await move_axis(5, 500, f);
+ return true;
}
var deviceDelay = async millisecs => {
if (blockly_stop) {
- console.log('stop in deviceDelay()')
- throw new Error('stopped')
- console.log('can\'t get here')
+ console.log('stop in deviceDelay()');
+ return false;
}
- console.assert(!blockly_stop, '!blockly_stop')
- await sleep(millisecs)
+ await sleep(millisecs);
+ return true;
}
document.getElementById('reset').addEventListener(
var code =
`(
async () => {
- try {
-${Blockly.JavaScript.workspaceToCode(workspace)} }
- catch (err) {
- console.log('warning', err.message);
- }
+ if (
+ !await (
+ async () => {
+${Blockly.JavaScript.workspaceToCode(workspace)} return true;
+ }
+ )()
+ )
+ console.log('aborted')
blockly_active = false;
device_busy = false;
document.getElementById('run-stop').innerHTML = 'Run';