tools¶
Submodules¶
- clock
- digital
- ground
- multivibrator
- oscilloscope
- powersource
- steppermotor
clock¶
-
class
BinPy.tools.clock.
Clock
(init_state=1, frequency=None, time_period=None, name=None)¶ Bases:
threading.Thread
This class uses threading technique to create a clock with a certain time period.
>>> my_clock = Clock(0,time_period=2,name="My First Clock") >>> my_clock.get_state() 0
Parameters: - frequency (It will decide time interval of the clock, use SI unit i.e. Hertz) –
- time_period (It will also decide time interval of the clock, use SI unit i.e. second) –
- init_state (It is the initial state of the clock(1 by default)) –
- name (It is the name of the clock.(optional)) –
- time_period and frequency both have been provided, then time_period (If) –
- override frequency (will) –
- nothing is provided, then it will set time_period = 1s by default (If) –
- start() : [ Depricated ] To start the clock thread.
- Clock starts at __init__ itself. This need not be used.
get_state() : Get the current state of the clock. set_state() : To set the current state of the clock. kill() : To kill the clock thread.
state : [ Property ] Return the state of the clock. name : [ Property ] Return the name of the clock. time_period : [ Property ] Return the time period of the clock. frequency : [ Property ] Return the current frequency of the clock.
Note
Once you are done with the clock, use my_clock.kill() to kill the clock. Running too many clocks will unnecessarily overload the CPU.
All operations are thread safe and synchronized between inter / intra thread calls.
-
frequency
¶
-
get_state
()¶ Returns the current state of the clock
-
kill
()¶ Kills the clock(Thread)
-
name
¶ Returns the name of the clock
-
run
()¶
-
set_state
(value)¶ Resets the state of the clock to the passed value
-
start
()¶ Do not use this method
-
state
¶ Returns the currentd state of the clock as a property.
-
time_period
¶
digital¶
-
class
BinPy.tools.digital.
DigitDisplay
(name=None)¶ This class emulates a 7 segmented display(Common Cathode)
Parameters: name – A name given to an object(Optional) -
evaluate
()¶
-
getName
()¶
- How to use:
>>> myDisplay = DigitDisplay("Display1") >>> print myDisplay.evaluate([1,1,1,1,1,1,1]) 8
Note
You can either pass complete list of 10 pins [pin1, pin2, pin3, pin4, pin5, pin6, pin7, pin8, pin9, pin10] in standard order or you can directly pass the list of values corresponding to a, b, c, d, e, f and g in lexicographical order.
http://tronixstuff.files.wordpress.com/2010/05/7segpinout.jpg
-
evaluate
(pin_conf) This method evaluates the values passed according to the display and returns an integer varying from 0 to 9
-
ground¶
-
class
BinPy.tools.ground.
Ground
¶ Models a Ground from which various connectors can tap by connecting to it. taps: The list of all connectors connected to this ground. connect(): Takes in one or more connectors as input and connects them to the ground. disconnect(): Takes in one or more connectors as input and disconnects them from the ground.
-
connect
(*connectors)¶ Takes in one or more connectors as an input and taps to the ground.
-
disconnect
(*connectors)¶ Takes in one or more connectors as an input and disconnects them from the ground. A floating connector has a value of None. A message is printed if a specified connector is not already tapping from this ground.
-
multivibrator¶
-
class
BinPy.tools.multivibrator.
Multivibrator
(init_state=1, mode=1, frequency=None, time_period=None, on_time=None, off_time=None)¶ Bases:
threading.Thread
This class uses threading technique to create a multivibrator with a certain time period. USAGE:
>>> m1 = Multivibrator() >>> m1.trigger() # or m1() >>> m1.get_state() # or m1.A.state 0 >>> m1.set_mode(2) >>> m1.trigger() >>> m1.get_state() >>> conn = Connector() >>> m1.set_output(conn) # To set the output to connector conn >>> conn() # Retrieves the current state
- Note: Once you are done with the multivibrator, use m1.kill() to kill the Multivibrators.
>>> m1.kill()
Following are the parameters of the class
frequency: It will decide time interval of the Multivibrator, use SI unit i.e. Hertz time_period: It will also decide time interval of the Multivibrator, use SI unit i.e. second
If time_period and frequency both have been provided, then time_period will override frequency If nothing is provided, then it will set time_period = 1s by default
init_state: It is the initial state of the multivibrator(1 by default)
- mode: It is the mode of operation.
- 1 –> Monostable 2 –> Astable 3 –> Bistable
Methods : trigger(),setMode(), getState(), setState(value), getTimePeriod(), kill(), stop(), setOutput()
-
get_state
()¶ Returns the current state
-
kill
()¶ Kills the Thread
-
run
()¶
-
set_mode
(mode)¶ Sets the mode of the Multivibrator
-
set_output
(conn)¶
-
set_state
(value)¶ Resets the state of the clock to the passed value
-
start
()¶ Do not use this method
-
stop
()¶
-
time_period
()¶ Returns the time period of the clock
-
trigger
()¶
oscilloscope¶
-
class
BinPy.tools.oscilloscope.
Oscilloscope
(*inputs)¶ Bases:
threading.Thread
Oscilloscope is helpful in visualizing simulations.
USAGE: # A clock of 1 hertz frequency clock = Clock(1, 1) clk_conn = clock.A
bc = BinaryCounter() os1 = Oscilloscope( (bc.out[1],’lsb’) , (bc.out[0],’msb’)) #Triggering the counter: for i in range(5):
b.trigger() print (b.state())os1.stop() os1.display()
-
clear
(keepInputs=False)¶
-
disconnect
(conn)¶ Disconnects conn from the inputDict
-
display
()¶
-
hold
()¶
-
kill
()¶
-
run
()¶
-
sampler
(trigPoint)¶
-
set_colour
(foreground=None, background=None)¶ Acceptable values are: 1 –> RED 2 –> GREEN 4 –> BLUE 7 –> WHITE
To RESET call without parameters.
Please note that serColor is not supported by all operating systems. This will run without problems on most Linux systems.
-
set_inputs
(*inputs)¶ Set inputs using a list of tuples.
For example: osc1.setInputs((conn1,”label”) , (conn2,”label”) ... )
-
set_scale
(scale=0.05)¶ This decides the time per unit xWidth. To avoid waveform distortion, follow NYQUIST sampling theorem. That is if the least time period of the waveform is T; Set the scale to be greater than T/2 [ preferably T/5 - To avoid edge sampling effects ]
There is a lower bound on the scale value [ use trial and error to identify this for your particular PC ] This limitation is set by the processing time taken to set a plot etc.
-
set_width
(w=150)¶ Set the maximum width of the oscilloscope. This is dependent on your current monitor configuration.
-
start
()¶ Do not use this method
-
unhold
()¶
-
powersource¶
-
class
BinPy.tools.powersource.
PowerSource
¶ Models a Power Source from which various connectors can tap by connecting to it.
taps: The list of all connectors connected to this power source.
connect(): Takes in one or more connectors as input and connects them to the power source.
disconnect(): Takes in one or more connectors as input and disconnects them from the power source.
-
connect
(*connectors)¶ Takes in one or more connectors as an input and taps to the power source.
-
disconnect
(*connectors)¶ Takes in one or more connectors as an input and disconnects them from the power source. A floating connector has a value of None. A message is printed if a specified connector is not already tapping from this source.
-