Created
March 6, 2024 20:47
-
-
Save Oldes/f3c78cc3438e448223dc40eac03d00c4 to your computer and use it in GitHub Desktop.
Cross-platform DMX port usage example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rebol [ | |
Purpose: "Cross-platform DMX port usage example" | |
Needs: 3.11.0 ;= https://github.com/Oldes/Rebol3/releases/tag/3.11.0 | |
] | |
;------------- DMX ------------------------ | |
dmx-ctx: context [ | |
ser: none | |
bin: make binary! 513 insert/dup bin 0 513 | |
;- Channel 10A | |
DIMM: 2 ;; 0 = no light, 255 = max light | |
RED: 3 | |
GREEN: 4 | |
BLUE: 5 | |
WHITE: 6 | |
AMBER: 7 | |
UV: 8 | |
STROBE: 9 | |
MACRO: 10 | |
SPEED: 11 | |
;- Light 2 | |
;; RED: 44 | |
;; GREEN: 45 | |
;; BLUE: 46 | |
;; WHITE: 47 | |
;; AMBER: 48 | |
;; UV: 49 | |
bin/:DIMM: 255 | |
bin/:UV: 255 | |
;bin/:MACRO: 225 | |
;bin/:SPEED: 255 | |
either system/platform = 'Windows [ | |
;; Windows... | |
ser: make port! [scheme: 'serial path: %COM7 speed: 250000 stop-bits: 2] | |
send-data: func[p][ | |
;; initiate and then clear a break condition | |
modify p 'BRK true | |
modify p 'BRK false | |
write p bin | |
] | |
ser/awake: func [event /local p][ | |
false | |
] | |
try/with [ | |
open ser | |
;modify ser 'RTS false | |
][ | |
;; Linux... | |
try/with [ | |
ser: open %/dev/dmx0 | |
send-data: func[p][write p bin] | |
] | |
set 'dmx-port ser | |
set 'update-dmx func[][ if all [dmx-port open? dmx-port] [send-data dmx-port] ] | |
] | |
;; then in regular interval modify the `dmx-ctx/bin` series and call `update-dmx` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Above code is just a fragment.. in real scenario I used Rebol webserver as a core.. GUI was made as a webpage which communicated with the server over WebSocket. The server was also responsible to play sounds and control electric plugs over GPIO.
It was possible to record all commands and re-play them later... the main loop was like: