コード例 #1
0
ファイル: controller.go プロジェクト: adunahay/magspoof
func main() {
	if len(os.Args) != 4 {
		fmt.Fprintf(os.Stderr, "%v <device> <baud> <data>\n", os.Args[0])
		os.Exit(1)
	}

	baud, err := strconv.Atoi(os.Args[2])
	if err != nil {
		fmt.Fprintf(os.Stderr, "baud must be numerical\n")
		os.Exit(1)
	}

	c := &goserial.Config{Name: os.Args[1], Baud: baud}
	s, err := goserial.OpenPort(c)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error connecting to device: %v\n", err)
		os.Exit(2)
	}

	err = sendBytes(s, []byte(os.Args[3]))
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error writing data: %v\n", err)
		os.Exit(3)
	}
}
コード例 #2
0
ファイル: gemlogger.go プロジェクト: bfritz/gemlogger
func openSerialPortOrExit() io.ReadWriteCloser {
	c := &goserial.Config{Name: serialPort, Baud: serialBaud}
	ser, err := goserial.OpenPort(c)
	if err != nil {
		log.Printf("Could not connect to serial port %s.", serialPort)
		log.Fatal(err)
	}
	return ser
}
コード例 #3
0
ファイル: example.go プロジェクト: huin/godatascrape
func main() {
	flag.Parse()

	sink, err := carbon.DialClient(net.TCPAddr{net.IPv4(127, 0, 0, 1), 2003})
	if err != nil {
		log.Fatal(err)
	}

	routerAddr := net.UDPAddr{net.IPv4(192, 168, 1, 1), 161}
	routerScrapers := scraper.ScrapingPoller{
		Ticks: time.Tick(10 * time.Second),
		Scrapers: []scraper.PolledScraper{
			&snmp.Counter32Scraper{
				Sender: sink.NewUint32Sender("network.router.wan.inBytes"),
				Addr:   routerAddr,
				OID:    []int{1, 3, 6, 1, 2, 1, 2, 2, 1, 10, 2},
			},
			&snmp.Counter32Scraper{
				Sender: sink.NewUint32Sender("network.router.wan.outBytes"),
				Addr:   routerAddr,
				OID:    []int{1, 3, 6, 1, 2, 1, 2, 2, 1, 16, 2},
			},
		},
	}

	allScrapers := []scraper.PassiveScraper{
		&routerScrapers,
	}

	// TODO: Use a serial port instead. For now this just reads and parses data
	// from the given file for testing.
	if *currentCostFile != "" {
		serialConfig := &goserial.Config{
			Name:     *currentCostFile,
			Baud:     57600,
			Parity:   goserial.ParityNone,
			Size:     goserial.ByteSize8,
			StopBits: goserial.StopBits1,
		}
		if serial, err := goserial.OpenPort(serialConfig); err != nil {
			log.Print(err)
		} else {
			defer serial.Close()
			allScrapers = append(allScrapers, cc.NewScraper(cc.Config{
				Serial: serial,
			}))
		}
	}

	for _, s := range allScrapers {
		fmt.Printf("scraper: %s\n", s)
	}

	scraper.RunPassiveScrapers(allScrapers)

	select {}
}
コード例 #4
0
// Open a device and set various control parameters, such as baud rate.
func open(tty string) io.ReadWriteCloser {
	c := &serial.Config{Name: tty, Baud: 115200}
	// out, err = os.OpenFile(tty, os.O_RDWR, 0x666) // ,
	out, err := serial.OpenPort(c)
	if err != nil {
		log.Fatalf("Unable to open %s: %v", tty, err)
	}
	return out
}
コード例 #5
0
ファイル: main.go プロジェクト: RobotClubKut/MatrixLEDTOOLS
func sendLCDStr(serialConfigure *goserial.Config, str *lcdString, fin chan bool) {
	for {
		str = lcdStringBuffer
		shiftCoord := len(str.c) * 16
		for i := 0; i < shiftCoord+96+1; i++ {
			serialPort, _ := goserial.OpenPort(serialConfigure)
			packet := createPacket(*str, i-96)
			writeLCDMatrix(packet, serialPort)
			//time.Sleep(1 * time.Millisecond)
			serialPort.Close()
		}
	}
	fin <- true
}
コード例 #6
0
ファイル: axon.go プロジェクト: chappyhome/gasworks-neurone
// Axon listens to the dentrites on the deltaE channel, and embodies an artificial neurone. When the energy
// of the neurone reaches a maximum, it fires into the axon (the web dendites of adjacent neurones).
func axon(deltaE chan float32, config Configuration) {
	// Find the device that represents the arduino serial connection.
	c := &goserial.Config{Name: findArduino(), Baud: 9600}
	s, _ := goserial.OpenPort(c)

	// When connecting to an older revision arduino, you need to wait a little while it resets.
	time.Sleep(1 * time.Second)

	neurone := Neurone{-2.0, deltaE, waitLength, time.Now().UnixNano(), config}
	state := wait

	for {
		state, neurone = state(neurone, s)

		fmt.Printf("INFO: e[%f]\n", neurone.energy)
	}
}
コード例 #7
0
ファイル: gocc.go プロジェクト: huin/gocc
// NewSerialMessageReader opens the named serial port, configures it for
// reading Current Cost data, and returns a MessageReader for doing so.
func NewSerialMessageReader(serialPath string) (*MessageReader, error) {
	serialConfig := &goserial.Config{
		Name:     serialPath,
		Baud:     57600,
		Parity:   goserial.ParityNone,
		Size:     goserial.Byte8,
		StopBits: goserial.StopBits1,
	}

	var serial io.ReadCloser
	var err error
	if serial, err = goserial.OpenPort(serialConfig); err != nil {
		return nil, err
	}

	return NewMessageReader(serial), nil
}
コード例 #8
0
ファイル: main.go プロジェクト: hagna/typefaster
func NewMcs() *Mcs {
	m := new(Mcs)
	m.Tree = typefaster.NewDiskTree(*treename)
	m.Cnode = m.Tree.Root()
	c := new(goserial.Config)
	c.Name = "/dev/ttyAMA0"
	c.Baud = 9600
	s, err := goserial.OpenPort(c)
	if err != nil {
		log.Fatal(err)
	}

	n, err := s.Write([]byte{97})
	if err != nil {
		log.Fatal(err)
	} else {
		fmt.Println("serial write got back", n)
	}
	m.serial = s

	return m
}
コード例 #9
0
ファイル: uart.go プロジェクト: ungerik/go-bbio
func NewUART(nr UARTNr, baud int, size UARTByteSize, parity UARTParityMode, stopBits UARTStopBits) (*UART, error) {
	dt := fmt.Sprintf("ADAFRUIT-UART%d", nr)
	err := LoadDeviceTree(dt)
	if err != nil {
		return nil, err
	}

	uart := &UART{nr: nr}

	config := &goserial.Config{
		Name:     fmt.Sprintf("/dev/ttyO%d", nr),
		Baud:     baud,
		Size:     goserial.ByteSize(size),
		Parity:   goserial.ParityMode(parity),
		StopBits: goserial.StopBits(stopBits),
	}
	uart.serial, err = goserial.OpenPort(config)
	if err != nil {
		return nil, err
	}

	return uart, nil
}
コード例 #10
0
ファイル: serialbee.go プロジェクト: Horrendus/beehive
func (mod *SerialBee) Run(eventChan chan bees.Event) {
	if mod.baudrate == 0 || mod.device == "" {
		return
	}

	var err error
	c := &goserial.Config{Name: mod.device, Baud: mod.baudrate}
	mod.conn, err = goserial.OpenPort(c)
	if err != nil {
		log.Fatal(err)
	}
	time.Sleep(1 * time.Second)

	for {
		//FIXME: don't block
		select {
		case <-mod.SigChan:
			return

		default:
		}

		text := ""
		c := []byte{0}
		for {
			_, err := mod.conn.Read(c)
			if err != nil {
				time.Sleep(1 * time.Second)
				continue
			}
			if c[0] == 10 || c[0] == 13 {
				break
			}

			text += string(c[0])
		}

		if len(text) > 0 {
			text = strings.TrimSpace(text)

			ev := bees.Event{
				Bee:  mod.Name(),
				Name: "message",
				Options: []bees.Placeholder{
					bees.Placeholder{
						Name:  "port",
						Type:  "string",
						Value: mod.device,
					},
					bees.Placeholder{
						Name:  "text",
						Type:  "string",
						Value: text,
					},
				},
			}
			eventChan <- ev
		}
		time.Sleep(1 * time.Second)
	}
}