logiccircuit help

logiccircuit help

 

Editing circuits

When you first open LogicCircuit it will be one empty logical circuit visible on the right pane of the program window named "Main".

image

To create you first circuit just drag and drop any item (for example a button) from the left pane to the design surface.

image

image

To wire your circuits connect output pin of one circuit with one or more input pins of another one. All pins are bold black dots on the edges of circuit symbols. All you need to do is just draw wires with your mouse.

image

image

You can select and move multiple symbols on your circuit.
Hold Ctrl key on your keyboard and click items on the design surface to select or unselect them.
Click wire while holding Shift key to select entire "conductor".
There are bunch of selection commands in the Edit menu.

image

When you moving symbols over the diagram wires connected to them will be sticking to the pins. If you want to move the symbols without wires hold Shift while dropping at the desired location.

You can also pan the entire surface in all 4 directions by holding Ctrl key and dragging any free space of the diagram. If you scroll your mouse wheel it will scroll the diagram vertically. Holding the Shift key and spinning the wheel will scroll the diagram horizontally. Finally, if you hold the Ctrl key and spin the wheel you can zoom the diagram in and out.

To edit properties of the symbol on the design surface double click it and the property dialog will pop up. However double clicking symbol of logical circuit will open it on the design surface. See Building advanced circuits for more details.

image

Now you have your first circuit ready and can try to power it up and see how it works.

image

 

Building advanced circuits

Creating sub circuits

In order to build more advanced circuits you need to create reusable logical circuits.
To create it click menu Circuit/New Logical Circuit.

Creating new logical circuit

Switching between circuits and using them on other circuits

To switch between your circuits you can double click them on the left panel or pressing Ctrl + Tab or Ctrl + Shift + Tab to navigate through circuits in reverse historical order. Press Tab more than once while holding Ctrl to navigate further in the history.

After you've created a new logical circuit you want to rename it and change text on its symbol.

To change properties of current logical circuit double click anywhere on the design surface, but not on any symbol. The circuit properties dialog will pop up. You also can open the same dialog by clicking menu Circuit/Logical Circuit.

Circuit properties dialog

Note that most of dialogs are resizable so make sure you see all the controls on the dialog.

Input and output pins

After you've created a new circuit it does not have any pins on its symbol's edges.

In order to wire it to other circuits you should define its input and output pins. This is very simple; just drag and drop as many input and output pins on the design surface of your circuit.

By default all input pins goes to the left side of the circuit symbol and output ones to the right side.

To change properties of the pin just double click it on the design surface and pin dialog will pop up.

Circuit properties dialog

You can change name, description, side of the circuit symbol where the pin will reside, give a description of the pin that will be visible when you hover mouse over it and provide its bit width. For more details on multi bit pins read about splitter.

To change the position of the pin on the side of the circuit's symbol you can move it on design surface relatively to other pins that reside on the same side. So if pin lower on the design surface it will be lower on the symbol's side if it on the right of the other pin it will be lower or righter on the symbol and so on.

The fact the pin is input or output is used to put input pins to the left and output pins to the right edge of circuit by default. It is also used to build truth table. However all pins are bidirectional, that means you can use either of them for both input and output signal. You can just think of them as piece of copper connecting inside of the circuit to its outside.

 

Oscillation

Consider the following circuit built in the real life:

Oscillator

Here is NAND gate receives constant "1" and its own output as an inputs.
So when the output is 0 it will switch to 1 and immediately after this back to 0. So it will oscillate until one turn off the power. The frequency of the oscillation will depend on parameters of transistors and resistors the gate is built from.
In order to control the frequency of the oscillation one need to add some sort of electrical reactance http://en.wikipedia.org/wiki/Reactance_(electronics) to the circuit. This will allow changing the frequency of oscillation by altering impedance of the reactance. But again in the real life the generated frequency want be stable enough and hence usually a special clock circuit are used instead. Such clock gate is available for you in the Logic Circuit program:

Clock gate

Now taking in consideration that there no easy way to control frequency of oscillation and the fact that the program has clock gate I can think of couple of ways to deal with self oscillating circuits like the one above. One way is to detect the oscillation and stop simulating because otherwise there is no way to control how many oscillations happened during one tick of the clock. The second way is to add some more realistic reactance elements. Apparently adding more realism want ends with just a reactance. Next you will need to match impedances, set some realistic delays on gates, and many other restrictions and complications that usually real hardware engineers facing. And this of course will shift the program from simple and free to professional and very expensive category.
That is why oscillations are not allowed in Logic Circuit and if you try to power up the above circuit the execution will be aborted, power will be turned off, and a message box "Oscillation" will pop up.

Splitter

Sometimes, your circuit can have too many wires running in parallel. In such cases, you may want to group them into a single bundle. To do this, you can use a splitter, which lets you either combine multiple wires into a bundle or split a bundle into separate wires.

Splitter example

Before you drag and drop a splitter into your circuit, you'll need to choose:

  • the number of pins on the split end,
  • the bit width of each pin on the split end, and
  • the splitter’s rotation.

 

For example, if you choose 4 pins and set the bit width to 2, each pin on the split side will carry 2 bits. This allows you to bundle other bundles.
The combined end will then carry 8 bits total (2 bits × 4 pins).

Elements like input/output pins, constants, RAM, and ROM support such bundled connections—but you must specify the bit width you need.

To do this, double-click the element while in edit mode. A property dialog will appear with a dropdown menu where you can set the bit width.

Changing Bit Width

The probe also supports bundles, but it detects the bit width automatically—so you don’t need to set it manually.

Starting from version 2.19.12.09, wires that connect pins with different bit widths will turn red. This helps you spot and fix mismatches more easily.

Red wire

 

Memory components (RAM and ROM)

ROM

For the definition of the ROM acronym please see http://en.wikipedia.org/wiki/Read-only_memory. In the Logic Circuit program ROM has one input pin allowing setting the address of the data, and one output pin set to the value of the memory cell located at the provided address. There is no extra signals should be set in order to read the data and of course there no way to change the data in the ROM via its pins.
However the ROM can be "programmed" or filled with desired values in the edit mode of the Logic Circuit program. In order to do these double click the ROM’s symbol on your circuit and the ROM dialog will pop up.
If you check "Dual port" box it will add one more address input and one more data output. This allows reading from the same module from two cells at the same time.

ROM Dialog

In the dialog you can change bit width of both address and data pins. When you changing bit width of the address pin you will see the number of available cells get updated while changing of the data bit width will affect the size of each cell. The number of cells is a power of 2 of the address bit width and the maximum number allowed in each cell is power of 2 of data bit width.
In order to change value stored in a cell click it in the Data greed or move focus in the greed and navigate to the desired cell with you arrow keys and just type a new value. Value must be entered in hexadecimal format. You can also load values from a binary file. In order to load content of file in the ROM click "Load..." button. To save it in a file click "Save..." button.

It is also possible to load a text file that contains a sequence of numbers separated by white spaces, commas or semicolons. The numbers can be in binary, decimal or hexadecimal representation. To load text file click Load text button. The format of the file can be selected in the drop down control next to that button.

RAM

For the definition of RAM acronym please see http://en.wikipedia.org/wiki/RAM. In the Logic Circuit program RAM has 3 input pins and one output, and 4 inputs and 2 outputs if Dual port flag is checked.
The first input pin is address pin where you can select the cell you are reading or storing the data to. The second pin is input data pin. The circuit should send the data to store to this pin. When the RAM is dual port, then data is send to address provided in first address input. The third input pin is one bit RAM write signal. The data get stored when the value on this pin is changing in the specified way. In order to specify the time of storing the data double click symbol of the RAM on your circuit and RAM dialog will pop up (see below).
The only output pin of the RAM is output data. It works exactly like output pin of ROM.
When circuit gets powered up the RAM gets initialized. By default it initialized to random values, but you can choose to set all its bits to zeros, ones or preserve values between circuit runs. In the last case you can also edit values in the memory in the edit mode in the RAM dialog. In order to change RAM’s properties double click its symbol on the circuit diagram while in edit mode and RAM dialog will pop up.

RAM Dialog

Like in ROM you can change bit width of the address and data pins. Obviously the bit width of input data pin will be equal to bit width of output data pin so it is only one data bit width drop down there.
In the "Write on" drop down you can choose storing behavior of the RAM, so it will store the data when signal on "RAM write" input pin will change from 1 to 0 or vice versa.

You can choose how to initialize your RAM module when the circuit is powered up.

The "Randomly" is what a real RAM module will be initialized to, so this is your primary selection. You can also set all bits to zero or one. Finally, you can save all the memory and keep it between runs. This is how a flash memory or any other storage device can work.

Please note that this option will only work if your RAM module is resided on the main circuit of your project. The reason of this restriction is if you have, such RAM in sub circuit and use it more than once than multiple values need to be stored in one RAM.

Run time

In the running mode you can browse content of the memory component by double clicking it symbol on your circuit. The memory dialog will pop up.

Memory Dialog

Please see Splitter to learn how to make multiple bits wires.
To get a feeling of the memory units please connect each of them with constants and probes and change the values and see what is the outcome is.

 

LED Matrix

To learn more about LEDs – Light-Emitting Diodes please read the following Wikipedia article:

http://en.wikipedia.org/wiki/Light-emitting_diode

LED Matrix is a grid of LED’s cells. Each cell contains up to 3 LEDs of red, green and blue colors. Color of each cell is a combination of colors of lit diodes:

Color adding

For more on RGB color model please read:

http://en.wikipedia.org/wiki/Rgb

Each matrix can contain up to 10 rows and 10 columns. Each cell can be of rectangular or round shape.

There are two ways of controlling the matrix:

  • By controlling each individual LED.
  • By controlling all LEDs on intersection of selected columns and rows.

The difference is in the bit width and number of input pins on the matrix.

For the first type of the matrix the left edge will contain as many pins as many rows is in the matrix and bit width of each pin will be equal to the number of column in the matrix multiplied by the number of colors in each dot. For example the following three matrices have 3, 6, and 9 bit width of each pin.

First type of matrix

The second type of matrix is somewhat more real. The matrices available on the market are controlled in the same manner. It has pins in the left and top edges of the matrix. There are as many pins on the left edge as many rows on the matrix; there are as many pins on the top edge as many columns on the matrix. Pins on the left edge are all 1 bit wide, while widths of the top pins on are equal to number of colors of each cell. The real matrices are controlled like this because LEDs are wired like on this circuit:

First type of matrix

The cell in the matrix will be lit if the correspondent pins on the left and top edges are set to non-zero state. See these two examples.

First type of matrix

To control such matrices usually you need to build a special driver that will select one row at a time and set state of all columns to what is needed for this row. In the next cycle the driver will select next row and lit all required cells and so on. So at each particular moment only one row is lit and if you roll rows fast enough the eye will not notice the dynamics but will see a formed picture instead. In Logic Circuit program however it will artificially lit for a little bit longer after the cell turned off in order to simulate this effect.

 

Debugging circuits

Please read http://en.wikipedia.org/wiki/Debugging for understanding what debugging means.

Basic debugging tools

In Logic Circuit program you debug circuits by assigning input values and observing outputs.

The easiest way to get different input values in the runtime is to use Constant. In design time add a constant to your circuit, select desired bit with and initial value. In the runtime you can double click the constant and it will increment its value within it bit width. So if you constant are 1 bit wide, then double clicking it will change its value from 0 to 1 and reset it back to 0 while you double clicking it. Two bit constant will get values 0, 1, 2, 3, and 0 again.

The easiest way to observe output value is clicking your mouse and hold it on wire that connected to the output of interest. While you hold mouse button a little display will be showing bit width and value transferred by wire.

Wire display

More permanent way to observe output values is to use probes. In design time add probes to your circuit and connect them to pins you want to monitor. In the runtime you will read current value on the probe.

Constant connected to probe

More over probes are remembering history of values ever been measured. To see the history in the runtime double click the probe and probe dialog will pop up.

Probe history dialog

Sometimes your probe will be reading a series of values. You can mark such a series in the dialog with Mark button. When you click it a special line <<< Mark >>> will be inserted at the top of probe’s history, so all further changes will be easily separated from the earlier ones.

Mark in history

If you need to monitor values of a few probes at once and see how their values depend from each other you can open oscilloscope and see the dynamics of all your probes. In order to open the oscilloscope click menu Tools/Oscilloscope. This menu is enabled only in the runtime and only if you have at least one probe connected to your circuit.

Oscilloscope window

In the oscilloscope window you can start and stop measurement with Oscilloscoping check box.

Finally you can use truth table and scripts to validate your circuits.

Other debugging tips

Sometime it will be helpful to create a test circuit where you can play with your debugging circuit and see how it works. In more complicated scenarios you can to build a special environment where your debugging circuit receives a series of inputs and outputs get verified automatically.

But probably the best way is to design your circuit in small modules with clear and simple semantic so you will build error free circuits and don’t need to debug them at all.

 

Truth Table

You can generate a truth table for your subcircuit if it has input and output pins and doesn’t include memory elements like flip-flops or RAM. In other words, your circuit must behave like a pure function.

Learn more about pure functions: Pure Function (Wikipedia)

Learn more about truth tables: Truth Table (Wikipedia)

To create a truth table, go to the menu: Circuit/Truth Table.

Truth table of simple AND circuit

The dialog will show a table with columns labeled by the input and output pin names. Each row shows a combination of input values and the corresponding output.

Here’s another example using a full adder:

Truth table of full adder

The number of rows in a truth table equals 2 raised to the total number of input bits. For example, with 3 one-bit inputs, the table will have 23 = 8 rows. Adding more input bits increases the size of the table quickly. However, the dialog will only show up to 4096 rows for usability.

Filtering Rows

You can use a filter expression to display only certain rows. Filters use pin names and logical conditions. For example, for an AND gate, the filter q = x & y checks that output q matches the expected result.

There’s a checkbox to invert the filter. When checked, only the rows that don’t match the condition will appear. This is useful for debugging.

At the bottom of the dialog, you’ll see two numbers: total rows and the number currently displayed.

Expression Syntax

To use pin names in expressions:

  • If the name starts with a letter and contains only letters and numbers (e.g., x1Pin3), just use the name directly.
  • If the name contains special characters, spaces, or starts with a digit, put it in double quotes (e.g., "1a""out pin").
  • Escape quotes or backslashes in names using a backslash: "a\"""a\\pin".

 

You can write numbers in different formats:

  • Decimal: 010
  • Hexadecimal: 0x1A0XFF
  • Octal: 012077
  • Binary: 0b1010B0011

Use _ or ' in numbers for readability, e.g., 0b1010_0001.

 

Operations in Expressions

There are two types of operations:

  • Arithmetic – Performs calculations like addition or bitwise shifts.
  • Logical – Evaluates to 1 (true) or 0 (false), such as comparisons or logical AND.

Examples:

  • 3 + 4 results in 7 (arithmetic)
  • 3 < 5 results in 1 (logical)

Some supported operators:

PriorityOperatorDescription
1 (E) Parentheses
1 -E, ~E, !E Negation, Bitwise NOT, Logical NOT
2 <<, >> Bitwise Shifts
3 & Bitwise AND
4 |, ^ Bitwise OR, XOR
5 *, /, % Multiply, Divide, Modulus
6 +, - Add, Subtract
7 =, ==, !=, <>, <, <=, >, >= Comparisons
8 && Logical AND
9 || Logical OR

For example, if you're checking only the sum bit s of a full adder, you may need to mask the carry:

s = (inC + a + b) & 1

Using Functions

You can define reusable functions like this:

function_name(arg1, arg2, ...) : expression

Example: Check if a number is even:

is_even(n) : (n & 1) = 0

Use it in an expression like:

is_even(a + b) && is_even(c)

Another example using a multiplexer:

case(n, e) : (N = n) * e

case(0, X0) + case(1, X1) + case(2, X2) + case(3, X3) = Q

Make sure function names and their parameters don’t match any circuit pin names.

It is also possible to define a function without parameters. In such case just specify function name, colon, and expression for this function To call it just type its name. For example:

B:(b ^ (Nb * 0xF)) a + B = q && c + B = q

Where: B:(b ^ (Nb * 0xF)) is function definition and a + B = q && c + B = q is use of function B.

 

Displays

Sometimes you want to combine visualization logic with display element itself. For example you want to have a hexadecimal display which has 4 bit input and showing hexadecimal digit on 7 segment display.

Starting from version 2.13.07.22 you can do this. Just put display element on the circuit, add required logic with appropriate inputs. Open Logical Circuit dialog (you can do it via menu Circuit/Logical Circuit or just double click on an empty area of the circuit diagram). In the dialog check "Display visual elements on symbol" and click OK.

Creating display

Observe on the left panel of the program window that symbol of the circuit has changed and now it is showing 7 segment display itself.

New symbol of the display

Now when you use newly built display on other circuits it will display the value of its input.

You can nest displays one in another. For example you can use HEX display to build one byte hexadecimal display. Of course you’ll need to mark byte display to show it visual element on it symbol as well.

Nesting one display into another

You can use LEDs, LED matrixes, 7 segment displays, buttons, Graphics Arrays, and other logical circuit displays to build your display.

Here is an example of numeric keypad you can build.

Numeric keypad

Please download sample digital clock circuit project to see how it works.

 

Sensor

The sensor provides several ways to feed your circuit with data from the external world. You can partially configure the sensor before placing it on the design surface, or provide all the details in the dialog. To launch the sensor dialog, double-click it when the program is in editing mode.

To configure the sensor, first select the sensor type, then provide other data required by the selected type.
Here is a list of the available sensor types:

  • Series

    Allows you to provide a series of sensor measurements separated by spaces. Each measure is in the form {cycle}:{value}, where both cycle and value are hexadecimal numbers.
    - If the cycle is an even number or 0, it corresponds to a clock change from 0 to 1 (rising edge).
    - If the cycle is odd, the clock changes from 1 to 0 (falling edge).

    For example:

    1:4 2:5 6:F 9:4

    This will set the sensor output to:
    - 4 on the falling edge of the first cycle
    - 5 on the rising edge of the second cycle
    - F (15 in decimal) on the rising edge of the third cycle, and so on.

    If you check "Repeat series," the cycle will repeat after the series ends. If unchecked, the sensor will output the last value until power is turned off.

  • Random

    In this mode, the sensor outputs random numbers at random clock cycles. You can specify the minimum and maximum number of cycles before a change occurs.

  • Manual

    This mode allows you to manually enter a new value in hexadecimal format. The new value will be output after the "Enter" key is pressed or when the input loses focus.

  • Key Code

    In this mode, the output will be the number of the key pressed on the keyboard. The key code is an 8-bit number, so if fewer than 8 bits are specified, the number will be truncated.

  • ASCII Code

    In this mode, the output will be the ASCII code of the key pressed on the keyboard. The ASCII code is an 8-bit number, so if fewer than 8 bits are specified, the number will be truncated.

  • Sequence

    In this mode, the sensor will output the next sequential number starting from 0.

  • Clock

    The clock mode will output the current time of day in BCD format, with 32 bits divided into 4 groups of 8 bits each, representing hours, minutes, seconds, and hundredths of seconds.

 

Scripting language

Overview

Starting with version 2.17.03.20 LogicCircuit comes with scripting language. It uses one of the most popular one - Python. Because LogicCircuit is using Microsoft .NET framework the actual implementation of Python is IronPython.

With version 2.24.02.27 the Python upgraded to version 3.

There is a lot of resources on the Internet to get help with IronPython and Python in general.
If you are new to Python you can start with https://www.learnpython.org/ more advanced users can use https://ironpython-test.readthedocs.io/en/latest/reference/

To start using IronPython in LogicCircuit you open console by clicking menu Tools/IronPython Console.
The console let you type python expressions and get results. For starters type:

print("hello, world!")

after standard Python prompt ">>>" and hit Enter. You will see python printing the string. To make things a bit more interactive type:

print("hello, {0}".format(input("Enter your name: ")))

This will try to replace {0} with result of function input. Which in turn will print out prompt for you to type your name. Once you type it and hit Enter you will be greeted.

You can define a function. Just type:

def Greet(name):

and hit enter. You will see that Python did not execute your command. Instead it showed you three dots as a new prompt. That because your statement is incomplete. Just enter another text:

    print("hello {0}".format(name))

Please notice that you should prepend the print with a few spaces or tabs. Hit Enter and you will see another three dots prompt. This time just hit enter. This will inform console that you are done entering multiline statement. Now you have your function created and you can call it. Just type:

Greet("place your name here")

You will see Python greeting you.

Of course it is inconvenient to create functions this way. So you can just open your favorite text editor and create as many functions there as you want. In order to run your file, you will need to type in console:

exec(open(r"C:\location\file.py").read())

Please note letter r that prepending the string with the path. This will require to avoid need for doubling the slashes.

Once you have your script in a file you will probably run it more than once. Console remembers your commands and you can press up and down arrows on your keyboard to cycle through history of your commands.

If your script is executing for too long you can terminate it if press Ctrl+C. This will also cancel multiline expression mode. However, if you select something in console it will do normal copy to clipboard operation like in any other editor. If you hit Esc it will clean any text you have typed so far after prompt.

When you are typing in console it can help you by inserting suggestions on the global variables or members of object you have typed so far. To make console insert suggestion just start typing and hit Tab key on your keyboard. Console will try to append suggestions that match the text you typed. If you hit Tab multiple times the previous suggestion will be replaced with new match, cycling through all matching items.

Using script in LogicCircuit

The main reason for the scripting language in LogicCircuit is to let you test your circuits. The test script will set inputs of the circuit to the desired values, evaluate the circuit and read values from outputs. This is actually very similar to what truth table is doing, but in script you can test circuits with a state.

Let’s start with very simple circuit:

Repeater circuit

This circuit just repeats it’s input. To test it we will need to create a tester object. You can type right in the console or in the file and run it in console the following:

tester = App.CreateTester("Repeater")

Now variable tester contains object you can use to test the circuit.

In order to set value to some input you will need to execute the following statement:

tester.SetInput("x", 1)

The first parameter string x is the name of the input you want to set. The second is the value. Please note the value should fit into bits of the pin. For example, if you have 1-bit pin and will try to set it value to anything but 0 or 1 you will see the error:

Value 2 get truncated by pin x. Make sure value can fit to 1 bit(s) of the pin.

After you set all the desired values in the input pins of your circuit you can run it.

tester.Evaluate()

This function will return True if successful and False if there is an oscillation occurred.

Once you have successfully Run the circuit you will need to read values of output pins.

tester.GetOutput("q")

This will get value of output pin q.

Reading of evaluated values in some cases might be more complicated. If your circuit can produce high impedance values, the function GetOutput will not work and output error message:

CircuitException: Output value cannot be represented by number because it contains bit(s) in high impedance state: -. Use GetStateOutput instead.

As the message suggests you should use GetStateOutput function instead in such cases. This function will return 2 bits for every bit of the output pin. The state of this two bits are:

  • 0 - the output bit in the high impedance state
  • 1 - the output bit in 0 state
  • 2 - the output bit in 1 state

It is up to your script to analyze all bits of your output returned by this function. Python provides bitwise operations you can use for that.

Currently you cannot set values with high impedance bits into input pins. If you need to test your circuit with some inputs in such state, you can create a test bed circuit use Tri state gates connected to the circuit you want to test and then in script actually test the test bed circuit instead.

For some real example of script testing circuit you can download samples, open Digital Clock project and run DigitalClockTest.py script.

Other useful functionality.

So the main entry point to access LogicCircuit functionality in your script is App class.

Besides CreateTester method you can call App.ClearConsole() to clear IronPython console.

To access your circuit, you start with App.Editor property. This property returns editor of current project. The editor has bunch of other properties and methods you can use. For example you might want to get name of current project - App.Editor.Project.Name or file currently open - App.Editor.File in order to ensure the project you are testing is the right one.

You can access the main window of LogicCircuit via App.Editor.Mainframe. For example you can put a text in the status bar:

App.Editor.Mainframe.Status = "hello, world!"

Some properties and methods of any window are accessible from the script directly like the status text, but some are not so easy to use. The reason is in Windows any screen object must be accessed only from the execution thread that it was created on. You are running IronPython scripts on its own thread and hence if you try access UI from script directly you will get error message:

The calling thread cannot access this object because a different thread owns it.

It is even possible that you will be able to perform some window operations, but later when you try to navigate to different circuit from UI you will get that same error message. That is because some UI element were created on script thread now and not accessible from UI thread. In such case you can reopen the file.

In order to bypass this problem, you will need to run parts of your script that accessing UI on thread that is owning Window of LogicCircuit. The easiest way to do this is to create a function without arguments and pass it to App.Dispatch() method. Here is the example of function you can create to turn power on and off from script:

 

def Power(state):
    def Set():
        App.Editor.Power=state
    App.Dispatch(Set)

 

Now you can safely call function Power with 1 or 0 argument to turn on or off the power of your circuit.

Here is another fun code snippet for you. Just paste it in your console, hit Enter and enjoy the Matrix.

clr.AddReference("PresentationCore")
clr.AddReference("PresentationFramework")

def PlayMatrix():
    con = System.Windows.Window.GetWindow(System.Windows.Input.Keyboard.FocusedElement).Content
    con.Background = System.Windows.Media.Brushes.Black
    con.Foreground = System.Windows.Media.Brushes.GreenYellow

App.Dispatch(PlayMatrix)

And speaking of Matrix you should never run any scripts from unknown source. It can harm your computer, stole your private information and so on.

Transactions

In LogicCircuit all the schematics elements are stored in transactional memory. For more details on this you can read this article: Lock free parallel programming: transactions, snapshots, and change descriptions.

As a result, if you want to modify anything you will need to do this inside a transaction. Here is an example of how to change name of the project from your script. First let’s create a function:

def SetProjectName(name):
    def Set():
        App.Editor.Project.Name = name
    App.InTransaction(Set)

Now you can call it with desired name:

SetProjectName("hello, world")

Now you can open properties of your project via menu Circuit/Project and see the new name.

One of the biggest benefits of using transactional memory is the undo and redo operations are naturally supported. So after you change the name of the project via script you can undo it via menu Edit/Undo, and then redo it again with menu Edit/Redo.

Of course inside of one transaction you can change as many things as you want and all of them can be undone with just one menu click. On the other hand, the series of transactions can be undone in a series of undo actions.

As you probably figure out some changes when they bubbling up to UI will result thread issue errors, so you better do transaction inside of dispatch.

Please note when you are doing some long running operation on UI thread you won’t be able to abort the script with Ctrl+C as this is happening on UI thread and it is busy with your script. So avoid long running operations dispatched.

If this all sounds too complicated don’t warry, if your goal is just test your circuit you can do it with simple App.CreateTester function without any dispatcher or transactional gimmicks.

 

Command line parameters.

You can launch LogicCircuit and pass IronPython expression to execute on startup.

LogicCircuit.exe /run "print 'hello, world!'"

To remind you what parameters are support run:

LogicCircuit.exe /?
 

=========== End

 

posted @ 2026-08-07 21:38  lsgxeva  阅读(5)  评论(0)    收藏  举报