Example #1
0
func sigHandler() *chanpubsub.ChanPubSub {
	termChan := make(chan os.Signal, 1)
	signal.Notify(termChan, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)

	ps := chanpubsub.New()

	go func() {
		ps.Pub(<-termChan)
		return
	}()

	return ps
}
Example #2
0
func (s *SerialPort) Open() (err error) {
	if s.opened {
		return nil
	}

	s.port, err = serial.OpenPort(&s.Config)
	if err != nil {
		return err
	}

	if s.ChanPubSub == nil {
		s.ChanPubSub = chanpubsub.New()
	}

	go s.reader()

	if s.Write == nil {
		s.Write = s.writer()
	}

	s.opened = true
	return nil
}