simavr的python包装器,它是avr和arduino模拟器。

pysimavr的Python项目详细描述


pysimavr是simavr的python包装器,它是AVRarduino模拟器

链接:

TravisCoverallsLatest VersionSupported Python versionsLicenseDownloadsCode HealthDocumentation

功能:
  • python包装器使用swig
  • simavr包含源代码和avr-libc头,以便于安装
  • 在生成的接口之上的面向对象接口
  • 最大速度可以实时
  • 串行通信
  • 检查simavr文档

基本用法

>>> from pysimavr.avr import Avr
>>> avr=Avr(mcu='atmega48',f_cpu=8000000)
>>> firmware = Firmware('lcd.elf')
>>> avr.load_firmware(firmware)
>>> from pysimavr.sim import ArduinoSim
>>> print ArduinoSim(snippet='Serial.print("hello!");').get_serial()
hello!

安装

检查simavr文档

一般

  • install python

  • install pip

  • install swig (for source build only)

  • install header files and a static library for Python (for source build only)

  • install a compiler (for source build only)

  • install elf library

  • install the program:

    # as root
    pip install pysimavr
    

ubuntu 14.04

sudo apt-get install python-pip
sudo apt-get install python-dev gcc libelf-dev arduino
sudo pip install pysimavr
# optional for some tests:
sudo apt-get install freeglut3-dev scons swig

卸载

# as root
pip uninstall pysimavr

用法

pysimavr.examples.simple:

#-- include('examples/simple.py')--#
from pysimavr.avr import Avr

if __name__ == "__main__":
    avr = Avr(mcu='atmega48', f_cpu=8000000)
    print( avr.pc )
    avr.step(1)
    print( avr.pc )
    avr.step(1)
    print( avr.pc )

    avr.terminate()
#-#

输出:

#-- sh('python -m pysimavr.examples.simple ')--#
0
2
4
#-#

pysimavr.examples.hello:

#-- include('examples/hello.py')--#
from pysimavr.sim import ArduinoSim

if __name__ == "__main__":
    s= ArduinoSim(snippet='Serial.println("hello!");').get_serial()
    print(s)
#-#

输出:

#-- sh('python -m pysimavr.examples.hello ')--#
hello!

#-#

pysimavr.examples.delay:

#-- include('examples/delay.py')--#
from pysimavr.sim import ArduinoSim
import time

snippet = '''
int i=0;
while (1)
{
    Serial.println(i++);
    _delay_ms(1000);
}
'''
t0 = None


def logger(x):
    global t0
    t = time.time()
    if not t0:
        t0 = t
    print t - t0, x


f_cpu=16000000
fps=20
speed=1
timespan=5

if __name__ == "__main__":
    ArduinoSim(snippet=snippet,
           timespan=timespan,
           serial_line_logger=logger,
           f_cpu=f_cpu,
           fps=fps,
           speed=speed,
           ).run()
#-#

输出:

#-- sh('python -m pysimavr.examples.delay ')--#
0.0 0

1.00977802277 1

2.01976013184 2

3.02968215942 3

4.03792500496 4

#-#

VCD导出示例

pysimavr.examples.vcd:

#-- include('examples/vcd.py')--#
from pysimavr.sim import ArduinoSim


vcdfile='delay.vcd'
snippet = '''
    Serial.println("start");
    pinMode(0, OUTPUT);
    digitalWrite(0, HIGH);
    delay(100);
    digitalWrite(0, LOW);
    delay(100);
    digitalWrite(0, HIGH);
    delay(100);
    digitalWrite(0, LOW);
    delay(100);
    Serial.println("end");
'''

if __name__ == "__main__":
    sim = ArduinoSim(snippet=snippet, vcd=vcdfile, timespan=0.5)
    sim.run()
#-#
gtkwave_id0.png

文件层次结构

|-docs                   sphinx documentation
|---.build               generated documentation
|-pysimavr               main python package, high level classes
|---examples             examples
|---swig                 all swig files (simavr and parts)
|-----include            copy of simavr generated *.h files
|-------avr              copy from avr-libc
|-----parts              some electronic parts in c
|-----simavr             simavr as git submodule
|-tests                  unit tests

如何更新外部源

  1. avr-libc头文件(ubuntu文件夹:usr/lib/avr/include/avr/)复制到pysimavr/swig/include/avr
  2. simavr是git子模块。在simavr目录中运行'make', 然后将生成的sim_core_config.h和sim_core_decl.h复制到pysimavr/swig/include中

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
javai是JAXB的新手。如何将两个具有不同名称空间的不同xml合并为一个具有根元素的xml并将其解组?   JDO中的java应该是可传递的DefaultFetchGroup吗   java服务器配置问题   java在理解JList时遇到困难   java何时将RequestContextFilter用于Jersey?   java从数据库中读取文本文件。jar文件   Java正则表达式,仅适用于不包括零的正数   爪哇番石榴。类路径中的jar   JavaEE:关于设计的问题   java GUI,在面板中排列按钮   java Android为什么使用接口被认为是活动和片段之间通信的最佳实践?   java如何获取wicket图像的url以在开放图元标记中使用它   从Java字节[]>Base64>Javascript数组缓冲>Base64>byte[]   java正则表达式帮助字符串JWE766。1.pdf格式摘录766   java Hibernate,JPA忽略@Formula