没有合适的资源?快使用搜索试试~ 我知道了~
scratch图形化编程操作硬件.docx
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 139 浏览量
2024-05-17
10:34:45
上传
评论
收藏 32KB DOCX 举报
温馨提示
![preview](https://dl-preview.csdnimg.cn/89319106/0001-104f874d828fe432e2e2462246c9e736_thumbnail-wide.jpeg)
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
试读
3页
scratch是一款又麻省理工开发的图形化编程软件,这款软件提供了可以使用javascript与scratch交互的接口,同时提供了一个socket端口和一系列的命令与应用程序交互,这里我们讲解如何通过python与scratch交互 本资源为scratch图形化编程入门教程。
资源推荐
资源详情
资源评论
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/release/download_crawler_static/89319106/bg1.jpg)
#####一,简介
scratch 是一款又麻省理工开发的图形化编程软件,这款软件提供了可以使用 javascript 与 scratch 交互的接口,同时提供了一
个 socket 端口和一系列的命令与应用程序交互,这里我们讲解如何通过 python 与 scratch 交互
####二,说明
之所以选择 python 是主要基于以下几个原因:
1,python 是非编译性语言,所以除非库的提供者将不想开源的代码写在 C/C++,或者 java 等编译性语言的代码中,然后通过
python 调用,一般情况下我们是可以看到源代码的
2,scratch 对于使用 python 与它交互,有现成的 python 库可以调用,这样我们就不需要详细了解 scratch 对外定义的繁琐的
命令结构,这样没有意义
####三,原理
1,当 scratch 启动的时候会默认打开本机的 42001 端口作为服务器端的 socket 接收应用程序请求(这个 port 只是默认的,可
以修改)
2,我们通过本地 socket 连接到 scratch,然后可以发送一系列的命令与 scratch 交互,这样我们就能通过 scratch 图形化编程操
作我们希望操作的任何东西,比如硬件
####四,环境配置
说明:我实在 ubuntu 下面,可以在类似的 linux 发行版上面都行
1,安装 scratch:注意要安装 1.4 版的,我在自己的机台上面用下面这条命令安装的就是 1.4,如果有人安装不是 1.4 版,我这里
暂时不敢保证
sudo apt-get install scratch
2,安装 scratch 的 python 库
sudo apt-get install python-pip scratchpy
3,安装之后在安装目录有一个 scratch.py 的 python 脚本,可以查看 scratch.py 的代码,这个里面提供的通过 python 操作 scratch
的所有接口以及命令
####五,scratch.py 提供的接口
下面贴出 scratch.py 在我们这里用到的部分代码:有兴趣的可以看 scratch.py 的源码
import array
import errno
import itertools
import socket
import struct
class ScratchError(Exception): pass
class ScratchConnectionError(ScratchError): pass
class Scratch(object):
prefix_len = 4
broadcast_prefix_len = prefix_len + len('broadcast ')
sensorupdate_prefix_len = prefix_len + len('sensor-update ')
msg_types = set(['broadcast', 'sensor-update'])
def __init__(self, host='localhost', port=42001):
self.host = host
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/7386ab88f5ce450e8817b9541ae085eb_caryxp.jpg!1)
小小哭包
- 粉丝: 1906
- 资源: 3975
![benefits](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-1.c8e153b4.png)
下载权益
![privilege](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-2.ec46750a.png)
C知道特权
![article](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-3.fc5e5fb6.png)
VIP文章
![course-privilege](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-4.320a6894.png)
课程特权
![rights](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-icon.fe0226a8.png)
开通VIP
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)