File: example_test.go

package info (click to toggle)
golang-github-pkg-term 0.0~git20181116.27bbf2e-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 200 kB
  • sloc: makefile: 2
file content (36 lines) | stat: -rw-r--r-- 683 bytes parent folder | download
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
package term

import (
	"log"
	"time"
)

// Open a terminal in raw mode at 19200 baud.
func ExampleOpen() {
	Open("/dev/ttyUSB0", Speed(19200), RawMode)
}

// Reset an Arduino by toggling the DTR signal.
func ExampleTerm_SetDTR() {
	t, _ := Open("/dev/USB0")
	t.SetDTR(false) // toggle DTR low
	time.Sleep(250 * time.Millisecond)
	t.SetDTR(true) // raise DTR, resets Ardunio
}

// Send Break to the remote DTE.
func ExampleTerm_SendBreak() {
	t, _ := Open("/dev/ttyUSB0")
	for {
		time.Sleep(3 * time.Second)
		log.Println("Break...")
		t.SendBreak()
	}
}

// Restore the terminal state
func ExampleTerm_Restore() {
	t, _ := Open("/dev/tty")
	// mutate terminal state
	t.Restore()
}