-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
61 lines (53 loc) · 1.5 KB
/
main.go
File metadata and controls
61 lines (53 loc) · 1.5 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// 05_remote_control: PLCのリモート操作(停止・ラッチクリア・起動)サンプル。
//
// !! 警告 !!
// このプログラムを実行すると接続先の PLC が停止します。
// 設備・装置が動作中の場合は絶対に実行しないでください。
// 実行前に安全を確認し、"yes" と入力して続行してください。
package main
import (
"bufio"
"fmt"
"os"
"strings"
"time"
mc "github.com/moge800/gomcprotocol"
)
func main() {
fmt.Println("!! 警告 !! このプログラムは PLC を停止させます。")
fmt.Print("続行しますか? (yes/no): ")
scanner := bufio.NewScanner(os.Stdin)
scanner.Scan()
if strings.TrimSpace(scanner.Text()) != "yes" {
fmt.Println("中止しました。")
return
}
c, err := mc.New3EClient("192.168.0.1", 5007, mc.ModeBinary)
if err != nil {
panic(err)
}
if err := c.Connect(); err != nil {
panic(err)
}
defer c.Close()
// PLC を停止
fmt.Println("PLC を停止中...")
if err := c.RemoteStop(); err != nil {
panic(err)
}
fmt.Println("停止完了")
time.Sleep(500 * time.Millisecond)
// ラッチクリア(停止中のみ可能)
fmt.Println("ラッチクリア中...")
if err := c.RemoteLatchClear(); err != nil {
panic(err)
}
fmt.Println("ラッチクリア完了")
time.Sleep(500 * time.Millisecond)
// PLC を起動(clearMode=0: クリアなし)
fmt.Println("PLC を起動中...")
if err := c.RemoteRun(0, false); err != nil {
panic(err)
}
fmt.Println("起動完了")
}