未加星标

Interfacing with NewPort Motion Controllers on a Mac

字体大小 | |
[开发(python) 所属分类 开发(python) | 发布者 店小二04 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏

This post describes how to interface with a NewPort Motion Controller over USB using a Mac.

This process uses python, with the pyUSB module and the libusb-compat backend.

The script launches a console type interface, which accepts valid NewPort style commands (see bottom of page).

NoteThis script has only been tested with a single closed-loop Picomotor controller (model 8745) .

Install

Install Homebrew and Python

Follow the steps at this guide for setting up Python and homebrew. You'll need homebrew to install the USB backend, and Python 2.7.x to run my code.

Install the USB Backend - libusb $ brew install libusb-compat Install pyUSB $ pip install pyusb Install my NewPort Python Code $ brew install wget $ wget https://bitbucket.org/bdhammel/newport_controller/raw/062f9e5bf9c369051b71dac232d4eb0a703d9c3e/newport.py Using the Python Code

Launch the code by typing the following into terminal

$ python newport.py

You should see this prompt open up, asking you to identify the motor to connect to.

####################################################################### # Python controller for NewFocus Picomotor Controller ####################################################################### Run the following command in a new terminal window: $ system_profiler SPUSBDataType Enter Product ID: >

In another terminal window, query the connected USB devices with system_profiler SPUSBDataType . You're looking for a similar connection to this one:

USB 3.0 Hi-Speed Bus: Host Controller Location: Built-in USB Host Controller Driver: AppleUSBXHCI PCI Device ID: 0x1e31 PCI Revision ID: 0x0004 PCI Vendor ID: 0x8086 Bus Number: 0x0a Picomotor Controller: Product ID: 0x4000 Vendor ID: 0x104d Version: 1.00 Serial Number: 12345678 Speed: Up to 12 Mb/sec Manufacturer: New Focus Location ID: 0x14200000 / 6 Current Available (mA): 500 Current Required (mA): Unknown (Device has not been configured)

Enter your controller's Product ID and Vendor ID . The script should find the device and report back the connected motors. Try it out by sending a command to move one of these motors.

############################################################################### # Python controller for NewFocus Picomotor Controller ################################################################################ Run the following command in a new terminal window: $ system_profiler SPUSBDataType Enter Product ID: > 0x4000 Enter Vendor ID: > 0x104d Connected to Motor Controller Model 8742. Firmware Version 2.2 08/01/13 Motor #1: 'Standard' Motor Motor #2: No motor connected Motor #3: No motor connected Motor #4: No motor connected Picomotor Command Line --------------------------- Enter a valid NewFocus command, or 'quit' to exit the program. Common Commands: xMV[+-]: .....Indefinitely move motor 'x' in + or - direction ST: .....Stop all motor movement xPRnn: .....Move motor 'x' 'nn' steps Input > 1MV+ Input > ST Input >

For a full list of commands on the 8745 controller, see section 6.2 in the user manual

NoteNot all of these have been tested, and there are undoubtedly some bugs.

Once you have the Product ID and Vendor ID, you can write these directly into the python script, so you don't have to re-enter them every time you start the program.

Inside newport.py

if __name__ == '__main__': print('\n\n') print('#'*80) print('#\tPython controller for NewFocus Picomotor Controller') print('#'*80) print('\n') idProduct = None #'0x4000' idVendor = None #'0x104d' if not (idProduct or idVendor): print('Run the following command in a new terminal window:') print('\t$ system_profiler SPUSBDataType\n') print('Enter Product ID:') idProduct = raw_input('> ') print('Enter Vendor ID:') idVendor = raw_input('> ') print('\n')

Replace the None after idProduct and idVendor with your Product ID and Vendor ID. When the script runs in the future, it won't prompt you for these values.

本文开发(python)相关术语:python基础教程 python多线程 web开发工程师 软件开发工程师 软件开发流程

主题: PythonApple
分页:12
转载请注明
本文标题:Interfacing with NewPort Motion Controllers on a Mac
本站链接:http://www.codesec.net/view/484640.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 开发(python) | 评论(0) | 阅读(38)