root 3 年 前
コミット
c3883a335b

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "CocoRoboXDeskTop",
-  "version": "1.0.1",
+  "version": "1.0.2",
   "description": "cocorobo",
   "repository": "https://github.com/CocoRoboLabs/CocoBlockly-desktop.git",
   "scripts": {

+ 88 - 83
src/renderer/uploader.js

@@ -173,7 +173,7 @@ function getpythoval() {
                 for (let i = 0; i < results.length; i++) {
                     const val = results[i];
                     const mf = val.manufacturer;
-                    if (mf && mf.toLocaleLowerCase().indexOf('silicon') > -1) {
+                    if (mf && (mf.toLocaleLowerCase().indexOf('silicon') > -1 || mf.toLocaleLowerCase().indexOf('wch.cn') > -1)) {
                         resolve(val);
                         break;
                     }
@@ -358,12 +358,12 @@ export function pythonupload(code, val, socket) {
     return new Promise(async (resolve, reject) => {
         try {
             if (_childexec && !_childexec.killed) {
-                // try {
-                //     _childexec.stdin.write('\r\x1D');
-                // }
-                // catch (e) {
-                //     console.log(e);
-                // }
+                try {
+                    _childexec.stdin.write('\x03\x02\x03\x1D');
+                }
+                catch (e) {
+                    console.log(e);
+                }
                 _childexec.kill('SIGKILL');
                 _childexec.killed = true;
             }
@@ -385,7 +385,7 @@ export function pythonupload(code, val, socket) {
                 var _timeout = null;
                 var _strout = "";
                 var _strerr = "";
-                var arr = ["-m", "there", '--reset', "run", "-t", "6000", `${_pythonpath}`, "-p", `${val}`, "-i"];//
+                var arr = ["-m", "there", "--reset", "run", `${_pythonpath}`, "-p", `${val}`, "-i"];//
                 // exec(`cd "${pythonpath}" && /usr/local/bin/python3.8 -m there run "${_pythonname}" -p ${val} -i`, (err, stdout, stderr) =>
                 //     console.log(stderr)
                 // );
@@ -397,7 +397,7 @@ export function pythonupload(code, val, socket) {
                                 // 使用循环确保我们读取所有的可用数据。
                                 while ((chunk = _childexec.stdin.read()) !== null) {
                                     console.log(`数据: ${chunk}`);
-                                    _childexec.stdout.write('\r\x1D');
+                                    _childexec.stdout.write('\x03\x02\x03\x1D');
                                 }
                             });
                 
@@ -465,7 +465,7 @@ export function pythonupload(code, val, socket) {
                 resolve();
             }
             //resolve();
-        }, 3000);
+        }, 1000);
     });
 }
 
@@ -474,7 +474,7 @@ export function pythonupload(code, val, socket) {
 //         try {
 //             if (_childexec && !_childexec.killed) {
 //                 // try {
-//                 //     _childexec.stdin.write('\r\x1D');
+//                 //     _childexec.stdin.write('\x03\x02\x03\x1D');
 //                 // }
 //                 // catch (e) {
 //                 //     console.log(e);
@@ -498,7 +498,7 @@ export function pythonupload(code, val, socket) {
 //             var _timeout = null;
 //             var _strout = "";
 //             var _strerr = "";
-//             var arr = ["-m", "there", '--reset', "run", "-t", "6000", `${_pythonpath}`, "-p", `${val}`, "-i"];
+//             var arr = ["-m", "there",  "run", "-t", "6000", `${_pythonpath}`, "-p", `${val}`, "-i"];
 //             _childexec = spawn(_python, arr, { encoding: 'utf-8', timeout: 0 });
 //             /*
 //                         _childexec.stdin.on('readable', () => {
@@ -506,7 +506,7 @@ export function pythonupload(code, val, socket) {
 //                             // 使用循环确保我们读取所有的可用数据。
 //                             while ((chunk = _childexec.stdin.read()) !== null) {
 //                                 console.log(`数据: ${chunk}`);
-//                                 process.stdout.write('\r\x1D');
+//                                 process.stdout.write('\x03\x02\x03\x1D');
 //                             }
 //                         });
 
@@ -571,7 +571,7 @@ export function pythonupload(code, val, socket) {
 //         try {
 //             if (_childexec && !_childexec.killed) {
 //                 try {
-//                     _childexec.stdin.write('\r\x1D');
+//                     _childexec.stdin.write('\x03\x02\x03\x1D');
 //                 }
 //                 catch (e) {
 //                     console.log(e);
@@ -667,12 +667,12 @@ export function pythonuploadfile(code, namepath, val, socket) {
     return new Promise(async (resolve, reject) => {
         try {
             if (_childexec && !_childexec.killed) {
-                // try {
-                //     _childexec.stdin.write('\r\x1D');
-                // }
-                // catch (e) {
-                //     console.log(e);
-                // }
+                try {
+                    _childexec.stdin.write('\x03\x02\x03\x1D');
+                }
+                catch (e) {
+                    console.log(e);
+                }
                 _childexec.kill('SIGKILL');
                 _childexec.killed = true;
             }
@@ -710,7 +710,7 @@ export function pythonuploadfile(code, namepath, val, socket) {
                         socket.emit('repl', { code: _strout });
                     }
                     _strout = "";
-                }, 10);
+                }, 30);
             });
 
             //错误处理
@@ -725,7 +725,7 @@ export function pythonuploadfile(code, namepath, val, socket) {
                     }
                     _strerr = "";
                     //socket.emit('repl', { code: _strout });
-                }, 10);
+                }, 30);
             });
 
             //关闭处理
@@ -738,7 +738,7 @@ export function pythonuploadfile(code, namepath, val, socket) {
                 //console.log('exit code : ' + code);
             });
             resolve();
-        }, 3000);
+        }, 1000);
 
         // var cmd = `python -m there --reset push ${_pythonpath} /${_filename} -p ${val.comName}`;
         // //执行ampy
@@ -765,6 +765,12 @@ export function pythonuploadfilebyfile(file, namepath, val, socket) {
     return new Promise(async (resolve, reject) => {
         try {
             if (_childexec && !_childexec.killed) {
+                try {
+                    _childexec.stdin.write('\x03\x02\x03\x1D');
+                }
+                catch (e) {
+                    console.log(e);
+                }
                 _childexec.kill('SIGKILL');
                 _childexec.killed = true;
             }
@@ -802,7 +808,7 @@ export function pythonuploadfilebyfile(file, namepath, val, socket) {
                         socket.emit('repl', { code: _strout });
                     }
                     _strout = "";
-                }, 10);
+                }, 30);
             });
 
             //错误处理
@@ -817,7 +823,7 @@ export function pythonuploadfilebyfile(file, namepath, val, socket) {
                     }
                     _strerr = "";
                     //socket.emit('repl', { code: _strout });
-                }, 10);
+                }, 30);
             });
 
             //关闭处理
@@ -830,7 +836,7 @@ export function pythonuploadfilebyfile(file, namepath, val, socket) {
                 //console.log('exit code : ' + code);
             });
             resolve();
-        }, 3000);
+        }, 1000);
     });
 }
 
@@ -846,12 +852,12 @@ export function uploadfile(code, namepath, val, socket) {
     return new Promise(async (resolve, reject) => {
         try {
             if (_childexec && !_childexec.killed) {
-                // try {
-                //     _childexec.stdin.write('\r\x1D');
-                // }
-                // catch (e) {
-                //     console.log(e);
-                // }
+                try {
+                    _childexec.stdin.write('\x03\x02\x03\x1D');
+                }
+                catch (e) {
+                    console.log(e);
+                }
                 _childexec.kill('SIGKILL');
                 _childexec.killed = true;
             }
@@ -888,7 +894,7 @@ export function uploadfile(code, namepath, val, socket) {
                         socket.emit('repl', { code: _strout });
                     }
                     _strout = "";
-                }, 10);
+                }, 30);
             });
 
             //错误处理
@@ -903,7 +909,7 @@ export function uploadfile(code, namepath, val, socket) {
                     }
                     _strerr = "";
                     //socket.emit('repl', { code: _strout });
-                }, 10);
+                }, 30);
             });
 
             //关闭处理
@@ -916,7 +922,7 @@ export function uploadfile(code, namepath, val, socket) {
                 //console.log('exit code : ' + code);
             });
             resolve();
-        }, 3000);
+        }, 1000);
     });
 }
 
@@ -926,12 +932,12 @@ export function pythonreset(val, socket) {
     return new Promise(async (resolve, reject) => {
         try {
             if (_childexec && !_childexec.killed) {
-                // try {
-                //     _childexec.stdin.write('\r\x1D');
-                // }
-                // catch (e) {
-                //     console.log(e);
-                // }
+                try {
+                    _childexec.stdin.write('\x03\x02\x03\x1D');
+                }
+                catch (e) {
+                    console.log(e);
+                }
                 _childexec.kill('SIGKILL');
                 _childexec.killed = true;
             }
@@ -959,7 +965,7 @@ export function pythonreset(val, socket) {
                         socket.emit('repl', { code: _strout });
                     }
                     _strout = "";
-                }, 10);
+                }, 30);
             });
 
             //错误处理
@@ -974,7 +980,7 @@ export function pythonreset(val, socket) {
                     }
                     _strerr = "";
                     //socket.emit('repl', { code: _strout });
-                }, 10);
+                }, 30);
             });
 
             //关闭处理
@@ -987,7 +993,7 @@ export function pythonreset(val, socket) {
                 //console.log('exit code : ' + code);
             });
             resolve();
-        }, 3000);
+        }, 1000);
 
 
         // //发送文件给micropython板子
@@ -1006,12 +1012,12 @@ export function getmcnty(val, socket) {
     return new Promise(async (resolve, reject) => {
         try {
             if (_childexec && !_childexec.killed) {
-                // try {
-                //     _childexec.stdin.write('\r\x1D');
-                // }
-                // catch (e) {
-                //     console.log(e);
-                // }
+                try {
+                    _childexec.stdin.write('\x03\x02\x03\x1D');
+                }
+                catch (e) {
+                    console.log(e);
+                }
                 _childexec.kill('SIGKILL');
                 _childexec.killed = true;
             }
@@ -1049,7 +1055,7 @@ export function getmcnty(val, socket) {
                         }
                         socket.emit('repl', { code: _strout });
                         _strout = "";
-                    }, 10);
+                    }, 30);
                 });
 
                 //错误处理
@@ -1065,7 +1071,7 @@ export function getmcnty(val, socket) {
                         }
                         _strerr = "";
                         //socket.emit('repl', { code: _strout });
-                    }, 10);
+                    }, 30);
                 });
 
                 //关闭处理
@@ -1078,7 +1084,7 @@ export function getmcnty(val, socket) {
                     //console.log('exit code : ' + code);
                 });
             }
-        }, 3000);
+        }, 1000);
     });
 }
 
@@ -1099,12 +1105,12 @@ export function pythoncmd(code, val, socket) {
     return new Promise(async (resolve, reject) => {
         try {
             if (_childexec && !_childexec.killed) {
-                // try {
-                //     _childexec.stdin.write('\r\x1D');
-                // }
-                // catch (e) {
-                //     console.log(e);
-                // }
+                try {
+                    _childexec.stdin.write('\x03\x02\x03\x1D');
+                }
+                catch (e) {
+                    console.log(e);
+                }
                 _childexec.kill('SIGKILL');
                 _childexec.killed = true;
             }
@@ -1113,31 +1119,30 @@ export function pythoncmd(code, val, socket) {
             console.log(e);
         }
         //发送文件给micropython板子
-        //var val = await getpythoval().catch(e => err = e);
         setTimeout(function () {
             var _timeout = null;
             var _strout = "";
             var _strerr = "";
-            var arr = ["-m", "there", '--reset', "-c", `${code}`, "-p", `${val}`];
+            var arr = ["-m", "there", "-c", `${code}`, "-p", `${val}`];
             _childexec = spawn(_python, arr, { encoding: 'utf-8', timeout: 0 });
             //成功执行获取值处理
             _childexec.stdout.on('data', function (chunk) {
                 clearTimeout(_timeout);
                 _strout += chunk.toString();
                 _timeout = setTimeout(() => {
-                    // if (_strout.indexOf("Error") > -1) {
-                    //     reject(_strout);
-                    //     let error = errHandler(_strout);
-                    //     socket.emit('upload', { ProgrammerStatus: 'Error', Error: error });
-                    // }
-                    // else {
-                    //     resolve(_strout);
-                    //     socket.emit('repl', { code: _strout });
-                    // }
+                    if (_strout.indexOf("Error") > -1) {
+                        reject(_strout);
+                        let error = errHandler(_strout);
+                        socket.emit('upload', { ProgrammerStatus: 'Error', Error: error });
+                    }
+                    else {
+                        resolve(_strout);
+                        socket.emit('repl', { code: _strout });
+                    }
                     //
-                    resolve();
-                    //_strout = "";
-                }, 100);
+                    // resolve(_strout);
+                    _strout = "";
+                }, 30);
             });
 
             //错误处理
@@ -1145,15 +1150,15 @@ export function pythoncmd(code, val, socket) {
                 clearTimeout(_timeout);
                 _strerr += data.toString();
                 _timeout = setTimeout(() => {
-                    // if (_strerr.indexOf("SPIFFS") == -1 && _strerr.indexOf("ClearCommError") == -1 && (_strerr.indexOf("ERROR") > -1 || _strerr.indexOf("Error") > -1)) {
-                    //     reject(_strerr);
-                    //     let error = errHandler(_strerr);
-                    //     socket.emit('upload', { ProgrammerStatus: 'Error', Error: error });
-                    // }
-                    // _strerr = "";
-                    resolve();
+                    if (_strerr.indexOf("SPIFFS") == -1 && _strerr.indexOf("ClearCommError") == -1 && (_strerr.indexOf("ERROR") > -1 || _strerr.indexOf("Error") > -1)) {
+                        reject(_strerr);
+                        let error = errHandler(_strerr);
+                        socket.emit('upload', { ProgrammerStatus: 'Error', Error: error });
+                    }
+                    _strerr = "";
+                    // resolve(_strerr);
                     //socket.emit('repl', { code: _strout });
-                }, 10);
+                }, 30);
             });
 
             //关闭处理
@@ -1166,7 +1171,7 @@ export function pythoncmd(code, val, socket) {
                 //console.log('exit code : ' + code);
             });
 
-        }, 3000);
+        }, 1000);
     });
 }
 
@@ -1177,7 +1182,7 @@ function spawnlisten(spawnObj) {
         // 使用循环确保我们读取所有的可用数据。
         while ((chunk = _childexec.stdin.read()) !== null) {
             console.log(`数据: ${chunk}`);
-            process.stdout.write('\r\x1D');
+            process.stdout.write('\x03\x02\x03\x1D');
         }
     });
 

+ 1 - 1
src/static/win/python/python-3.7.3-embed-win32/Lib/site-packages/there/repl_connection.py

@@ -136,7 +136,7 @@ class MicroPythonRepl(object):
         self.serial.rts = False
         self.serial.dsrdtr = False
         self.serial.rtscts = False
-        self.serial.readlines()
+        self.serial.read(99999)
         if user is not None:
             time.sleep(0.1)
             self.serial.read_until(b'Login as: ')

+ 1 - 1
src/static/win/python/python-3.8.3-embed-amd64/Lib/site-packages/there/repl_connection.py

@@ -136,7 +136,7 @@ class MicroPythonRepl(object):
         self.serial.rts = False
         self.serial.dsrdtr = False
         self.serial.rtscts = False
-        self.serial.readlines()
+        self.serial.read(99999)
         if user is not None:
             time.sleep(0.1)
             self.serial.read_until(b'Login as: ')