Package: pfxbrick
PFx Brick Python APIThis repository contains a python package API for developing python scripts and applications which communicate with the PFx Brick.  This package supports both USB and Bluetooth LE connections to the PFx Brick and is supported for Windows, macOS and linux.Getting StartedOS RequirementsSupports Windows 10, version 16299 (Fall Creators Update) or greaterSupports Linux distributions with BlueZ >= 5.43OS X/macOS support via Core Bluetooth API, from at least OS X version 10.11Package RequirementsPython 3.6+HIDAPIBleaksphinx (for documentation)InstallationPre-install System requirements for linuxThepfxbrickpackage will require some packages to be installed suport access to USB and Bluetooth hardware drivers.  Use your preferred package manager to install these packages:libhidapi-devlibudev-devlibusb-1.0-0-devbluezbluetoothlibbluetooth-devPre-install System requirements for macOSIt is recommended to use thebrewpackage manager to install the packages for USB hardware access. (Hardware support for Bluetooth will automatically be installed withpfxbricksetup.pyinstall script which installs thebleakpackage with its dependency topyobjc-framework-CoreBluetooth).$brewinstallhidapiInstallation with pipThepfxbrickpackage can be installed with pip:$pipinstallpfxbrickInstall from sourceInstall directly from the source code with thesetup.pyscript:$gitclonehttps://github.com/fx-bricks/pfx-brick-py.git$cdpfx-brick-py$pythonsetup.pyinstallConda Virtual EnvironmentYou can also use the package in a standalone conda virtual environment. To create a conda environment namedpfxtest:$gitclonehttps://github.com/fx-bricks/pfx-brick-py.git$cdpfx-brick-py$condaenvcreate-fenvironment.yml$condaactivatepfxtest$pipinstall-rrequirements.txt$pythonsetup.pyinstallBasic UsageAfter installation, the package can imported:$python>>>importpfxbrick>>>pfxbrick.__version__An example of the package can be seen belowimporttimefrompfxbrickimport*# Open a PFx Brick session instancebrick=PFxBrick()brick.open()# Get the PFx Brick configuration settingsbrick.get_config()brick.print_config()# Get the user defined name of the PFx Brickbrick.get_name()print(brick.name)# Change the user defined namebrick.set_name('My Cool Brick')# Turn on some lights for 5 secbrick.light_on([1,2,7,8])time.sleep(5)brick.light_off([1,2,7,8])# Set motor channel A to 50% speed graduallyforspeedinrange(50):brick.set_motor_speed([1],speed)time.sleep(0.1)brick.stop_motor([1])# Play an audio file with indefinite repeatbrick.repeat_audio_file("LongBeep1")time.sleep(5)brick.stop_audio_file("LongBeep1")# End the sessionbrick.close()Utility ScriptsThepfxbrickpackage will install some useful command line script applications in your python environment’s path.  These include:pfxcat- dumps the raw contents of a file on the PFx Brick to your console.pfxdir- shows the directory listing of the PFx Brick file systempfxget- gets a file from the PFx Brickpfxput- copies a local host file on to the PFx Brickpfxrm- delete a file from the PFx Brickpfxrename- renames a file on the PFx Brickpfxdump- dumps raw contents of PFx Brick flash memorypfxinfo- discovers and shows information on all attached PFx Brickspfxmonitor- shows real time operational status of a PFx Brickpfxtest- PFx Brick self test utilitypfxplay- plays an audio file on the PFx Brickpfxrun- runs a script a file on the PFx Brickpfxscan- scans for Bluetooth PFx Bricks and shows each brick’s informationAfter installing thepfxbrickpackage, you should be able to use any of these utilities directly from the command line as follows:$pfxinfo┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓┃A216PFxBrick16MB┃┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩│SerialNumber:AF716069││ICDVersion:03.38││FirmwareVersion:01.50build0555││USBvendorID:0x04D8││USBproductID:0xEF74││Status:0x00Normal││Errors:0x00None││Name:MyPFxBrick│└──────────────────────────────────────────────────────────────────────────┘$pfxdirIDNameSizeAttrUser1User2CRC320sin150Hz.wav132.3kB0000000204CE0000002CA712A54E1pink6dB.wav132.3kB0000000204CE0000002CE6AACE612files,270.3kBused,16490.5kBremainingTo find out more information on how to use each utility, use without arguments or with the-hargument.$pfxinfo-husage:pfxinfo[-h][-c]ShowinformationforallattachedPFxBricksoptionalarguments:-h,--helpshowthishelpmessageandexit-c,--configShowconfigurationdetailsDocumentationPFx Brick Interface Control Document (ICD) v.3.39describes details of PFx Brick operation and communication protocolPython API Reference DocumentationIf you want to learn more about PFx Brick, check outour website.Change Logv.0.8.6improved Bluetooth scanning and device discovery (thanks to a PR from @aholzel)added newpfxscancommand line utilityv.0.8.5support for new ICD revision v.3.39updates to the scripts and documentationv.0.8.4updated command line scripts to use argparseadded new GitHub test actionsv.0.8.3updated command line scripts to install using setuptools console_scripts for better platform compatibilityv.0.8.1bug fixesv.0.8.0all new support added for v.3.38 of ICDsupport for v.1.50+ firmware which conforms to v.3.38 ICDadded command line utility scripts which are installed into the python pathrevised documentationv.0.7.1revised documentationimproved BLE notifcation callbacksv.0.7.0added Bluetooth LE connection access with same functionality as USBadded convenience methods to PFxBrick class to execute actions directlyadded support for running scripts on PFx Brickv.0.6.2fixed error reporting for file system access methodsfixed file directory refresh to ignore empty directory entriesv.0.6.1changed the USB write function to ensure consistent cross-platform compatibilityv.0.6.0finished implementing missing functionalityfinished documentationfirst public announced releasev.0.5.1Added CHANGELOG.rst to project manifestv.0.5.0Initial release