-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
76 lines (55 loc) · 1.66 KB
/
main.go
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"./TransportData"
"./ParseData"
"./InputData"
"./Log"
"strconv"
"time"
)
var scalePort, rulerPort *TransportData.Port
func main() {
Controller()
}
func Controller() {
for {
if scalePort == nil || rulerPort == nil {
scalePort, rulerPort = TransportData.SelectPort()
} else {
scaleResponse := TransportData.SendScaleCommand(scalePort)
if scaleResponse == nil {
println("Весы отвалились")
scalePort = nil
}
rulerResponse := TransportData.SendRulerCommand(rulerPort)
if rulerResponse == nil {
println("Линейка отвалилась")
rulerPort = nil
}
if scalePort != nil && rulerPort != nil {
weightBox := ParseData.ParseScaleData(scaleResponse)
widthBox, heightBox, lengthBox, onlyWeight := ParseData.ParseRulerData(rulerResponse)
correctWeight := int(weightBox)
checkScaleData, led := ParseData.CheckData(correctWeight, widthBox, heightBox, lengthBox, onlyWeight)
if led {
rulerPort.Connection.Write([]byte{0x66}) // байт готовности, включает диод
} else {
rulerPort.Connection.Write([]byte{0x55}) // байт готовности, выключает диод
}
if checkScaleData {
if onlyWeight {
InputData.ToClipBoard(strconv.Itoa(correctWeight))
} else {
InputData.ToClipBoard(":" + strconv.Itoa(correctWeight) +
":" + strconv.Itoa(widthBox) +
":" + strconv.Itoa(heightBox) +
":" + strconv.Itoa(lengthBox))
}
InputData.ToClipBoard("_ESC_Save")
Log.Write(correctWeight, widthBox, heightBox, lengthBox)
time.Sleep(time.Second * 3)
}
}
}
}
}