Bonsai CLI

661 views
Skip to first unread message

Bruno Cruz

unread,
Feb 14, 2016, 9:54:18 AM2/14/16
to Bonsai Users

Hi everyone

is there anyway to run bonsai from the command line and play the sketch directly? additionally can you pass variables this way? Something like:

path\Bonsai64.exe path2\sketch.bonsai --start variable1 = x

Thanks
Bruno

goncaloclopes

unread,
Feb 14, 2016, 11:20:34 AM2/14/16
to Bonsai Users
Hi Bruno,

Glad you asked! Yes, it is possible to do both of these things.

1) To run a Bonsai workflow directly from the command line, just add the flag: --start
Note that this will first open the editor and then start the workflow. If you want to run the workflow without any editor (until it completes), pass in the flag --noeditor. This is useful for offline batch processing (e.g. video tracking, etc).

2) You can also initialize externalized properties through the command line. For example, in the following workflow:


You can set the externalized FileName value using the following command line:

path\Bonsai64.exe path2\workflow.bonsai -p:FileName="video.avi"

The general syntax is to use -p:<propertyName>=<string> where <string> is whatever text you would write in the property editor in order to configure that property. You can even set properties in nested workflows by giving the nested workflow a name, and using "." (dot) syntax to specify properties inside the nesting (e.g. Nested.FileName="video.avi").

Hope this helps,

Bruno Cruz

unread,
Feb 14, 2016, 12:02:39 PM2/14/16
to goncaloclopes, Bonsai Users
i tried the start flag before and it didnt work and i just realized why, i used as test sketch a file with "range" as single node, so it didnt do nothing! But actually the no editor is super useful thanks!


Regarding the second part, it works, but now i am running 2 nodes with matrixwritter and I want to name both of them, unfortunately, using your sintax, bonsai only names the later one. Is there a way to name both? or do i have to do it inside a nested workflow and access each of them inside it?

Thanks alot!!

--
You received this message because you are subscribed to a topic in the Google Groups "Bonsai Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/bonsai-users/HlIIOQP1JOA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to bonsai-users...@googlegroups.com.
Visit this group at https://groups.google.com/group/bonsai-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/bonsai-users/7a6b9377-a05b-4be7-ac89-a581569c6cdf%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

goncaloclopes

unread,
Feb 14, 2016, 12:39:16 PM2/14/16
to Bonsai Users
Did you try giving different names to the properties? You can rename an externalized property by clicking on it and changing the Name property in the editor.
If you want to use different properties you need to give them unique names.

Let me know if it doesn't work, and in this case it will be very helpful if you can include the attached workflow.

Hope this helps,
G

Bruno Cruz

unread,
Feb 14, 2016, 12:47:28 PM2/14/16
to goncaloclopes, Bonsai Users
Works like a charm! super useful ;)

Thanks

--
You received this message because you are subscribed to a topic in the Google Groups "Bonsai Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/bonsai-users/HlIIOQP1JOA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to bonsai-users...@googlegroups.com.
Visit this group at https://groups.google.com/group/bonsai-users.

Bruno Cruz

unread,
Feb 20, 2016, 9:06:35 AM2/20/16
to Bonsai Users
Hi again,

So i managed to put everything working except for a little detail.
I am reading Serial using bonsai. Simply put: SerialStringRead into TextWriter and it working very well ;).

There is, however, one thing i am not managing to get to work.
Although PortName is "externalizable", the baudRate a which it runs it is not as far as i can tell. Unfortunately, if I want to run it from cmd in different computers, i would need to manually set the baudrate each time the port changes which would defeat the propose of running it from the command line. 
To bypass this problem i tried to manually edit the SerialPort.config (and because i mostly run at 115200) I added a bunch of "fake" ports like so:

    <SerialPortConfiguration>
   
<PortName>COMX</PortName>
   
<BaudRate>115200</BaudRate>
 
</SerialPortConfiguration>


Where X took values from 1-20. This, however, produces the following error:

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.InvalidOperationException: There is an error in XML document (63, 7). ---> System.Xml.XmlException: The 'SerialPortConfigurationSettings' start tag on line 2 position 2 does not match the end tag of 'SerialPortConfiguration'. Line 63, position 7.
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args)
   at System.Xml.XmlTextReaderImpl.ThrowTagMismatch(NodeData startTag)
   at System.Xml.XmlTextReaderImpl.ParseEndElement()
   at System.Xml.XmlTextReaderImpl.ParseElementContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.XmlReader.MoveToContent()
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderSerialPortConfigurationCollection.Read3_Item()
   --- End of inner exception stack trace ---
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
   at Bonsai.IO.SerialPortManager.LoadConfiguration()
   at Bonsai.IO.Design.SerialPortConfigurationControl.LoadConfiguration()
   at Bonsai.Design.ConfigurationControl.configurationManagerButton_Click(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.6.1055.0 built by: NETFXREL2
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
Bonsai
    Assembly Version: 2.2.0.0
    Win32 Version: 2.2.0.1885
    CodeBase: file:///C:/Users/bruno.cruz/AppData/Local/Bonsai/Bonsai.EXE
----------------------------------------
System.Core
    Assembly Version: 4.0.0.0
    Win32 Version: 4.6.1055.0 built by: NETFXREL2
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.6.1055.0 built by: NETFXREL2
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Configuration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.6.1055.0 built by: NETFXREL2
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.6.1067.0 built by: NETFXREL3STAGE
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
Microsoft.GeneratedCode
    Assembly Version: 1.0.0.0
    Win32 Version: 4.6.1067.0 built by: NETFXREL3STAGE
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
Bonsai.Editor
    Assembly Version: 2.2.0.0
    Win32 Version: 2.2.0.1885
    CodeBase: file:///C:/Users/bruno.cruz/AppData/Local/Bonsai/Packages/Bonsai.Editor.2.2.0/lib/net45/Bonsai.Editor.dll
----------------------------------------
Bonsai.Core
    Assembly Version: 2.2.0.0
    Win32 Version: 2.2.0.1885
    CodeBase: file:///C:/Users/bruno.cruz/AppData/Local/Bonsai/Packages/Bonsai.Core.2.2.0/lib/net45/Bonsai.Core.dll
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.6.1055.0 built by: NETFXREL2
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.6.1068.2 built by: NETFXREL3STAGE
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Reactive.Linq
    Assembly Version: 2.2.5.0
    Win32 Version: 2.2.5.40722
    CodeBase: file:///C:/Users/bruno.cruz/AppData/Local/Bonsai/Packages/Rx-Linq.2.2.5/lib/net45/System.Reactive.Linq.dll
----------------------------------------
System.Reactive.Interfaces
    Assembly Version: 2.2.5.0
    Win32 Version: 2.2.5.40722
    CodeBase: file:///C:/Users/bruno.cruz/AppData/Local/Bonsai/Packages/Rx-Interfaces.2.2.5/lib/net45/System.Reactive.Interfaces.dll
----------------------------------------
System.Reactive.Core
    Assembly Version: 2.2.5.0
    Win32 Version: 2.2.5.40722
    CodeBase: file:///C:/Users/bruno.cruz/AppData/Local/Bonsai/Packages/Rx-Core.2.2.5/lib/net45/System.Reactive.Core.dll
----------------------------------------
System.Reactive.PlatformServices
    Assembly Version: 2.2.5.0
    Win32 Version: 2.2.5.40722
    CodeBase: file:///C:/Users/bruno.cruz/AppData/Local/Bonsai/Packages/Rx-PlatformServices.2.2.5/lib/net45/System.Reactive.PlatformServices.dll
----------------------------------------
Bonsai.Design
    Assembly Version: 2.2.0.0
    Win32 Version: 2.2.0.1885
    CodeBase: file:///C:/Users/bruno.cruz/AppData/Local/Bonsai/Packages/Bonsai.Design.2.2.0/lib/net45/Bonsai.Design.dll
----------------------------------------
Microsoft.GeneratedCode
    Assembly Version: 1.0.0.0
    Win32 Version: 4.6.1067.0 built by: NETFXREL3STAGE
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Xml.Linq
    Assembly Version: 4.0.0.0
    Win32 Version: 4.6.1055.0 built by: NETFXREL2
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml.Linq/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.Linq.dll
----------------------------------------
Microsoft.GeneratedCode
    Assembly Version: 1.0.0.0
    Win32 Version: 4.6.1067.0 built by: NETFXREL3STAGE
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
Bonsai.System
    Assembly Version: 2.2.0.0
    Win32 Version: 2.2.0.1885
    CodeBase: file:///C:/Users/bruno.cruz/AppData/Local/Bonsai/Packages/Bonsai.System.2.2.0/lib/net45/Bonsai.System.dll
----------------------------------------
Microsoft.GeneratedCode
    Assembly Version: 1.0.0.0
    Win32 Version: 4.6.1067.0 built by: NETFXREL3STAGE
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
Anonymously Hosted DynamicMethods Assembly
    Assembly Version: 0.0.0.0
    Win32 Version: 4.6.1055.0 built by: NETFXREL2
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/mscorlib/v4.0_4.0.0.0__b77a5c561934e089/mscorlib.dll
----------------------------------------
Bonsai.System.Design
    Assembly Version: 2.2.0.0
    Win32 Version: 2.2.0.1885
    CodeBase: file:///C:/Users/bruno.cruz/AppData/Local/Bonsai/Packages/Bonsai.System.Design.2.2.0/lib/net45/Bonsai.System.Design.dll
----------------------------------------
Bonsai.Design.Visualizers
    Assembly Version: 2.2.0.0
    Win32 Version: 2.2.0.1885
    CodeBase: file:///C:/Users/bruno.cruz/AppData/Local/Bonsai/Packages/Bonsai.Design.Visualizers.2.2.0/lib/net45/Bonsai.Design.Visualizers.dll
----------------------------------------
OpenCV.Net
    Assembly Version: 3.3.0.0
    Win32 Version: 3.3.0.0
    CodeBase: file:///C:/Users/bruno.cruz/AppData/Local/Bonsai/Packages/OpenCV.Net.3.3.0/lib/net40/OpenCV.Net.dll
----------------------------------------
Bonsai.Dsp.Design
    Assembly Version: 2.2.0.0
    Win32 Version: 2.2.0.1885
    CodeBase: file:///C:/Users/bruno.cruz/AppData/Local/Bonsai/Packages/Bonsai.Dsp.Design.2.2.0/lib/net45/Bonsai.Dsp.Design.dll
----------------------------------------
Bonsai.Dsp
    Assembly Version: 2.2.0.0
    Win32 Version: 2.2.0.1885
    CodeBase: file:///C:/Users/bruno.cruz/AppData/Local/Bonsai/Packages/Bonsai.Dsp.2.2.0/lib/net45/Bonsai.Dsp.dll
----------------------------------------
Bonsai.Vision
    Assembly Version: 2.2.0.0
    Win32 Version: 2.2.0.1885
    CodeBase: file:///C:/Users/bruno.cruz/AppData/Local/Bonsai/Packages/Bonsai.Vision.2.2.0/lib/net45/Bonsai.Vision.dll
----------------------------------------
Bonsai.Vision.Design
    Assembly Version: 2.2.0.0
    Win32 Version: 2.2.0.1885
    CodeBase: file:///C:/Users/bruno.cruz/AppData/Local/Bonsai/Packages/Bonsai.Vision.Design.2.2.0/lib/net45/Bonsai.Vision.Design.dll
----------------------------------------
Accessibility
    Assembly Version: 4.0.0.0
    Win32 Version: 4.6.1055.0 built by: NETFXREL2
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Accessibility/v4.0_4.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
----------------------------------------
System.Design
    Assembly Version: 4.0.0.0
    Win32 Version: 4.6.1055.0 built by: NETFXREL2
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Design/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Design.dll
----------------------------------------
Microsoft.GeneratedCode
    Assembly Version: 1.0.0.0
    Win32 Version: 4.6.1067.0 built by: NETFXREL3STAGE
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.


So my question is:

1. Is there any way to, from the command line, send both the COM port and the baudRate to run it at
2.If i can only send the COM port is there, at least a easy to make the default baudRate 115200?

Thanks alot!!

goncaloclopes

unread,
Feb 20, 2016, 9:10:56 AM2/20/16
to Bonsai Users
You make a good point about configuring the BaudRate. I'll think about it...

About your error though, I believe the error message is actually telling you what to do in this case:

************** Exception Text **************
System.InvalidOperationException: There is an error in XML document (63, 7). ---> System.Xml.XmlException: The 'SerialPortConfigurationSettings' start tag on line 2 position 2 does not match the end tag of 'SerialPortConfiguration'. Line 63, position 7.

I think you are probably just missing a </SerialPortConfigurationSettings> end tag at the end of the file.
Can you confirm this is the case?

In case this is not it, can you attach the whole file so I can take a look?
Best,

Bruno Cruz

unread,
Feb 20, 2016, 9:17:51 AM2/20/16
to goncaloclopes, Bonsai Users
you are right, seems to be working now! My bad thanks again ;)
If you do add BaudRate as an externalizable property let me know

Thanks for the quick answer ;)

--
You received this message because you are subscribed to a topic in the Google Groups "Bonsai Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/bonsai-users/HlIIOQP1JOA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to bonsai-users...@googlegroups.com.
Visit this group at https://groups.google.com/group/bonsai-users.

Atabak Dehban

unread,
Aug 1, 2016, 9:51:37 AM8/1/16
to Bonsai Users, goncal...@gmail.com
Sorry to hijack your topic Bruno ;)

But I have a related question. Is it also possible to feed in non-string parameters? E.g. the array for cropPolygon? And what would be the correct syntax?

Gonçalo Lopes

unread,
Aug 2, 2016, 1:31:32 AM8/2/16
to Atabak Dehban, Bonsai Users
Hi Atabak,

Unfortunately it doesn't work for the CropPolygon right now. The reason is that the property must have a declared TypeConverter that knows how to convert from string into the property type, in order for CLI to work. A good rule of thumb is: if you can write the property using a string directly on the property window, you can use it from CLI. If you have to use an editor (like in this case), you cannot.

However, a workaround would be to make your own conversion. Basically you declare a String source that is externalized with a property and then make a PythonTransform or some other node that makes the conversion from that, something like the attached workflow.

Hope this helps. In the future I may extend the string conversion to more and more types, but for complex types it will be on a case-by-case basis.


cliregions.png

Atabak Dehban

unread,
Aug 3, 2016, 9:27:05 AM8/3/16
to Bonsai Users, atabak...@neuro.fchampalimaud.org
Thanks Goncalo,

Now it's clear.

Bruno Cruz

unread,
Aug 11, 2017, 10:06:09 AM8/11/17
to Bonsai Users
Sorry for digging up this post!
 Is there a way to actually pass a "--Stop" flag when bonsai is already running? 
I can easly get the PID of the process and kill it throught the command line, but this has obvious problems. For instance if i am saving a file and kill bonsai like this videos get corrupted, and CSV are missing values at the end of the file. Can you think of any way bonsai can be closed without running into this kind of problems? 

Thanks!
Bruno


On Sunday, February 14, 2016 at 2:54:18 PM UTC, Bruno Cruz wrote:

Gonçalo Lopes

unread,
Aug 14, 2017, 8:08:21 AM8/14/17
to Bruno Cruz, Bonsai Users
Hey Bruno,

Unfortunately, command line arguments can only be passed in when the executable is started. You can setup a specific key combination, or configure a network message to stop the workflow, though, using TakeUntil. However, this will still not shut down the editor.

You may be able to automate sending a keystroke "Alt-F4" to the editor process. If the workflow is already stopped and nothing else has been changed, it should just close the editor. Something like this: https://stackoverflow.com/questions/10407769/directly-sending-keystrokes-to-another-process-via-hooking

Another option if you don't need any visualizers is to call Bonsai with the "--noeditor" flag. In this way, if the workflow stops the process is immediately stopped.

Hope one these options helps. 

--
You received this message because you are subscribed to the Google Groups "Bonsai Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bonsai-users+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages