Comments (41)
@bilikyar 这样改的话就OK了,测试没问题,注意调用board.shutdown()方法解除对tty的占用并结束线程
@wwj718
import zmq
import subprocess
import pathlib
import platform
import time
import threading
import os
import asyncio
from time import sleep
from pymata_aio.pymata3 import PyMata3
from pymata_aio.constants import Constants
from codelab_adapter.utils import ui_error
from codelab_adapter.core_extension import Extension
from codelab_adapter import settings
from codelab_adapter.utils import threaded
def get_python3_path():
# If it is not working, Please replace python3_path with your local python3 path. shell: which python3
if (platform.system() == "Darwin"):
# which python3
# 不如用PATH python
# 不确定
path = "/usr/local/bin/python3"
if platform.system() == "Windows":
path = "python3"
if platform.system() == "Linux":
path = "/usr/bin/python3"
return path
python3_path = get_python3_path()
class arduinoExtension(Extension):
def __init__(self):
name = type(self).__name__
super().__init__(name)
def boardaction(self):
self.board = PyMata3()
BOARD_LED = 13
self.board.set_pin_mode(BOARD_LED, Constants.OUTPUT)
print("LED On")
self.board.digital_write(BOARD_LED, 1)
self.board.sleep(1.0)
print("LED Off")
self.board.digital_write(BOARD_LED, 0)
self.board.sleep(1.0)
self.board.shutdown()
print("finished")
@threaded
def task(self):
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(self.boardaction())
loop.run_forever()
def run(self):
self.task()
while self._running:
pass
export = arduinoExtension
from codelab_adapter_extensions.
现在的问题说明:
1.这是我目前的插件测试代码
import zmq import subprocess import pathlib import platform import time import threading import os from time import sleep from pymata_aio.pymata3 import PyMata3 from pymata_aio.constants import Constants from codelab_adapter.utils import ui_error from codelab_adapter.core_extension import Extension from codelab_adapter import settings def get_python3_path(): # If it is not working, Please replace python3_path with your local python3 path. shell: which python3 if (platform.system() == "Darwin"): # which python3 # 不如用PATH python # 不确定 path = "/usr/local/bin/python3" if platform.system() == "Windows": path = "python3" if platform.system() == "Linux": path = "/usr/bin/python3" return path python3_path = get_python3_path() class arduinoExtension(Extension): def __init__(self): name = type(self).__name__ super().__init__(name) board = PyMata3() BOARD_LED = 13 board.set_pin_mode(BOARD_LED, Constants.OUTPUT) print("LED On") board.digital_write(BOARD_LED, 1) board.sleep(1.0) print("LED Off") board.digital_write(BOARD_LED, 0) board.sleep(1.0) def run(self): pass while self._running: pass export = arduinoExtension2.通过命令行的方式运行adapter在ubuntu第一次启动插件,能运行成功,以下是成功信息:
pymata_aio Version 2.30 Copyright (c) 2015-2018 Alan Yorinks All rights reserved. Using COM Port:/dev/ttyACM0 Initializing Arduino - Please wait... 2019-05-29 14:49:28,756 - INFO - [socketio_server.py:293:background_task2] - - sub: arduinoExtension-30871 Arduino Firmware ID: 2.5 StandardFirmataPlus.ino Auto-discovery complete. Found 20 Digital Pins and 6 Analog Pins LED On LED Off 2019-05-29 14:49:38,050 - DEBUG - [gui.py:380:_handle_extension_checkbox] - - extension checkbox:extension_arduino_nano is clicked; value:0 2019-05-29 14:49:38,050 - DEBUG - [core_extension.py:65:publish] - - publish: {'topic': '__control', 'payload': 'terminate', 'type': 'adapter'} 2019-05-29 14:49:38,051 - DEBUG - [socketio_server.py:253:background_task] - - sensor_sub recv: {'topic': '__control', 'payload': 'terminate', 'type': 'adapter'}3.关闭插件,重开就会报以下错误,adapter自动关闭:
pymata_aio Version 2.30 Copyright (c) 2015-2018 Alan Yorinks All rights reserved. Using COM Port:/dev/ttyACM0 Initializing Arduino - Please wait... 2019-05-29 14:49:41,896 - INFO - [socketio_server.py:293:background_task2] - - sub: arduinoExtension-30825 _report_firmware() missing 1 required positional argument: 'sysex_data' Shutting down ...
这个我测试了一下,主要是firmata的串口操作导致的,第一次连接成功;第二次连接枚举失败,目前比较傻瓜的解决方案是每次启动插件的时候,重新烧录一遍固件
from codelab_adapter_extensions.
这个问题的解决方案是avrdude,arduino的本身就是调用此模块来烧录程序的。
from codelab_adapter_extensions.
为了完善的Arduino插件,我们需要一下几点(有遗漏,欢迎补充):
- 需要印度这所学校用的操作系统的版本和Arduino的型号(nano 还是 uno),也就是简单的需求收集工作这点 @wwj718 能否麻烦你跟他们问一问呢?
- 完善adapter arduino插件,实现如果对于没有固件的arduino板子,进行自动烧录的工作。这个部分我比较熟我可以完成。
- 完善arduino的scratch部分的插件,然后我在考虑是否需要翻译插件为印地语,这个与需要根据印度那边的给我们的反馈。
from codelab_adapter_extensions.
Arduino nano with chg340 driver chip.
using python 3.7.
Os Ubuntu 18.04 64 bit.
Python is in default path of Ubuntu.
from codelab_adapter_extensions.
好的,那现在的主要问题就是自动烧录固件了。
from codelab_adapter_extensions.
Ubuntu上自动烧录固件功能已完成,现在需要跟之前的插件进行整合。
from codelab_adapter_extensions.
开发引导
前端Scratch插件
CodeLab Adapter extension
from codelab_adapter_extensions.
这样就清楚了
from codelab_adapter_extensions.
@bilikyar 关于第三点,我觉得使用英文就行了,英语在印度使用广泛。
from codelab_adapter_extensions.
@wwj718 我在ubuntu 18.04 上使用下面的方式启动插件的时候,adapter直接崩溃,你在打包pymata_aio 的时候进行测试过吗?
import zmq
import subprocess
import pathlib
import platform
import time
import threading
from time import sleep
from codelab_adapter import settings
from codelab_adapter.core_extension import Extension
from pymata_aio.pymata3 import PyMata3
from pymata_aio.constants import Constants
class arduinoExtension(Extension):
def __init__(self):
name = type(self).__name__
super().__init__(name)
board = PyMata3()
from codelab_adapter_extensions.
@bilikyar 我到ubuntu下测试一下,我在mac和windows下测试过
from codelab_adapter_extensions.
@bilikyar 我刚在ubuhntu16.04 64bit下测试,
from pymata_aio.pymata3 import PyMata3
from pymata_aio.constants import Constants
是正常的
board = PyMata3()触发了错误:
pymata_aio Version 2.30 Copyright (c) 2015-2018 Alan Yorinks All rights reserved.
Unable to find Serial Port, Please plug in cable or check cable connections.
你可以在adapter之外先测试 PyMata3()
from codelab_adapter_extensions.
adapter之外運行是沒問題的
from codelab_adapter_extensions.
@bilikyar 我在adapter之外运行也是一样的错误呢
from codelab_adapter_extensions.
你试试使用命令行运行,看错误信息
from codelab_adapter_extensions.
现在的问题说明:
1.这是我目前的插件测试代码
import zmq
import subprocess
import pathlib
import platform
import time
import threading
import os
from time import sleep
from pymata_aio.pymata3 import PyMata3
from pymata_aio.constants import Constants
from codelab_adapter.utils import ui_error
from codelab_adapter.core_extension import Extension
from codelab_adapter import settings
def get_python3_path():
# If it is not working, Please replace python3_path with your local python3 path. shell: which python3
if (platform.system() == "Darwin"):
# which python3
# 不如用PATH python
# 不确定
path = "/usr/local/bin/python3"
if platform.system() == "Windows":
path = "python3"
if platform.system() == "Linux":
path = "/usr/bin/python3"
return path
python3_path = get_python3_path()
class arduinoExtension(Extension):
def __init__(self):
name = type(self).__name__
super().__init__(name)
board = PyMata3()
BOARD_LED = 13
board.set_pin_mode(BOARD_LED, Constants.OUTPUT)
print("LED On")
board.digital_write(BOARD_LED, 1)
board.sleep(1.0)
print("LED Off")
board.digital_write(BOARD_LED, 0)
board.sleep(1.0)
def run(self):
pass
while self._running:
pass
export = arduinoExtension
2.通过命令行的方式运行adapter在ubuntu第一次启动插件,能运行成功,以下是成功信息:
pymata_aio Version 2.30 Copyright (c) 2015-2018 Alan Yorinks All rights reserved.
Using COM Port:/dev/ttyACM0
Initializing Arduino - Please wait... 2019-05-29 14:49:28,756 - INFO - [socketio_server.py:293:background_task2] - - sub: arduinoExtension-30871
Arduino Firmware ID: 2.5 StandardFirmataPlus.ino
Auto-discovery complete. Found 20 Digital Pins and 6 Analog Pins
LED On
LED Off
2019-05-29 14:49:38,050 - DEBUG - [gui.py:380:_handle_extension_checkbox] - - extension checkbox:extension_arduino_nano is clicked; value:0
2019-05-29 14:49:38,050 - DEBUG - [core_extension.py:65:publish] - - publish: {'topic': '__control', 'payload': 'terminate', 'type': 'adapter'}
2019-05-29 14:49:38,051 - DEBUG - [socketio_server.py:253:background_task] - - sensor_sub recv: {'topic': '__control', 'payload': 'terminate', 'type': 'adapter'}
3.关闭插件,重开就会报以下错误,adapter自动关闭:
pymata_aio Version 2.30 Copyright (c) 2015-2018 Alan Yorinks All rights reserved.
Using COM Port:/dev/ttyACM0
Initializing Arduino - Please wait... 2019-05-29 14:49:41,896 - INFO - [socketio_server.py:293:background_task2] - - sub: arduinoExtension-30825
_report_firmware() missing 1 required positional argument: 'sysex_data'
Shutting down ...
from codelab_adapter_extensions.
@bilikyar 比力 我猜和插件的加载机制有关,看起来是资源没有释放,我看看插件加载机制,稍后给你反馈
from codelab_adapter_extensions.
@zhouF96 你看下这个问题
from codelab_adapter_extensions.
@bilikyar 我刚才梳理过了插件的生命周期 :
勾选插件:
- import 对应python模块(extension_xxx.py)
- 实例化类(arduinoExtension)
- 将run方法运行为线程
取消勾选: 将self.__running设置为false
from codelab_adapter_extensions.
init(self):方法中应该只包含插件的基本信息,不占用端口资源等,与外界交互的逻辑部分/或有资源释放的部分应该写在run(self):方法下,run方法中,gui界面打勾的话,调用插件的run方法,并且将插件的self._running设置为true,不打勾的话,跳出self._running的循环,在循环后释放资源。
from codelab_adapter_extensions.
import zmq
import subprocess
import pathlib
import platform
import time
import threading
import os
from time import sleep
from pymata_aio.pymata3 import PyMata3
from pymata_aio.constants import Constants
from codelab_adapter.utils import ui_error
from codelab_adapter.core_extension import Extension
from codelab_adapter import settings
def get_python3_path():
# If it is not working, Please replace python3_path with your local python3 path. shell: which python3
if (platform.system() == "Darwin"):
# which python3
# 不如用PATH python
# 不确定
path = "/usr/local/bin/python3"
if platform.system() == "Windows":
path = "python3"
if platform.system() == "Linux":
path = "/usr/bin/python3"
return path
python3_path = get_python3_path()
class arduinoExtension(Extension):
def __init__(self):
name = type(self).__name__
super().__init__(name)
def run(self):
board = PyMata3()
BOARD_LED = 13
board.set_pin_mode(BOARD_LED, Constants.OUTPUT)
while self._running:
print("LED On")
board.digital_write(BOARD_LED, 1)
board.sleep(1.0)
print("LED Off")
board.digital_write(BOARD_LED, 0)
board.sleep(1.0)
export = arduinoExtension
from codelab_adapter_extensions.
@zhouF96
现在报了以下错误:
Exception in thread 1559120970.4316733:
Traceback (most recent call last):
File "threading.py", line 916, in _bootstrap_inner
File "threading.py", line 864, in run
File "codelab_adapter/core_extension.py", line 92, in start_as_thread
File "/home/bilikyar/codelab_adapter/extensions/extension_arduino_nano.py", line 45, in run
board = PyMata3()
File "site-packages/pymata_aio/pymata3.py", line 67, in __init__
File "asyncio/events.py", line 694, in get_event_loop
File "asyncio/events.py", line 602, in get_event_loop
RuntimeError: There is no current event loop in thread '1559120970.4316733'.
2019-05-29 17:09:30,840 - INFO - [socketio_server.py:293:background_task2] - - sub: arduinoExtension-30843
from codelab_adapter_extensions.
@zhouF96 在python的线程中需要这样运行协程: https://github.com/Scratch3Lab/codelab_adapter_extensions/blob/master/extension_mqtt_broker.py#L37
from codelab_adapter_extensions.
上海一家硬件公司开放的插件: https://github.com/Scratch3Lab/codelab_adapter_extensions/blob/master/extension_robofriends.py,
基于makeblock开放的arduino firmata项目
from codelab_adapter_extensions.
为了完善的Arduino插件,我们需要一下几点(有遗漏,欢迎补充):
- 需要印度这所学校用的操作系统的版本和Arduino的型号(nano 还是 uno),也就是简单的需求收集工作这点 @wwj718 能否麻烦你跟他们问一问呢?
- 完善adapter arduino插件,实现如果对于没有固件的arduino板子,进行自动烧录的工作。这个部分我比较熟我可以完成。
- 完善arduino的scratch部分的插件,然后我在考虑是否需要翻译插件为印地语,这个与需要根据印度那边的给我们的反馈。
adapter arduino插件如何实现arduino编译和烧录的呢?调用arduino官方自带的gcc exe编译器?
from codelab_adapter_extensions.
@bilikyar @zhouF96 @jatsmulator 可能比我更清楚 @zfm076 提出的这个问题, 是否能给出一些回答?
from codelab_adapter_extensions.
@bilikyar @zhouF96 @jatsmulator 可能比我更清楚 @zfm076 提出的这个问题, 是否能给出一些回答?
谢谢你们抽空回答我的问题。现在我在本地电脑已经完成了arduino的编译下载的exe程序开发。其实也是调用了arduino自带的gcc、avrdude的工具用python做一个exe文件而已。然后现在准备开发一套arduino的scratch blocks,按照网上的教程在我电脑搭建好了scratch-blocks、scratch-gui、scratch-vm。也编译通过了,网页也能打开scratch的编辑器了。 然后下一步就不懂怎么开发我想要的block了,也就是我要是想添加一个arduino的block 应该改哪些东西呢?有木有参考资料额?谢谢
from codelab_adapter_extensions.
你可以参考这个文章,然后你可以看看其他这个博客里文章,会对你比较有帮助。
from codelab_adapter_extensions.
你可以参考这个文章,然后你可以看看其他这个博客里文章,会对你比较有帮助。
谢谢,我按照文章里面操作。
在Cmder输入以下提示 不是命令。所以打不开编辑器呢?
λ webpack-dev-server --https
'webpack-dev-server' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
from codelab_adapter_extensions.
你可以参考这个文章,然后你可以看看其他这个博客里文章,会对你比较有帮助。
谢谢,我按照文章里面操作。
在Cmder输入以下提示 不是命令。所以打不开编辑器呢?
λ webpack-dev-server --https
'webpack-dev-server' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
npm install -g yarn
npm install -g webpack
npm install -g webpack-dev-server
mkdir Scratch3 #
cd Scratch3
git clone https://github.com/LLK/scratch-gui 这些步骤已经做了额
from codelab_adapter_extensions.
你可以参考这个文章,然后你可以看看其他这个博客里文章,会对你比较有帮助。
谢谢,我按照文章里面操作。
在Cmder输入以下提示 不是命令。所以打不开编辑器呢?
λ webpack-dev-server --https
'webpack-dev-server' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
λ yarn install
'yarn' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
from codelab_adapter_extensions.
你可以参考这个文章,然后你可以看看其他这个博客里文章,会对你比较有帮助。
谢谢,我按照文章里面操作。
在Cmder输入以下提示 不是命令。所以打不开编辑器呢?
λ webpack-dev-server --https
'webpack-dev-server' 不是内部或外部命令,也不是可运行的程序
或批处理文件。λ yarn install
'yarn' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
这个问题是没添加环境变量,添加即可。
from codelab_adapter_extensions.
yarn你需要单独安装,这是像npm的包管理系统。
from codelab_adapter_extensions.
yarn你需要单独安装,这是像npm的包管理系统。
yarn已经安装完毕。webpack-dev-server --https这个也要单独安装?
from codelab_adapter_extensions.
你可以通过yarn add webpack-dev-server 命令来安装; yarn add 命令在功能上等同于npm install
from codelab_adapter_extensions.
npm install
我已经运行这个命令安装了的:npm install webpack-dev-server 。然后往终端输入λ nwebpack-dev-server 还是提示这个不是命令。
'webpack-dev-server' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
from codelab_adapter_extensions.
npm install
我已经运行这个命令安装了的:npm install webpack-dev-server 。然后往终端输入λ nwebpack-dev-server 还是提示这个不是命令。
'webpack-dev-server' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
然后我参照 "scripts": {
"start:dev": "webpack-dev-server"
}
往package.json添加以上信息在运行。这个指令:npm run start:dev 然后输出以下信息,还有很多我没复制出来。然后我在网页上打开 https://0.0.0.0:8601/ 却提示您访问的网页出错了!打不开额。
[email protected] start:dev E:\molok\arduino\scratch3.0\scratch\scratch-gui
webpack-dev-server --https
i 「wds」: Generating SSL Certificate
i 「wds」: Project is running at https://0.0.0.0:8601/
i 「wds」: webpack output is served from /
i 「wds」: Content not from webpack is served from E:\molok\arduino\scratch3.0\scratch\scratch-gui\build
Replace Autoprefixer browsers option to Browserslist config.
Use browserslist key in package.json or .browserslistrc file.
Using browsers option cause some error. Browserslist config
can be used for Babel, Autoprefixer, postcss-normalize and other tools.
If you really need to use option, rename it to overrideBrowserslist.
Learn more at:
https://github.com/browserslist/browserslist#readme
https://twitter.com/browserslist
from codelab_adapter_extensions.
npm install
我已经运行这个命令安装了的:npm install webpack-dev-server 。然后往终端输入λ nwebpack-dev-server 还是提示这个不是命令。
'webpack-dev-server' 不是内部或外部命令,也不是可运行的程序
或批处理文件。然后我参照 "scripts": {
"start:dev": "webpack-dev-server"
}
往package.json添加以上信息在运行。这个指令:npm run start:dev 然后输出以下信息,还有很多我没复制出来。然后我在网页上打开 https://0.0.0.0:8601/ 却提示您访问的网页出错了!打不开额。[email protected] start:dev E:\molok\arduino\scratch3.0\scratch\scratch-gui
webpack-dev-server --httpsi 「wds」: Generating SSL Certificate
i 「wds」: Project is running at https://0.0.0.0:8601/
i 「wds」: webpack output is served from /
i 「wds」: Content not from webpack is served from E:\molok\arduino\scratch3.0\scratch\scratch-gui\buildReplace Autoprefixer browsers option to Browserslist config.
Use browserslist key in package.json or .browserslistrc file.Using browsers option cause some error. Browserslist config
can be used for Babel, Autoprefixer, postcss-normalize and other tools.If you really need to use option, rename it to overrideBrowserslist.
Learn more at:
https://github.com/browserslist/browserslist#readme
https://twitter.com/browserslist
咦?奇怪 居然能打开https://127.0.0.1:8601。。。 它上面不是说Project is running at https://0.0.0.0:8601/ 在这个网址上运行的么?
from codelab_adapter_extensions.
你可以参考这个文章,然后你可以看看其他这个博客里文章,会对你比较有帮助。
你好,我想在网页端实现拖动block在右边显示出ardunio的代码。现在网页端block已经搭好了,不懂怎么将对应的block和实际的arduino代码对应起来。不懂需要设置scratch源码哪些地方。应该看哪方面的资料额?
from codelab_adapter_extensions.
@zfm076 https://blog.just4fun.site/blockly-dev-hello-world.html
from codelab_adapter_extensions.
Related Issues (20)
- cmder下载后出问题,运行不成,文件坏了 HOT 6
- 证书更新 HOT 4
- pyinstaller 3.5 增加 jupyterlab的钩子 HOT 2
- 关于树莓派插件 HOT 3
- 除了EIM之外其他的scratch插件在哪能看到呢? HOT 4
- 更新codelab-adapter-mac-2_5_3之后使用cozmo插件出下面的提示 HOT 5
- 在windows下运行python-kernel-extension错误 HOT 4
- Extension_vector HOT 2
- Physical Blocks Scratch HOT 1
- 发现physical blocks 2.0中json列表是从右往左取的
- Extension中執行到while循環來執行攝像頭數據讀取后,疑似綫程阻塞導致插件無法响應後面的eim消息, 請教有沒有什麽辦法可以解決? HOT 2
- 请问下codelab可以打包成exe在本地运行吗? HOT 2
- 请教下 本项目和下载版本的区别 HOT 1
- 请问toio是通过什么方式连接的。 HOT 1
- 同时使用多个相同的MarkerID
- 希望把ESP32接入codelab,但是没有成功,能否给予一些例子。 HOT 4
- 请求大师adapter连接Arduino不成功总显示none type object HOT 6
- 老师,路过的好心人,能帮看看Arduino连接的nonetype错吗 HOT 1
- Scratch3 Alphamini extension and enabling other features HOT 9
- 可以看到Extension和Node具体实现差异么 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from codelab_adapter_extensions.