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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
|
%global _empty_manifest_terminate_build 0
Name: python-sacn
Version: 1.9.0
Release: 1
Summary: sACN / E1.31 module for easy handling of DMX data over ethernet
License: MIT License
URL: https://www.github.com/Hundemeier/sacn
Source0: https://mirrors.nju.edu.cn/pypi/web/packages/2b/3a/5f7fa70575492ed6fbbf3cb2093059c6d38ae634cd96f3b6de0930720371/sacn-1.9.0.tar.gz
BuildArch: noarch
%description
## Usage
### Sending
To use the sending functionality you have to use the `sACNsender`.
```python
import sacn
import time
sender = sacn.sACNsender() # provide an IP-Address to bind to if you want to send multicast packets from a specific interface
sender.start() # start the sending thread
sender.activate_output(1) # start sending out data in the 1st universe
sender[1].multicast = True # set multicast to True
# sender[1].destination = "192.168.1.20" # or provide unicast information.
# Keep in mind that if multicast is on, unicast is not used
sender[1].dmx_data = (1, 2, 3, 4) # some test DMX data
time.sleep(10) # send the data for 10 seconds
sender.stop() # do not forget to stop the sender
```
You can activate an output universe via `activate_output(<universe>)` and then change the attributes of this universe
via `sender[<universe>].<attribute>`. To deactivate an output use `deactivate_output(<universe>)`. The output is
terminated like the [E1.31][e1.31] describes it on page 14.
If you want to flush manually and the sender thread should not send out automatic, use the
`sACNsender.manual_flush` option. This is useful when you want to use a fixture that is using more than one universe
and all the data on multiple universes should send out at the same time.
Tip: you can get the activated outputs with `get_active_outputs()` and you can move an output with all its settings
from one universe to another with `move_universe(<from>, <to>)`.
Available Attributes for `sender[<universe>].<attribute>` are:
* `destination: str`: the unicast destination as string. (eg "192.168.1.150") Default: "127.0.0.1"
* `multicast: bool`: set whether to send out via multicast or not. Default: False
If True the data is send out via multicast and not unicast.
* `ttl: int`: the time-to-live for the packets that are send out via multicast on this universe. Default: 8
* `priority: int`: (must be between 0-200) the priority for this universe that is send out. If multiple sources in a
network are sending to the same receiver the data with the highest priority wins. Default: 100
* `preview_data: bool`: Flag to mark the data as preview data for visualization purposes. Default: False
* `dmx_data: tuple`: the DMX data as a tuple. Max length is 512 and for legacy devices all data that is smaller than
512 is merged to a 512 length tuple with 0 as filler value. The values in the tuple have to be [0-255]!
`sACNsender` Creates a sender object. A sender is used to manage multiple sACN universes and handles their output.
DMX data is send out every second, when no data changes. Some changes may be not send out, because the fps
setting defines how often packets are send out to prevent network overuse. So if you change the DMX values too
often in a second they may not all been send. Vary the fps parameter to your needs (Default=30).
* `bind_address: str`: the IP-Address to bind to.
Provide an IP-Address to bind to if you want to send multicast packets from a specific interface.
* `bind_port: int`: optionally bind to a specific port. Default=5568. It is not recommended to change the port.
Change the port number if you have trouble with another program or the sACNreceiver blocking the port
* `source_name: str`: the source name used in the sACN packets. See the [standard][e1.31] for more information.
* `cid: tuple`: the cid. If not given, a random CID will be generated. See the [standard][e1.31] for more information.
* `fps: int` the frames per second. See explanation above. Has to be >0. Default: 30
* `universeDiscovery: bool` if true, universe discovery messages are send out via broadcast every 10s. Default: True
* `sync_universe: int` set a specific universe used in the sync-packets. Default: 63999
When manually flushed, the E1.31 sync feature is used. So all universe data is send out, and after all data was send out
a sync packet is send to all receivers and then they are allowed to display the received data. Note that not all
receiver implemented this feature of the sACN protocol.
Example for the usage of the manual_flush:
```python
import sacn
import time
sender = sacn.sACNsender()
sender.start()
sender.activate_output(1)
sender.activate_output(2)
sender[1].multicast = True
sender[2].multicast = True
sender.manual_flush = True # turning off the automatic sending of packets
sender[1].dmx_data = (1, 2, 3, 4) # some test DMX data
sender[2].dmx_data = (5, 6, 7, 8) # by the time we are here, the above data would be already send out,
# if manual_flush would be False. This could cause some jitter
# so instead we are flushing manual
time.sleep(1) # let the sender initialize itself
sender.flush()
sender.manual_flush = False # keep manual flush off as long as possible, because if it is on, the automatic
# sending of packets is turned off and that is not recommended
sender.stop() # stop sending out
```
### Receiving
To use the receiving functionality you have to use the `sACNreceiver`.
```python
import sacn
import time
# provide an IP-Address to bind to if you want to send multicast packets from a specific interface
receiver = sacn.sACNreceiver()
receiver.start() # start the receiving thread
# define a callback function
@receiver.listen_on('universe', universe=1) # listens on universe 1
def callback(packet): # packet type: sacn.DataPacket
print(packet.dmxData) # print the received DMX data
# optional: if multicast is desired, join with the universe number as parameter
receiver.join_multicast(1)
time.sleep(10) # receive for 10 seconds
# optional: if multicast was previously joined
receiver.leave_multicast(1)
receiver.stop()
```
The usage of the receiver is way more simple than the sender.
The `sACNreceiver` can be initialized with the following parameters:
* `bind_address: str`: Provide an IP-Address to bind to if you want to receive multicast packets from a specific interface.
* `bind_port: int`: Default: 5568. It is not recommended to change this value!
Only use when you are know what you are doing!
Please keep in mind to not use the callbacks for time consuming tasks!
If you do this, then the receiver can not react fast enough on incoming messages!
Functions:
* `join_multicast(<universe>)`: joins the multicast group for the specific universe.
* `leave_multicast(<universe>)`: leave the multicast group specified by the universe.
* `get_possible_universes()`: Returns a tuple with all universes that have sources that are sending out data and this
data is received by this machine
* `register_listener(<trigger>, <callback>, **kwargs)`: register a listener for the given trigger.
You can also use the decorator `listen_on(<trigger>, **kwargs)`. Possible trigger so far:
* `availability`: gets called when there is no data for a universe anymore or there is now data
available. This gets also fired if a source terminates a stream via the stream_termination bit.
The callback should get two arguments: `callback(universe, changed)`
* `universe: int`: is the universe where the action happened
* `changed: str`: can be 'timeout' or 'available'
* `universe`: registers a listener for the given universe. The callback gets only one parameter, the DataPacket.
You can also use the decorator `@listen_on('universe', universe=<universe>)`.
The callback should have one argument: `callback(packet)`
* `packet: DataPacket`: the received DataPacket with all information
* `remove_listener(<callback>)`: removes a previously registered listener regardless of the trigger.
This means a listener can only be removed completely, even if it was listening to multiple universes.
If the function never was registered, nothing happens.
Note: if a function was registered multiple times, this remove function needs to be called only once.
* `remove_listener_from_universe(<universe>)`: removes all listeners from the given universe.
This does only have effect on the 'universe' listening trigger.
If no function was registered for this universe, nothing happens.
### DataPacket
This is an abstract representation of an sACN Data packet that carries the DMX data. This class is used internally by
the module and is used in the callbacks of the receiver.
The DataPacket provides following attributes:
* `sourceName: str`: a string that is used to identify the source. Only the first 64 bytes are used.
* `priority: int`: the priority used to manage multiple DMX data on one receiver. [1-200] Default: 100
* `universe: int`: the universe for the whole message and its DMX data. [1-63999]
* `sequence: int`: the sequence number. Should increment for every new message and can be used to check for wrong
order of arriving packets.
* `option_StreamTerminated: bool`: True if this packet is the last one of the stream for the given universe.
* `option_PreviewData: bool`: True if this data is for visualization purposes.
* `option_ForceSync: bool`: True if this should only function in a synchronized state.
* `dmxStartCode: int`: the start code for the data tuple. [1-255] Default: 0x00 for streaming level data. See
[Alternate START Codes](https://tsp.esta.org/tsp/working_groups/CP/DMXAlternateCodes.php) for more information.
* `dmxData: tuple`: the DMX data as tuple. Max length is 512 and shorter tuples getting normalized to a length of 512.
Filled with 0 for empty spaces.
## Development
Some tools are used to help with development of this library. These are [flake8](https://flake8.pycqa.org), [pytest](https://pytest.org) and [coverage.py](https://coverage.readthedocs.io).
Install those tools with pip:
```
pip install flake8 pytest pytest-timeout coverage
```
`flake8` checks for formatting issues and can be run with `flake8` or `python -m flake8` in the root directory of this repository.
`pytest` is used for unit testing and can be executed with `pytest` or `python -m pytest` in the root directory of this repository.
By default, this skips the integration test, which uses real hardware I/O and might not run in every configuration.
Use the flag `--run-integration-tests` to run the additional tests (e.g. `python -m pytest --run-integration-tests`)
It is useful to check if the test coverage changed with `coverage run -m pytest` and then `coverage html`, which generates a `htmlcov/index.html` file with all the information.
### Changelog
* 1.9.0: The behavior of multicast sending and receiving is now unified across most operating systems. This means Windows no longer requires to set a `bind_address` to be able to use multicast or universe discovery. (Thanks to mthespian! See #42 for more information)
* 1.8.1: Calling `stop` on a sender or receiver now closes the underlying socket too. Note: after stopping a sender or receiver, it can not be started again with `start`. (See #39 for more information)
* 1.8.0: Added function for removing a listener on a receiver by universe. See `sACNreceiver.remove_listener_from_universe(<universe>)` for more information.
* 1.7.1: Small changes that might improve timing on the sender. (Thanks to mthespian! See #36 for more information)
* 1.7.0: Added function for removing a listener on a receiver. See `sACNreceiver.remove_listener(<callback>)` for more information.
* 1.6.4: Functionality related to sending of sACN data is now mostly covered by tests. Removed undocumented parameters for `sACNsender.start()`.
* 1.6.3: Functionality related to receiving sACN data is now mostly covered by tests. Fixed a bug, where an exception was thrown on the first `DataPacket` when the stream-termination option was set. (Additional thanks to mthespian! See #31 for more information)
* 1.6.2: Test coverage of sub-module `messages` is now 100%. Fixed a bug where a too long source name did not throw an exception.
Fixed a bug where invalid DMX data could be set on the `DataPacket`. (Thanks to mthespian! See #30 for more information)
* 1.6.1: Fixed a bug, where the DMX start code was not set on received packets (Thanks to mthespian! See #29 for more information)
* 1.6: Added dmxStartCode property to DataPacket (Thanks to mthespian! see #27 for more information)
* 1.5: Performance improvement: Deleted debugging statements in hot path of packet sending and receiving (Thanks to shauneccles! See #25 for more information)
* 1.4.6: Fix: When creating a DataPacket with invalid DMX start codes (i.e. not `0x00`) an exception is thrown (Thanks to niggiover9000! See #11 for more information)
* 1.4.5: When using a manual flush, only a specified list of universes can be flushed (Thanks to CrazyIvan359! See #22 for more information)
* 1.4.4: The universe used for the sACN-sync messages can now be set when creating a `sACNsender` (Thanks to CrazyIvan359! See #21 for more information)
* 1.4.3: The sequence number of the sync-packet when using manual flush was not increased (Thanks to @BlakeGarner ! See #19 for more information)
* 1.4.2: The internal logging of the receiver_thread and output_thread was using the root logger instead of its module-logger. (Thanks to @mje-nz ! See #18 for more information)
* 1.4: Added a manual flush feature for sending out all universes at the same time. Thanks to ahodges9 for the idea.
[e1.31]: http://tsp.esta.org/tsp/documents/docs/E1-31-2016.pdf
%package -n python3-sacn
Summary: sACN / E1.31 module for easy handling of DMX data over ethernet
Provides: python-sacn
BuildRequires: python3-devel
BuildRequires: python3-setuptools
BuildRequires: python3-pip
%description -n python3-sacn
## Usage
### Sending
To use the sending functionality you have to use the `sACNsender`.
```python
import sacn
import time
sender = sacn.sACNsender() # provide an IP-Address to bind to if you want to send multicast packets from a specific interface
sender.start() # start the sending thread
sender.activate_output(1) # start sending out data in the 1st universe
sender[1].multicast = True # set multicast to True
# sender[1].destination = "192.168.1.20" # or provide unicast information.
# Keep in mind that if multicast is on, unicast is not used
sender[1].dmx_data = (1, 2, 3, 4) # some test DMX data
time.sleep(10) # send the data for 10 seconds
sender.stop() # do not forget to stop the sender
```
You can activate an output universe via `activate_output(<universe>)` and then change the attributes of this universe
via `sender[<universe>].<attribute>`. To deactivate an output use `deactivate_output(<universe>)`. The output is
terminated like the [E1.31][e1.31] describes it on page 14.
If you want to flush manually and the sender thread should not send out automatic, use the
`sACNsender.manual_flush` option. This is useful when you want to use a fixture that is using more than one universe
and all the data on multiple universes should send out at the same time.
Tip: you can get the activated outputs with `get_active_outputs()` and you can move an output with all its settings
from one universe to another with `move_universe(<from>, <to>)`.
Available Attributes for `sender[<universe>].<attribute>` are:
* `destination: str`: the unicast destination as string. (eg "192.168.1.150") Default: "127.0.0.1"
* `multicast: bool`: set whether to send out via multicast or not. Default: False
If True the data is send out via multicast and not unicast.
* `ttl: int`: the time-to-live for the packets that are send out via multicast on this universe. Default: 8
* `priority: int`: (must be between 0-200) the priority for this universe that is send out. If multiple sources in a
network are sending to the same receiver the data with the highest priority wins. Default: 100
* `preview_data: bool`: Flag to mark the data as preview data for visualization purposes. Default: False
* `dmx_data: tuple`: the DMX data as a tuple. Max length is 512 and for legacy devices all data that is smaller than
512 is merged to a 512 length tuple with 0 as filler value. The values in the tuple have to be [0-255]!
`sACNsender` Creates a sender object. A sender is used to manage multiple sACN universes and handles their output.
DMX data is send out every second, when no data changes. Some changes may be not send out, because the fps
setting defines how often packets are send out to prevent network overuse. So if you change the DMX values too
often in a second they may not all been send. Vary the fps parameter to your needs (Default=30).
* `bind_address: str`: the IP-Address to bind to.
Provide an IP-Address to bind to if you want to send multicast packets from a specific interface.
* `bind_port: int`: optionally bind to a specific port. Default=5568. It is not recommended to change the port.
Change the port number if you have trouble with another program or the sACNreceiver blocking the port
* `source_name: str`: the source name used in the sACN packets. See the [standard][e1.31] for more information.
* `cid: tuple`: the cid. If not given, a random CID will be generated. See the [standard][e1.31] for more information.
* `fps: int` the frames per second. See explanation above. Has to be >0. Default: 30
* `universeDiscovery: bool` if true, universe discovery messages are send out via broadcast every 10s. Default: True
* `sync_universe: int` set a specific universe used in the sync-packets. Default: 63999
When manually flushed, the E1.31 sync feature is used. So all universe data is send out, and after all data was send out
a sync packet is send to all receivers and then they are allowed to display the received data. Note that not all
receiver implemented this feature of the sACN protocol.
Example for the usage of the manual_flush:
```python
import sacn
import time
sender = sacn.sACNsender()
sender.start()
sender.activate_output(1)
sender.activate_output(2)
sender[1].multicast = True
sender[2].multicast = True
sender.manual_flush = True # turning off the automatic sending of packets
sender[1].dmx_data = (1, 2, 3, 4) # some test DMX data
sender[2].dmx_data = (5, 6, 7, 8) # by the time we are here, the above data would be already send out,
# if manual_flush would be False. This could cause some jitter
# so instead we are flushing manual
time.sleep(1) # let the sender initialize itself
sender.flush()
sender.manual_flush = False # keep manual flush off as long as possible, because if it is on, the automatic
# sending of packets is turned off and that is not recommended
sender.stop() # stop sending out
```
### Receiving
To use the receiving functionality you have to use the `sACNreceiver`.
```python
import sacn
import time
# provide an IP-Address to bind to if you want to send multicast packets from a specific interface
receiver = sacn.sACNreceiver()
receiver.start() # start the receiving thread
# define a callback function
@receiver.listen_on('universe', universe=1) # listens on universe 1
def callback(packet): # packet type: sacn.DataPacket
print(packet.dmxData) # print the received DMX data
# optional: if multicast is desired, join with the universe number as parameter
receiver.join_multicast(1)
time.sleep(10) # receive for 10 seconds
# optional: if multicast was previously joined
receiver.leave_multicast(1)
receiver.stop()
```
The usage of the receiver is way more simple than the sender.
The `sACNreceiver` can be initialized with the following parameters:
* `bind_address: str`: Provide an IP-Address to bind to if you want to receive multicast packets from a specific interface.
* `bind_port: int`: Default: 5568. It is not recommended to change this value!
Only use when you are know what you are doing!
Please keep in mind to not use the callbacks for time consuming tasks!
If you do this, then the receiver can not react fast enough on incoming messages!
Functions:
* `join_multicast(<universe>)`: joins the multicast group for the specific universe.
* `leave_multicast(<universe>)`: leave the multicast group specified by the universe.
* `get_possible_universes()`: Returns a tuple with all universes that have sources that are sending out data and this
data is received by this machine
* `register_listener(<trigger>, <callback>, **kwargs)`: register a listener for the given trigger.
You can also use the decorator `listen_on(<trigger>, **kwargs)`. Possible trigger so far:
* `availability`: gets called when there is no data for a universe anymore or there is now data
available. This gets also fired if a source terminates a stream via the stream_termination bit.
The callback should get two arguments: `callback(universe, changed)`
* `universe: int`: is the universe where the action happened
* `changed: str`: can be 'timeout' or 'available'
* `universe`: registers a listener for the given universe. The callback gets only one parameter, the DataPacket.
You can also use the decorator `@listen_on('universe', universe=<universe>)`.
The callback should have one argument: `callback(packet)`
* `packet: DataPacket`: the received DataPacket with all information
* `remove_listener(<callback>)`: removes a previously registered listener regardless of the trigger.
This means a listener can only be removed completely, even if it was listening to multiple universes.
If the function never was registered, nothing happens.
Note: if a function was registered multiple times, this remove function needs to be called only once.
* `remove_listener_from_universe(<universe>)`: removes all listeners from the given universe.
This does only have effect on the 'universe' listening trigger.
If no function was registered for this universe, nothing happens.
### DataPacket
This is an abstract representation of an sACN Data packet that carries the DMX data. This class is used internally by
the module and is used in the callbacks of the receiver.
The DataPacket provides following attributes:
* `sourceName: str`: a string that is used to identify the source. Only the first 64 bytes are used.
* `priority: int`: the priority used to manage multiple DMX data on one receiver. [1-200] Default: 100
* `universe: int`: the universe for the whole message and its DMX data. [1-63999]
* `sequence: int`: the sequence number. Should increment for every new message and can be used to check for wrong
order of arriving packets.
* `option_StreamTerminated: bool`: True if this packet is the last one of the stream for the given universe.
* `option_PreviewData: bool`: True if this data is for visualization purposes.
* `option_ForceSync: bool`: True if this should only function in a synchronized state.
* `dmxStartCode: int`: the start code for the data tuple. [1-255] Default: 0x00 for streaming level data. See
[Alternate START Codes](https://tsp.esta.org/tsp/working_groups/CP/DMXAlternateCodes.php) for more information.
* `dmxData: tuple`: the DMX data as tuple. Max length is 512 and shorter tuples getting normalized to a length of 512.
Filled with 0 for empty spaces.
## Development
Some tools are used to help with development of this library. These are [flake8](https://flake8.pycqa.org), [pytest](https://pytest.org) and [coverage.py](https://coverage.readthedocs.io).
Install those tools with pip:
```
pip install flake8 pytest pytest-timeout coverage
```
`flake8` checks for formatting issues and can be run with `flake8` or `python -m flake8` in the root directory of this repository.
`pytest` is used for unit testing and can be executed with `pytest` or `python -m pytest` in the root directory of this repository.
By default, this skips the integration test, which uses real hardware I/O and might not run in every configuration.
Use the flag `--run-integration-tests` to run the additional tests (e.g. `python -m pytest --run-integration-tests`)
It is useful to check if the test coverage changed with `coverage run -m pytest` and then `coverage html`, which generates a `htmlcov/index.html` file with all the information.
### Changelog
* 1.9.0: The behavior of multicast sending and receiving is now unified across most operating systems. This means Windows no longer requires to set a `bind_address` to be able to use multicast or universe discovery. (Thanks to mthespian! See #42 for more information)
* 1.8.1: Calling `stop` on a sender or receiver now closes the underlying socket too. Note: after stopping a sender or receiver, it can not be started again with `start`. (See #39 for more information)
* 1.8.0: Added function for removing a listener on a receiver by universe. See `sACNreceiver.remove_listener_from_universe(<universe>)` for more information.
* 1.7.1: Small changes that might improve timing on the sender. (Thanks to mthespian! See #36 for more information)
* 1.7.0: Added function for removing a listener on a receiver. See `sACNreceiver.remove_listener(<callback>)` for more information.
* 1.6.4: Functionality related to sending of sACN data is now mostly covered by tests. Removed undocumented parameters for `sACNsender.start()`.
* 1.6.3: Functionality related to receiving sACN data is now mostly covered by tests. Fixed a bug, where an exception was thrown on the first `DataPacket` when the stream-termination option was set. (Additional thanks to mthespian! See #31 for more information)
* 1.6.2: Test coverage of sub-module `messages` is now 100%. Fixed a bug where a too long source name did not throw an exception.
Fixed a bug where invalid DMX data could be set on the `DataPacket`. (Thanks to mthespian! See #30 for more information)
* 1.6.1: Fixed a bug, where the DMX start code was not set on received packets (Thanks to mthespian! See #29 for more information)
* 1.6: Added dmxStartCode property to DataPacket (Thanks to mthespian! see #27 for more information)
* 1.5: Performance improvement: Deleted debugging statements in hot path of packet sending and receiving (Thanks to shauneccles! See #25 for more information)
* 1.4.6: Fix: When creating a DataPacket with invalid DMX start codes (i.e. not `0x00`) an exception is thrown (Thanks to niggiover9000! See #11 for more information)
* 1.4.5: When using a manual flush, only a specified list of universes can be flushed (Thanks to CrazyIvan359! See #22 for more information)
* 1.4.4: The universe used for the sACN-sync messages can now be set when creating a `sACNsender` (Thanks to CrazyIvan359! See #21 for more information)
* 1.4.3: The sequence number of the sync-packet when using manual flush was not increased (Thanks to @BlakeGarner ! See #19 for more information)
* 1.4.2: The internal logging of the receiver_thread and output_thread was using the root logger instead of its module-logger. (Thanks to @mje-nz ! See #18 for more information)
* 1.4: Added a manual flush feature for sending out all universes at the same time. Thanks to ahodges9 for the idea.
[e1.31]: http://tsp.esta.org/tsp/documents/docs/E1-31-2016.pdf
%package help
Summary: Development documents and examples for sacn
Provides: python3-sacn-doc
%description help
## Usage
### Sending
To use the sending functionality you have to use the `sACNsender`.
```python
import sacn
import time
sender = sacn.sACNsender() # provide an IP-Address to bind to if you want to send multicast packets from a specific interface
sender.start() # start the sending thread
sender.activate_output(1) # start sending out data in the 1st universe
sender[1].multicast = True # set multicast to True
# sender[1].destination = "192.168.1.20" # or provide unicast information.
# Keep in mind that if multicast is on, unicast is not used
sender[1].dmx_data = (1, 2, 3, 4) # some test DMX data
time.sleep(10) # send the data for 10 seconds
sender.stop() # do not forget to stop the sender
```
You can activate an output universe via `activate_output(<universe>)` and then change the attributes of this universe
via `sender[<universe>].<attribute>`. To deactivate an output use `deactivate_output(<universe>)`. The output is
terminated like the [E1.31][e1.31] describes it on page 14.
If you want to flush manually and the sender thread should not send out automatic, use the
`sACNsender.manual_flush` option. This is useful when you want to use a fixture that is using more than one universe
and all the data on multiple universes should send out at the same time.
Tip: you can get the activated outputs with `get_active_outputs()` and you can move an output with all its settings
from one universe to another with `move_universe(<from>, <to>)`.
Available Attributes for `sender[<universe>].<attribute>` are:
* `destination: str`: the unicast destination as string. (eg "192.168.1.150") Default: "127.0.0.1"
* `multicast: bool`: set whether to send out via multicast or not. Default: False
If True the data is send out via multicast and not unicast.
* `ttl: int`: the time-to-live for the packets that are send out via multicast on this universe. Default: 8
* `priority: int`: (must be between 0-200) the priority for this universe that is send out. If multiple sources in a
network are sending to the same receiver the data with the highest priority wins. Default: 100
* `preview_data: bool`: Flag to mark the data as preview data for visualization purposes. Default: False
* `dmx_data: tuple`: the DMX data as a tuple. Max length is 512 and for legacy devices all data that is smaller than
512 is merged to a 512 length tuple with 0 as filler value. The values in the tuple have to be [0-255]!
`sACNsender` Creates a sender object. A sender is used to manage multiple sACN universes and handles their output.
DMX data is send out every second, when no data changes. Some changes may be not send out, because the fps
setting defines how often packets are send out to prevent network overuse. So if you change the DMX values too
often in a second they may not all been send. Vary the fps parameter to your needs (Default=30).
* `bind_address: str`: the IP-Address to bind to.
Provide an IP-Address to bind to if you want to send multicast packets from a specific interface.
* `bind_port: int`: optionally bind to a specific port. Default=5568. It is not recommended to change the port.
Change the port number if you have trouble with another program or the sACNreceiver blocking the port
* `source_name: str`: the source name used in the sACN packets. See the [standard][e1.31] for more information.
* `cid: tuple`: the cid. If not given, a random CID will be generated. See the [standard][e1.31] for more information.
* `fps: int` the frames per second. See explanation above. Has to be >0. Default: 30
* `universeDiscovery: bool` if true, universe discovery messages are send out via broadcast every 10s. Default: True
* `sync_universe: int` set a specific universe used in the sync-packets. Default: 63999
When manually flushed, the E1.31 sync feature is used. So all universe data is send out, and after all data was send out
a sync packet is send to all receivers and then they are allowed to display the received data. Note that not all
receiver implemented this feature of the sACN protocol.
Example for the usage of the manual_flush:
```python
import sacn
import time
sender = sacn.sACNsender()
sender.start()
sender.activate_output(1)
sender.activate_output(2)
sender[1].multicast = True
sender[2].multicast = True
sender.manual_flush = True # turning off the automatic sending of packets
sender[1].dmx_data = (1, 2, 3, 4) # some test DMX data
sender[2].dmx_data = (5, 6, 7, 8) # by the time we are here, the above data would be already send out,
# if manual_flush would be False. This could cause some jitter
# so instead we are flushing manual
time.sleep(1) # let the sender initialize itself
sender.flush()
sender.manual_flush = False # keep manual flush off as long as possible, because if it is on, the automatic
# sending of packets is turned off and that is not recommended
sender.stop() # stop sending out
```
### Receiving
To use the receiving functionality you have to use the `sACNreceiver`.
```python
import sacn
import time
# provide an IP-Address to bind to if you want to send multicast packets from a specific interface
receiver = sacn.sACNreceiver()
receiver.start() # start the receiving thread
# define a callback function
@receiver.listen_on('universe', universe=1) # listens on universe 1
def callback(packet): # packet type: sacn.DataPacket
print(packet.dmxData) # print the received DMX data
# optional: if multicast is desired, join with the universe number as parameter
receiver.join_multicast(1)
time.sleep(10) # receive for 10 seconds
# optional: if multicast was previously joined
receiver.leave_multicast(1)
receiver.stop()
```
The usage of the receiver is way more simple than the sender.
The `sACNreceiver` can be initialized with the following parameters:
* `bind_address: str`: Provide an IP-Address to bind to if you want to receive multicast packets from a specific interface.
* `bind_port: int`: Default: 5568. It is not recommended to change this value!
Only use when you are know what you are doing!
Please keep in mind to not use the callbacks for time consuming tasks!
If you do this, then the receiver can not react fast enough on incoming messages!
Functions:
* `join_multicast(<universe>)`: joins the multicast group for the specific universe.
* `leave_multicast(<universe>)`: leave the multicast group specified by the universe.
* `get_possible_universes()`: Returns a tuple with all universes that have sources that are sending out data and this
data is received by this machine
* `register_listener(<trigger>, <callback>, **kwargs)`: register a listener for the given trigger.
You can also use the decorator `listen_on(<trigger>, **kwargs)`. Possible trigger so far:
* `availability`: gets called when there is no data for a universe anymore or there is now data
available. This gets also fired if a source terminates a stream via the stream_termination bit.
The callback should get two arguments: `callback(universe, changed)`
* `universe: int`: is the universe where the action happened
* `changed: str`: can be 'timeout' or 'available'
* `universe`: registers a listener for the given universe. The callback gets only one parameter, the DataPacket.
You can also use the decorator `@listen_on('universe', universe=<universe>)`.
The callback should have one argument: `callback(packet)`
* `packet: DataPacket`: the received DataPacket with all information
* `remove_listener(<callback>)`: removes a previously registered listener regardless of the trigger.
This means a listener can only be removed completely, even if it was listening to multiple universes.
If the function never was registered, nothing happens.
Note: if a function was registered multiple times, this remove function needs to be called only once.
* `remove_listener_from_universe(<universe>)`: removes all listeners from the given universe.
This does only have effect on the 'universe' listening trigger.
If no function was registered for this universe, nothing happens.
### DataPacket
This is an abstract representation of an sACN Data packet that carries the DMX data. This class is used internally by
the module and is used in the callbacks of the receiver.
The DataPacket provides following attributes:
* `sourceName: str`: a string that is used to identify the source. Only the first 64 bytes are used.
* `priority: int`: the priority used to manage multiple DMX data on one receiver. [1-200] Default: 100
* `universe: int`: the universe for the whole message and its DMX data. [1-63999]
* `sequence: int`: the sequence number. Should increment for every new message and can be used to check for wrong
order of arriving packets.
* `option_StreamTerminated: bool`: True if this packet is the last one of the stream for the given universe.
* `option_PreviewData: bool`: True if this data is for visualization purposes.
* `option_ForceSync: bool`: True if this should only function in a synchronized state.
* `dmxStartCode: int`: the start code for the data tuple. [1-255] Default: 0x00 for streaming level data. See
[Alternate START Codes](https://tsp.esta.org/tsp/working_groups/CP/DMXAlternateCodes.php) for more information.
* `dmxData: tuple`: the DMX data as tuple. Max length is 512 and shorter tuples getting normalized to a length of 512.
Filled with 0 for empty spaces.
## Development
Some tools are used to help with development of this library. These are [flake8](https://flake8.pycqa.org), [pytest](https://pytest.org) and [coverage.py](https://coverage.readthedocs.io).
Install those tools with pip:
```
pip install flake8 pytest pytest-timeout coverage
```
`flake8` checks for formatting issues and can be run with `flake8` or `python -m flake8` in the root directory of this repository.
`pytest` is used for unit testing and can be executed with `pytest` or `python -m pytest` in the root directory of this repository.
By default, this skips the integration test, which uses real hardware I/O and might not run in every configuration.
Use the flag `--run-integration-tests` to run the additional tests (e.g. `python -m pytest --run-integration-tests`)
It is useful to check if the test coverage changed with `coverage run -m pytest` and then `coverage html`, which generates a `htmlcov/index.html` file with all the information.
### Changelog
* 1.9.0: The behavior of multicast sending and receiving is now unified across most operating systems. This means Windows no longer requires to set a `bind_address` to be able to use multicast or universe discovery. (Thanks to mthespian! See #42 for more information)
* 1.8.1: Calling `stop` on a sender or receiver now closes the underlying socket too. Note: after stopping a sender or receiver, it can not be started again with `start`. (See #39 for more information)
* 1.8.0: Added function for removing a listener on a receiver by universe. See `sACNreceiver.remove_listener_from_universe(<universe>)` for more information.
* 1.7.1: Small changes that might improve timing on the sender. (Thanks to mthespian! See #36 for more information)
* 1.7.0: Added function for removing a listener on a receiver. See `sACNreceiver.remove_listener(<callback>)` for more information.
* 1.6.4: Functionality related to sending of sACN data is now mostly covered by tests. Removed undocumented parameters for `sACNsender.start()`.
* 1.6.3: Functionality related to receiving sACN data is now mostly covered by tests. Fixed a bug, where an exception was thrown on the first `DataPacket` when the stream-termination option was set. (Additional thanks to mthespian! See #31 for more information)
* 1.6.2: Test coverage of sub-module `messages` is now 100%. Fixed a bug where a too long source name did not throw an exception.
Fixed a bug where invalid DMX data could be set on the `DataPacket`. (Thanks to mthespian! See #30 for more information)
* 1.6.1: Fixed a bug, where the DMX start code was not set on received packets (Thanks to mthespian! See #29 for more information)
* 1.6: Added dmxStartCode property to DataPacket (Thanks to mthespian! see #27 for more information)
* 1.5: Performance improvement: Deleted debugging statements in hot path of packet sending and receiving (Thanks to shauneccles! See #25 for more information)
* 1.4.6: Fix: When creating a DataPacket with invalid DMX start codes (i.e. not `0x00`) an exception is thrown (Thanks to niggiover9000! See #11 for more information)
* 1.4.5: When using a manual flush, only a specified list of universes can be flushed (Thanks to CrazyIvan359! See #22 for more information)
* 1.4.4: The universe used for the sACN-sync messages can now be set when creating a `sACNsender` (Thanks to CrazyIvan359! See #21 for more information)
* 1.4.3: The sequence number of the sync-packet when using manual flush was not increased (Thanks to @BlakeGarner ! See #19 for more information)
* 1.4.2: The internal logging of the receiver_thread and output_thread was using the root logger instead of its module-logger. (Thanks to @mje-nz ! See #18 for more information)
* 1.4: Added a manual flush feature for sending out all universes at the same time. Thanks to ahodges9 for the idea.
[e1.31]: http://tsp.esta.org/tsp/documents/docs/E1-31-2016.pdf
%prep
%autosetup -n sacn-1.9.0
%build
%py3_build
%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .
%files -n python3-sacn -f filelist.lst
%dir %{python3_sitelib}/*
%files help -f doclist.lst
%{_docdir}/*
%changelog
* Tue May 30 2023 Python_Bot <Python_Bot@openeuler.org> - 1.9.0-1
- Package Spec generated
|