Changelog#
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
0.1.0a16 - 2026-11-01#
Added#
experimental support for the Bpod State Machine 0.7-1.0 (Arduino Due) with firmware v23.
Bpod.wait(timeout=...)raises aTimeoutErrorwhen the state machine hasn't finished in time.stop_state_machine(timeout=...)waits at mosttimeoutseconds (one by default) for the Bpod to end the trial; otherwise it gives the trial up and raises aTimeoutError, and the connection has to be reopened.support for Python 3.15.
Fixed#
run()waits for the state machine sent before to start: sent while the Bpod still loaded that one, e.g. right after a session's first trial, the next one garbled the trial data. If it doesn't start within a second,run()gives that trial up and raises aTimeoutError, and the connection has to be reopened.a trial whose data can't be read from the Bpod, e.g. after a firmware fault, makes the next
wait(),run(),close()or other command raise aBpodError, and the connection has to be reopened, instead of the reader thread dying with a traceback and the data staying incomplete without notice.every handshake ends with a session clock reset, also on reopening the connection, and a reset the firmware answers late (about 50 ms on Bpod r2.0) is repeated, so timestamps stay aligned to the host clock.
reopening a
Bpodunlocks its FlexIO channel types and analog sampling rate, as the error message says, and its next trials record analog samples again.set_relay(True)turns a module's relay on again after a reopen.connecting no longer fails with firmware that sends a discovery byte when the port is opened, and no longer waits for the Bpod's next periodic discovery byte.
Bpod.close()finishes its cleanup before raising a connection lost during the trial, and closing an unpluggedBpodno longer raises anOSError.stopping a queued trial that the Bpod never started logs a warning, instead of reading the Bpod's reply as the trial's data.
softcode handling no longer ends when a global timer on the softcode channel turns off.
wait()no longer returns about 10 ms late after a process's first trial.a
Bpodcreated after closing another one for the same device takes over its IPC service, network advertisement included, instead of failing to bind the same addresses.closing a
Bpod, or any IPC host or client, no longer waits up to 100 ms for its event loop, and closing a remote host no longer waits for its goodbye packets.RemoteBpod.close()returns within a second when the host is gone, instead of waiting for a goodbye reply forever.a
RemoteBpodconnecting by one of the host machine's own network addresses is recognized as local: it uses the IPC transport and skips compressing trial data.iter_servicesanddiscover_remote_bpodreport a service that disappears and comes back again, and a record changing its address or port as a removal and an addition. On Windows,iter_servicesno longer stops reporting local services when one of them closes.a host without a route to the internet advertises one of its interface addresses via Zeroconf instead of the loopback address.
RemoteErrorsurvives pickling, e.g. when raised in a worker process.
Changed#
softcode actions (
SoftCode,SoftCodeApp) are sent as is, like MATLAB's, not one higher: they take 1 to 255, and 0 (none to the Bpod) is rejected. Handlers get the same values as before; the app port and softcodes from global timers get them as set.the softcode channels have no number, like their actions:
SoftCodeandSoftCodeAppfor global timers, conditions,Bpod.inputsandBpod.outputs.Bpod.version.machine_strnames the Bpod as precisely as its Teensy model and PCB revision tell, e.g.r2.5or2+ r1.2instead ofr2.0-2.5or2+ r1.0.the builder methods of
StateMachinevalidate their arguments through the models instead ofvalidate_call: validation errors are titled after the model (e.g.State) rather than the method, unknown keyword arguments raise aTypeError, and aTransitionsorActionsinstance passed toadd_stateis stored by reference.state names and operators must be strings;
bytesare no longer coerced.wait()also waits for the trial's softcode handlers to have run.wait()andstop_state_machine()can be interrupted with Ctrl+C while they wait for a trial, despite polars' signal handler.leaving the
Bpodcontext manager on an exception stops a running state machine instead of waiting for it, as doesBpod.close()when its wait is interrupted; if the Bpod doesn't end the trial, the reader gives it up.building state machines is two to three times faster, loading them from a file up to seven times, and
Bpod.runreturns about 40% sooner. Validating and compiling state machines andBpod.get_datagained 10-20%.connecting to a Bpod enumerates the serial ports once instead of three times, and
discover_bpodfinds a Bpod 2+ in under 10 ms instead of 230 ms: it skips a Bpod's other serial ports and Teensy models no Bpod is built on.reading trials takes half the CPU time and fewer thread wake-ups at high event rates.
the warning about a timing violation reports how far the host fell behind in reading the serial port: a full buffer stalls the Bpod's state machine cycle.
local
RemoteBpodconnections use the IPC transport wherever libzmq supports it, instead of only on POSIX.filelockis no longer capped below version 4.
Removed#
bpod.constants.VIDS_BPODandPIDS_BPOD: Bpod ports are matched by vendor and product ID together, as listed inbpod.constants.USB_IDS_BPOD.
0.1.0a15 - 2026-10-23#
Added#
FlexIO channels (Bpod Finite State Machine r2+):
Bpod.flex_ioconfigures each channel as digital or analog input or output, with analog thresholds and the sampling rate, andBpod.get_analog_datareturns the sampled analog input in millivolts. State machines can use Flex events and outputs, and global timers can drive Flex outputs.Bpod.action_names: the actions a state machine can currently set, likeBpod.input_event_namesfor events.ExtendedSerial.temporary_timeout: a context manager that changes the read timeout temporarily.ipc.iter_services,ipc.discoverandipc.ServiceIteratoraccept regex and collection criteria forproperties, likecom.find_ports(seemisc.Filter).misc.SuggestionMapping: a read-only mapping that suggests similar keys on failed lookups.
Changed#
com.find_portstakes explicit keyword-only filters instead of**filtersand raises aTypeErrorfor unknown ones. It and service discovery ignore filters set toNone.Bpod.inputs,Bpod.outputsandBpod.modulesare read-onlymisc.SuggestionMappings, so misspelled module names get a suggestion, too.FlexIO channels are no longer listed in
Bpod.inputsandBpod.outputs; useBpod.flex_io.methods that query or reconfigure the Bpod (e.g.,
set_status_led,update_modules,Input.read,Module.load_serial_message) raise aBpodErrorwhile a state machine is running, instead of corrupting the trial's data.send_softcodeandInput.overridesend nothing while no state machine is running, since the Bpod would ignore it; they log a warning instead.trial data columns are named in title case (
Time,Trial,State Machine,State,Type,Event,Channel,Value).TrialisUInt32instead ofUInt16, andValueisUInt16instead ofUInt8, to hold FlexIO analog-output values in millivolts.lower CPU load: trial data is read from the Bpod in chunks, and live trial events are published in batches.
RemoteBpod'sevent_callbackstill receives single events.building, validating and compiling state machines is faster, and takes about half the time for large ones.
polars 2 is supported (
polars>=1.32.3,<3), and most dependencies accept versions down to the oldest ones tested. pydantic requires 2.8 or newer, since older 2.x versions failed on import.
Removed#
misc.SuggestionDict(usemisc.SuggestionMapping) andcom.FilterValue(usemisc.Filter).the
rechunkparameter ofget_data: call.rechunk()on the result instead.Bpod.serial2: the FlexIO serial connection is now private.the unused
qtpydependency.
Fixed#
module events and softcodes never reached the state machine. Serial events are now allocated to modules as in Bpod's MATLAB software, which also fixes misnumbered input events with modules requesting a non-default number of events.
events in the same state machine cycle as a transition were evaluated in the new state, so trial data could attribute them to the wrong state or record transitions the Bpod never made.
GlobalTimerTrigandGlobalTimerCancelacted on the wrong global timers for indices of 2 or more.trial data showed valves and wire outputs as staying on when a state began that didn't set them, although the Bpod switches them off.
the
TrialEndtime of a queued trial was one state machine cycle late (100 µs on a Bpod 2+).state machine validation missed values the Bpod can't receive: softcodes above 254, references to global timers and counters that haven't been set (
GlobalTimerTrig,GlobalTimerCancel,GlobalCounterReset, onset triggers), and unknown global counter events and condition channels.a trial number above 65535 or below 0 made
get_data()fail, losing the collected trials.run()now rejects trial numbers outside 0 to 4,294,967,295.a
run()that raised before sending, e.g., for an invalid state machine, still used up a trial number, so the next trial skipped one.run()without a state machine reran the last one even after the hardware configuration had changed, e.g., throughupdate_modules(). It now raises aRuntimeError.get_data()right afterstop_state_machine()could raise "No trial data available" while the stopped trial was still being processed.Input.overridedidn't send the input's index, so the Bpod took the next command's first byte as the override state.is_runningwas brieflyFalsewhile a queued state machine was starting, sostop_state_machine()could do nothing.unplugging the Bpod during a trial went unnoticed.
wait()now raises aBpodError.a blocking
peek_data()could, rarely, hang when its trial ended without reaching a trigger state.closing a
Bpodcould wait forever for the Bpod to confirm the disconnect, or disconnect before the last softcodes were handled.leaving a
Bpodcontext didn't close its IPC service or end its softcode thread, and aBpodthat failed to connect kept its serial port open. Objects dropped without closing (aBpod, a subscribedRemoteBpod, an unfinishediter_servicesiterator, or anything a handler refers back to), a failedRemoteBpodhandshake and a failed Zeroconf start left connections and threads running.closing a
Bpod,ServiceHostorServiceClientfrom within its own handler hung or raised aRuntimeError.starting a service could fail with
FileNotFoundErrorwhile another process closed its last service, and closing aServiceHostorLocalServiceAdvertisementcould remove the files of a newer one with the same UUID.validating or compiling state machines in several threads at once (e.g., two Bpods in one process, or a
RemoteBpodnext to the host's own script) could fail or corrupt the caches they share.RemoteBpod.get_dataraised aDeprecationWarningwith polars 1.43.2 or newer.
0.1.0a14 - 2026-07-24#
Added#
Bpodpublishes live trial events over the PUB/SUB channel as a tagged union of typed messages.RemoteBpodaccepts anevent_callbackthat receives each live trial-event message.ServiceHost.get_metadatafor accessing per-request connection metadata from within a request handler.ServiceHost.publishfor broadcasting events over the PUB/SUB channel;ServiceClientdecodes them per its newevent_typeparameter.ServiceHostremembers the TCP ports last bound for a caller-supplieduuid(stored in the user state directory) and reuses them on restart; explicitport_rep/port_pubarguments take precedence.ServiceHost.has_subscribers: the host tracks PUB/SUB subscriptions andpublishdrops messages before encoding while nobody is listening.ServiceClient.requestaccepts an optionaltimeout; the client recovers cleanly after a timed-out request.
Changed#
Add UTC timezone to trial DataFrame timestamps.
ServiceClientadopts the host's serialization format during the handshake, replacing the per-request trial-and-error fallback.the WELCOME handshake carries the PUB channel's TCP port instead of full TCP addresses.
errors raised by
bpod_core.ipcare now uniformlyServiceErrorsubclassesremote method calls (
BpodRequestCall/BpodRequestData) are validated against an explicit allowlist instead of dispatching to arbitrary attributes.
Fixed#
ServiceClientno longer blocks indefinitely when the host dies mid-request.exceptions with non-serializable attributes no longer break error replies from
ServiceHost.resolved several shutdown races between
close()and the event threads /publish().ServiceIterator.close()now terminates an iteration blocked in__next__(e.g., withtimeout=None) instead of leaving the consumer waiting forever.
0.1.0a13 - 2026-06-18#
Changed#
further work on bringing
RemoteBpodto parity withBpod.ExtendedSerial.read_structandwrite_structmethods accept precompiled structs.reduced public interface of
bpod_core.ipc.improved documentation.
0.1.0a12 - 2026-04-30#
Just some minor improvements …
Changed#
further refinements to documentation.
cleaned up rendering of Graphviz graphs.
Removed#
removed unused
misc.DocstringInheritanceMixin
0.1.0a11 - 2026-04-24#
Added#
ExtendedSerial.read_struct_iterandExtendedSerial.stream_structmethods.misc.SuggestionDictfor key lookup with typo suggestions.added optional
trial_numberparameter toBpod.runmethod.
Changed#
replaced
NamedTupleswithmisc.SuggestionDictforBpod.inputsandBpod.outputsrefactored Sphinx documentation and API reference.
0.1.0a10 - 2026-04-16#
Added#
Bpod.address property — exposes the ZeroMQ address of the running instance.
Bpod.peek_data- read trial data before trial end.misc.ByteEnum- an extendedIntEnumthat caches its values as bytes.Timer fields in StateMachine now accept timedelta values in addition to floats.
bpodCLI entry point for launching a Bpod instance that can be connected to via TCP Unix Sockets.state machinecolumn added to trial data output (hash of the FSM)
Changed#
renamed
Bpod.send_state_machinetoBpod.run.removed
Bpod.run_state_machine.switched to Polars
LazyFramefor storing trial data.replaced use of
QueuewithSimpleQueue.switched
Bpod.modulefield fromNamedTupletodict.replaced hashlib.blake2b with xxhash for state machine hashing.
cache validation and compilation of state machines.
StateMachine.hashnow returnsbytesinstead ofstr.
0.1.0a9 - 2026-04-02#
Added#
bpod.is_readyproperty indicating whether a compiled FSM is loaded and ready to runbpod.is_queuedproperty indicating whether an FSM is queued to run after the current onebpod.get_datafor returning trial data after a state machine run.
Changed#
renamed
BNCinput events and output actions toTTLInandTTLOut.replaced MD5 hashing of
fsm.StateMachinewith blake2b.improved readability of
ValidationErrormessages infsm.StateMachine.state machine runs are now handled by three separate threads:
ReadThreadfor serial communication with the Bpod,EventThreadfor handling and structuring the incoming data, andSoftcodeThreadfor executing soft-codes.
Fixed#
reorganization of finalizers for better garbage collection.
0.1.0a8 - 2026-03-04#
Just a quick bugfix release …
Changed#
ipc.ServiceHost: set Zeroconf to listen on all interfaces, reorderWelcomeDatafields, and improve type hints.event handler callback type hint to return
Noneinstead ofAny.refactor CI workflows.
0.1.0a7 - 2026-03-01#
Added#
com.find_portsfor finding serial ports that match given filter criteria.com.verify_serial_discoveryfor checking if a serial device sends an expected discovery message.convenience functions for reading and writing integers in
com.ExtendedSerial.misc.extend_packedfor extending a bytearray by multiple values of the same format.misc.DocstringInheritanceMixinfor inheriting docstrings from base classes.ipc.LocalServiceAdvertisement: local service advertisement and discoveryipc.iter_servicesandipc.ServiceIteratorfor discovering services.bpod.discover_remote_bpodfor discovering remote Bpod instances.more examples.
Changed#
more verbose debug logging during state machine runs.
replace unmaintained
appdirsdependency withplatformdirs.switch to zero-based indexing for global counters, timers, conditions and soft-codes.
added file locking to
misc.SettingsDict.switch to using ZMQ multipart messages for communication.
renamed
ipc.DualChannelHost/ipc.DualChannelClienttoipc.ServiceHost/ipc.ServiceClient.restructured
bpodmodule into several submodules.zero-copy behavior on send path of
ipc.ServiceClientand receive path ofipc.ServiceHost.
Fixed#
decoupled finalizers and event loops from instance references.
0.1.0a6 - 2025-10-29#
Added#
Initial work on cached state machine validation:
fsm.StateMachine.check
Changed#
com.ExtendedSerialno longer supports NumPy types, integers, strings and iterables.refactoring of
com.ChunkedSerialReader
Removed#
com.to_bytesdependency on Pandas
0.1.0a5 - 2025-09-03#
Added#
fsm.to_fileandfsm.from_filefor export/import of state machines.YAML import/export for state machines
Work on documentation: Finite-State Machines
Changed#
moved state machine structure from msgspec Struct back to Pydantic Model
merged
fsm_typesmodule back intofsmrenamed parameters for
add_statemethod:state_change_conditions->transitionsandoutput_actions->actions
0.1.0a4 - 2025-08-25#
Added#
ipc.DualChannelHostandipc.DualChannelClientJSON import/export for state machines
example state machines
Changed#
improved export of state machines to graphviz
improved settings management
moved state machine structure from Pydantic Model to msgspec Struct
0.1.0a3 - 2025-08-04#
Added#
state machine assembly
state machine thread
ZMQ communication module
basic settings management
Changed#
switched package management from PDM to uv.
0.1.0a2 - 2025-05-07#
Added#
pydantic model for state machine
Changed#
further refactoring of the code
renamed
serialmodule tocomto avoid confusion with PySerial.
0.1.0a1 - 2025-04-22#
Changed#
major reorganization of the existing codebase.
renamed
serial_extensionsmodule toserial.
Removed#
removed
SerialSingletonclass.
0.1.0a0 - 2025-04-17#
First alpha release. Nothing works.