network module

Build and execute the network.

Used in the Logic Simulator project to add and connect devices together.

Classes

Network - builds and executes the network.

class network.Network(names, devices)

Bases: object

Build and execute the network.

This class contains many functions required for connecting devices together in the network, getting information about connections, and executing all the devices in the network.

Parameters

devices – instance of the devices.Devices() class.

get_connected_output(self, device_id, output_id):

Returns the device and port id of the connected output.

get_input_signal(self, device_id, input_id):

Returns the signal level at the output connected to the given input.

get_output_signal(self, device_id, output_id):

Returns the signal level at the given output.

make_connection(self, first_device_id, first_port_id, second_device_id,

second_port_id): Connects the first device to the second device.

check_network(self):

Checks if all inputs in the network are connected.

update_signal(self, signal, target):

Updates the signal in the direction of the target.

invert_signal(self, signal):

Returns the inverse of the signal if the signal is HIGH or LOW.

execute_switch(self, device_id):

Simulates a switch press.

execute_gate(self, device_id, x=None, y=None):

Simulates a logic gate and updates its output signal value.

execute_d_type(self, device_id):

Simulates a D-type device and updates its output signal value.

execute_clock(self, device_id):

Simulates a clock and updates its output signal value.

update_clocks(self):

If it is time to do so, sets clock signals to RISING or FALLING.

execute_network(self):

Executes all the devices in the network for one simulation cycle.

check_network()

Return True if all inputs in the network are connected.

execute_clock(device_id)

Simulate a clock and update its output signal value.

Return True if successful.

execute_d_type(device_id)

Simulate a D-type device and update its output signal value.

Return True if successful.

execute_gate(device_id, x=None, y=None)

Simulate a logic gate and update its output signal value.

The rule is: if all its inputs are x, then its output is y, else its output is the inverse of y. Note: (x,y) pairs for AND, OR, NOR, NAND, XOR are: (HIGH, HIGH), (LOW, LOW), (LOW, HIGH), (HIGH, LOW), (None, None). Return True if successful.

execute_network()

Execute all the devices in the network for one simulation cycle.

Return True if successful and the network does not oscillate.

execute_not(device_id)

Simulate a NOR gate.

Return True if successful.

execute_switch(device_id)

Simulate a switch.

The output signal is updated to the switch_state target. Return True if successful.

get_connected_output(device_id, input_id)

Return the output connected to the given input.

Return None if either of the specified IDs is invalid or the input is unconnected. The output is of the form (device ID, port ID).

get_input_signal(device_id, input_id)

Return the signal level at the output connected to the given input.

Return None if the input is unconnected or the specified IDs are invalid.

get_output_signal(device_id, output_id)

Return the signal level at the given output.

Return None if either of the specified IDs is invalid.

invert_signal(signal)

Return the inverse of the signal if the signal is HIGH or LOW.

Return None if the signal is not HIGH or LOW.

make_connection(first_device_id, first_port_id, second_device_id, second_port_id)

Connect the first device to the second device.

Return self.NO_ERROR if successful, or the corresponding error if not.

update_clocks()

If it is time to do so, set clock signals to RISING or FALLING.

update_signal(signal, target)

Update the signal in the direction of the target.

Return updated signal, and set steady_state to false if the new signal is different from the old signal.