1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
|
.. py:currentmodule:: pyartnet
######################################
PyArtNet
######################################
pyartnet is a python implementation of the ArtNet protocol using
`asyncio <https://docs.python.org/3/library/asyncio.html>`_.
Supported protocols are ArtNet, sACN and KiNet.
Getting Started
==================================
.. exec_code::
# hide: start
from helper import MockedSocket
MockedSocket().mock()
import pyartnet.base.network as network_module
from ipaddress import IPv4Address
async def resolve_hostname(*args, **kwargs):
return [IPv4Address('127.0.0.1')]
network_module.resolve_hostname = resolve_hostname
# hide: stop
import asyncio
from pyartnet import ArtNetNode
async def main():
async with ArtNetNode.create('IP', 6454) as node:
# Create universe 0
universe = node.add_universe(0)
# Add a channel to the universe which consists of 3 values
# Default size of a value is 8Bit (0..255) so this would fill
# the DMX values 1..3 of the universe
channel = universe.add_channel(start=1, width=3)
# Fade channel to 255,0,0 in 5s
# The fade will automatically run in the background
channel.add_fade([255,0,0], 1000)
# this can be used to wait till the fade is complete
await channel
# hide: start
node.stop_refresh()
# hide: stop
asyncio.run(main())
Channels
==================================
Accessing channels
----------------------------------
Created channels can be requested from the universe through the ``[]`` syntax or through :meth:`BaseUniverse.get_channel`.
If no channel name is specified during creation the default name will be built with ``{START}/{WIDTH}``.
.. exec_code::
# hide: start
from helper import MockedSocket
MockedSocket().mock()
import pyartnet.base.network as network_module
from ipaddress import IPv4Address
async def resolve_hostname(*args, **kwargs):
return [IPv4Address('127.0.0.1')]
network_module.resolve_hostname = resolve_hostname
import asyncio
from pyartnet import ArtNetNode
async def main():
# hide: stop
# create node/universe
async with ArtNetNode.create('IP', 6454) as node:
universe = node.add_universe(0)
# create the channel
channel = universe.add_channel(start=1, width=3)
# after creation this would also work (default name)
channel = universe['1/3']
channel = universe.get_channel('1/3')
# it's possible to name the channel during creation
universe.add_channel(start=4, width=3, channel_name='Dimmer1')
# access is then by name
channel = universe['Dimmer1']
channel = universe.get_channel('Dimmer1')
# hide: start
asyncio.run(main())
# hide: stop
Wider channels
----------------------------------
Currently there is support for 8Bit, 16Bit, 24Bit and 32Bit channels.
Channel properties can be set when creating the channel through :meth:`BaseUniverse.add_channel`.
.. exec_code::
# hide: start
from helper import MockedSocket
MockedSocket().mock()
import pyartnet.base.network as network_module
from ipaddress import IPv4Address
async def resolve_hostname(*args, **kwargs):
return [IPv4Address('127.0.0.1')]
network_module.resolve_hostname = resolve_hostname
import asyncio
from pyartnet import ArtNetNode
async def main():
# hide: stop
# create node/universe
async with ArtNetNode.create('IP', 6454) as node:
universe = node.add_universe(0)
# create a 16bit channel
channel = universe.add_channel(start=1, width=3, byte_size=2)
# hide: start
asyncio.run(main())
# hide: stop
Output correction
==================================
Output correction
----------------------------------
It is possible to use an output correction to create different brightness curves.
`Output correction <Available output corrections>`_ can be set on the channel, the universe or the node.
The universe output correction overrides the node output correction and the channel output
correction overwrites the universe output correction.
The graph shows different output values depending on the output correction.
From left to right:
linear (default when nothing is set), quadratic, cubic then quadruple
.. image:: ../curves.svg
:alt: Value curves for output correction
Quadratic or cubic results in much smoother and more pleasant fades when using LED Strips.
Example
----------------------------------
.. exec_code::
# hide: start
from helper import MockedSocket
MockedSocket().mock()
import pyartnet.base.network as network_module
from ipaddress import IPv4Address
async def resolve_hostname(*args, **kwargs):
return [IPv4Address('127.0.0.1')]
network_module.resolve_hostname = resolve_hostname
import asyncio
async def main():
# hide: stop
from pyartnet import ArtNetNode, output_correction
# create node/universe/channel
async with ArtNetNode.create('IP', 6454) as node:
universe = node.add_universe(0)
channel = universe.add_channel(start=1, width=3)
# set quadratic correction for the whole universe to quadratic
universe.set_output_correction(output_correction.quadratic)
# Explicitly set output for this channel to linear
channel.set_output_correction(output_correction.linear)
# Remove output correction for the channel.
# The channel will now use the correction from the universe again
channel.set_output_correction(None)
# hide: start
asyncio.run(main())
# hide: stop
Class Reference
==================================
Universe and Channel
----------------------------------
.. autoclass:: BaseUniverse
:members:
:inherited-members:
:member-order: groupwise
.. autoclass:: Channel
:members:
:inherited-members:
:member-order: groupwise
Node implementations
----------------------------------
.. autoclass:: ArtNetNode
:members:
:inherited-members:
:member-order: groupwise
.. autoclass:: KiNetNode
:members:
:inherited-members:
:member-order: groupwise
.. autoclass:: SacnNode
:members:
:inherited-members:
:member-order: groupwise
Fades
----------------------------------
.. autoclass:: pyartnet.fades.LinearFade
:members:
:inherited-members:
:member-order: groupwise
Available output corrections
----------------------------------
.. automodule:: pyartnet.output_correction
:members:
|