GithubHelp home page GithubHelp logo

doytsujin / go-sacn Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hundemeier/go-sacn

0.0 1.0 0.0 58 KB

Implementation of the sACN aka ANSI E1.31 protocol for streaming DMX-data in go

License: MIT License

Go 100.00%

go-sacn's Introduction

go-sacn

This is a sACN implementation for golang. It is based on the E1.31 protocol by the ESTA. A copy can be found here.

This is by no means a full implementation yet, but may be in the future. If you want to see a full DMX package, see the OLA project.

There is also some documentation on godoc.org. This Project suports Go Modules introduced in Go 1.11.

go get github.com/Hundemeier/go-sacn/sacn

Receiving

The simplest way to receive sACN packets is to use sacn.NewReceiverSocket.

For up-to-date information, visit the godoc.org website with this repo.

Stoping

You can stop the receiving of packets on a Receiver via receiver.Stop(). Please note that it can take up to 2,5s to stop the receiving and close all channels. If you have stoped a receiver once, you can restart via receiver.Start().

Transmitting

To transmitt DMX data, you have to initalize a Transmitter object. This handles all the protocol specific actions (currently not all). You can activate universes, if you wish to send out data. Then you can use a channel for 512-byte arrays to transmitt them over the network.

There are two different types of addressing the receiver: unicast and multicast. When using multicast, note that you have to provide a bind address on some operating systems (eg Windows). You can use both at the same time and any number of unicast addresses. To set wether multicast should be used, call transmitter.SetMulticast(<universe>, <bool>). You can set multiple unicast destinations as slice via transmitter.SetDestinations(<universe>, <[]string>). Note that any existing destinations will be overwritten. If you want to append a destination, you can use transmitter.Destination(<universe>) which returns a deep copy of the used net.UDPAddr objects.

Examples

GoDoc Examples:

Transmitter Example:

package main

import (
	"log"
	"math/rand"
	"time"

	"github.com/Hundemeier/go-sacn/sacn"
)

func main() {
	//instead of "" you could provide an ip-address that the socket should bind to
	trans, err := sacn.NewTransmitter("", [16]byte{1, 2, 3}, "test")
	if err != nil {
		log.Fatal(err)
	}
	
	//activates the first universe
	ch, err := trans.Activate(1)
	if err != nil {
		log.Fatal(err)
	}
	//deactivate the channel on exit
	defer close(ch)
	
	//set a unicast destination, and/or use multicast
	trans.SetMulticast(1, true)//this specific setup will not multicast on windows, 
	//because no bind address was provided
	
	//set some example ip-addresses
	trans.SetDestinations(1, []string{"192.168.1.13", "192.168.1.1"})
	
	//send some random data for 10 seconds
	for i := 0; i < 20; i++ {
		ch <- [512]byte{byte(rand.Int()), byte(i & 0xFF)}
		time.Sleep(500 * time.Millisecond)
	}
}

go-sacn's People

Contributors

hundemeier avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.