Skip to content

Commit bbe81f9

Browse files
authored
Merge pull request #21 from arduino/rts_cts_on
Added "rts" and "dtr" configuration parameters.
2 parents 0ee846b + 5e36edb commit bbe81f9

File tree

11 files changed

+196
-37
lines changed

11 files changed

+196
-37
lines changed

.github/workflows/check-go-dependencies-task.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Check Go Dependencies
33

44
env:
55
# See: https://github.com/actions/setup-go/tree/main#supported-version-syntax
6-
GO_VERSION: "1.17"
6+
GO_VERSION: "1.18.5"
77

88
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
99
on:

.github/workflows/check-go-task.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Check Go
33

44
env:
55
# See: https://github.com/actions/setup-go/tree/main#supported-version-syntax
6-
GO_VERSION: "1.17"
6+
GO_VERSION: "1.18.5"
77

88
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
99
on:

.licenses/serial-monitor/go/go.bug.st/serial.dep.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: go.bug.st/serial
3-
version: v1.3.5
3+
version: v1.4.0
44
type: go
55
summary: Package serial is a cross-platform serial library for the go language.
66
homepage: https://pkg.go.dev/go.bug.st/serial

.licenses/serial-monitor/go/go.bug.st/serial/unixutils.dep.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
22
name: go.bug.st/serial/unixutils
3-
version: v1.3.5
3+
version: v1.4.0
44
type: go
55
summary:
66
homepage: https://pkg.go.dev/go.bug.st/serial/unixutils
77
license: bsd-3-clause
88
licenses:
9-
- sources: serial@v1.3.5/LICENSE
9+
- sources: serial@v1.4.0/LICENSE
1010
text: |2+
1111
1212
Copyright (c) 2014-2021, Cristian Maglie.
@@ -41,7 +41,7 @@ licenses:
4141
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4242
POSSIBILITY OF SUCH DAMAGE.
4343
44-
- sources: serial@v1.3.5/README.md
44+
- sources: serial@v1.4.0/README.md
4545
text: |-
4646
The software is release under a [BSD 3-clause license]
4747
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
name: golang.org/x/exp/constraints
3+
version: v0.0.0-20220722155223-a9213eeb770e
4+
type: go
5+
summary: Package constraints defines a set of useful constraints to be used with type
6+
parameters.
7+
homepage: https://pkg.go.dev/golang.org/x/exp/constraints
8+
license: bsd-3-clause
9+
licenses:
10+
- sources: [email protected]/LICENSE
11+
text: |
12+
Copyright (c) 2009 The Go Authors. All rights reserved.
13+
14+
Redistribution and use in source and binary forms, with or without
15+
modification, are permitted provided that the following conditions are
16+
met:
17+
18+
* Redistributions of source code must retain the above copyright
19+
notice, this list of conditions and the following disclaimer.
20+
* Redistributions in binary form must reproduce the above
21+
copyright notice, this list of conditions and the following disclaimer
22+
in the documentation and/or other materials provided with the
23+
distribution.
24+
* Neither the name of Google Inc. nor the names of its
25+
contributors may be used to endorse or promote products derived from
26+
this software without specific prior written permission.
27+
28+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39+
- sources: [email protected]/PATENTS
40+
text: |
41+
Additional IP Rights Grant (Patents)
42+
43+
"This implementation" means the copyrightable works distributed by
44+
Google as part of the Go project.
45+
46+
Google hereby grants to You a perpetual, worldwide, non-exclusive,
47+
no-charge, royalty-free, irrevocable (except as stated in this section)
48+
patent license to make, have made, use, offer to sell, sell, import,
49+
transfer and otherwise run, modify and propagate the contents of this
50+
implementation of Go, where such license applies only to those patent
51+
claims, both currently owned or controlled by Google and acquired in
52+
the future, licensable by Google that are necessarily infringed by this
53+
implementation of Go. This grant does not include claims that would be
54+
infringed only as a consequence of further modification of this
55+
implementation. If you or your agent or exclusive licensee institute or
56+
order or agree to the institution of patent litigation against any
57+
entity (including a cross-claim or counterclaim in a lawsuit) alleging
58+
that this implementation of Go or any code incorporated within this
59+
implementation of Go constitutes direct or contributory patent
60+
infringement, or inducement of patent infringement, then any patent
61+
rights granted to you under this License for this implementation of Go
62+
shall terminate as of the date such litigation is filed.
63+
notices: []
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
name: golang.org/x/exp/slices
3+
version: v0.0.0-20220722155223-a9213eeb770e
4+
type: go
5+
summary: Package slices defines various functions useful with slices of any type.
6+
homepage: https://pkg.go.dev/golang.org/x/exp/slices
7+
license: bsd-3-clause
8+
licenses:
9+
- sources: [email protected]/LICENSE
10+
text: |
11+
Copyright (c) 2009 The Go Authors. All rights reserved.
12+
13+
Redistribution and use in source and binary forms, with or without
14+
modification, are permitted provided that the following conditions are
15+
met:
16+
17+
* Redistributions of source code must retain the above copyright
18+
notice, this list of conditions and the following disclaimer.
19+
* Redistributions in binary form must reproduce the above
20+
copyright notice, this list of conditions and the following disclaimer
21+
in the documentation and/or other materials provided with the
22+
distribution.
23+
* Neither the name of Google Inc. nor the names of its
24+
contributors may be used to endorse or promote products derived from
25+
this software without specific prior written permission.
26+
27+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38+
- sources: [email protected]/PATENTS
39+
text: |
40+
Additional IP Rights Grant (Patents)
41+
42+
"This implementation" means the copyrightable works distributed by
43+
Google as part of the Go project.
44+
45+
Google hereby grants to You a perpetual, worldwide, non-exclusive,
46+
no-charge, royalty-free, irrevocable (except as stated in this section)
47+
patent license to make, have made, use, offer to sell, sell, import,
48+
transfer and otherwise run, modify and propagate the contents of this
49+
implementation of Go, where such license applies only to those patent
50+
claims, both currently owned or controlled by Google and acquired in
51+
the future, licensable by Google that are necessarily infringed by this
52+
implementation of Go. This grant does not include claims that would be
53+
infringed only as a consequence of further modification of this
54+
implementation. If you or your agent or exclusive licensee institute or
55+
order or agree to the institution of patent litigation against any
56+
entity (including a cross-claim or counterclaim in a lawsuit) alleging
57+
that this implementation of Go or any code incorporated within this
58+
implementation of Go constitutes direct or contributory patent
59+
infringement, or inducement of patent infringement, then any patent
60+
rights granted to you under this License for this implementation of Go
61+
shall terminate as of the date such litigation is filed.
62+
notices: []

DistTasks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ version: "3"
1919

2020
vars:
2121
CONTAINER: "docker.elastic.co/beats-dev/golang-crossbuild"
22-
GO_VERSION: "1.17.5"
22+
GO_VERSION: "1.18.5"
2323
CHECKSUM_FILE: "{{.VERSION}}-checksums.txt"
2424

2525
tasks:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The `serial-monitor` tool is a command line program that interacts via stdio. It
44

55
## How to build
66

7-
Install a recent go environment (>=13.0) and run `go build`. The executable `serial-monitor` will be produced in your working directory.
7+
Install a recent go environment and run `go build`. The executable `serial-monitor` will be produced in your working directory.
88

99
## Usage
1010

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
module github.com/arduino/serial-monitor
22

3-
go 1.17
3+
go 1.18
44

55
require (
66
github.com/arduino/pluggable-monitor-protocol-handler v0.9.2
7-
go.bug.st/serial v1.3.5
7+
go.bug.st/serial v1.4.0
8+
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e
89
)
910

1011
require (

go.sum

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ github.com/arduino/pluggable-monitor-protocol-handler v0.9.2 h1:vb5AmE3bT9we5Ej4
22
github.com/arduino/pluggable-monitor-protocol-handler v0.9.2/go.mod h1:vMG8tgHyE+hli26oT0JB/M7NxUMzzWoU5wd6cgJQRK4=
33
github.com/creack/goselect v0.1.2 h1:2DNy14+JPjRBgPzAd1thbQp4BSIihxcBf0IXhQXDRa0=
44
github.com/creack/goselect v0.1.2/go.mod h1:a/NhLweNvqIYMuxcMOuWY516Cimucms3DglDzQP3hKY=
5-
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
65
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
76
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
87
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
@@ -11,15 +10,11 @@ github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brv
1110
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
1211
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
1312
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
14-
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
15-
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
1613
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
17-
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
18-
go.bug.st/serial v1.3.5 h1:k50SqGZCnHZ2MiBQgzccXWG+kd/XpOs1jUljpDDKzaE=
19-
go.bug.st/serial v1.3.5/go.mod h1:z8CesKorE90Qr/oRSJiEuvzYRKol9r/anJZEb5kt304=
20-
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
14+
go.bug.st/serial v1.4.0 h1:IXHzPVbUBbql66lQZ1iV9LWzGXT5lh6S9gZxHK/KyQE=
15+
go.bug.st/serial v1.4.0/go.mod h1:z8CesKorE90Qr/oRSJiEuvzYRKol9r/anJZEb5kt304=
16+
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA=
17+
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA=
2118
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k=
2219
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
23-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2420
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
25-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

main.go

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/arduino/serial-monitor/args"
2929
"github.com/arduino/serial-monitor/version"
3030
"go.bug.st/serial"
31+
"golang.org/x/exp/slices"
3132
)
3233

3334
func main() {
@@ -66,8 +67,8 @@ func NewSerialMonitor() *SerialMonitor {
6667
"parity": {
6768
Label: "Parity",
6869
Type: "enum",
69-
Values: []string{"None", "Even", "Odd", "Mark", "Space"},
70-
Selected: "None",
70+
Values: []string{"none", "even", "odd", "mark", "space"},
71+
Selected: "none",
7172
},
7273
"bits": {
7374
Label: "Data bits",
@@ -81,6 +82,18 @@ func NewSerialMonitor() *SerialMonitor {
8182
Values: []string{"1", "1.5", "2"},
8283
Selected: "1",
8384
},
85+
"rts": {
86+
Label: "RTS",
87+
Type: "enum",
88+
Values: []string{"on", "off"},
89+
Selected: "on",
90+
},
91+
"dtr": {
92+
Label: "DTR",
93+
Type: "enum",
94+
Values: []string{"on", "off"},
95+
Selected: "on",
96+
},
8497
},
8598
},
8699
openedPort: false,
@@ -99,25 +112,39 @@ func (d *SerialMonitor) Describe() (*monitor.PortDescriptor, error) {
99112

100113
// Configure is the handler for the pluggable-monitor CONFIGURE command
101114
func (d *SerialMonitor) Configure(parameterName string, value string) error {
102-
if d.serialSettings.ConfigurationParameter[parameterName] == nil {
115+
parameter, ok := d.serialSettings.ConfigurationParameter[parameterName]
116+
if !ok {
103117
return fmt.Errorf("could not find parameter named %s", parameterName)
104118
}
105-
values := d.serialSettings.ConfigurationParameter[parameterName].Values
106-
for _, i := range values {
107-
if i == value {
108-
oldValue := d.serialSettings.ConfigurationParameter[parameterName].Selected
109-
d.serialSettings.ConfigurationParameter[parameterName].Selected = value
110-
if d.openedPort {
111-
err := d.serialPort.SetMode(d.getMode())
112-
if err != nil {
113-
d.serialSettings.ConfigurationParameter[parameterName].Selected = oldValue
114-
return errors.New(err.Error())
115-
}
116-
}
117-
return nil
119+
if !slices.Contains(parameter.Values, value) {
120+
return fmt.Errorf("invalid value for parameter %s: %s", parameterName, value)
121+
}
122+
// Set configuration
123+
oldValue := parameter.Selected
124+
parameter.Selected = value
125+
126+
// Apply configuration to port
127+
var configErr error
128+
if d.openedPort {
129+
switch parameterName {
130+
case "baudrate", "parity", "bits", "stop_bits":
131+
configErr = d.serialPort.SetMode(d.getMode())
132+
case "dtr":
133+
configErr = d.serialPort.SetDTR(d.getDTR())
134+
case "rts":
135+
configErr = d.serialPort.SetRTS(d.getRTS())
136+
default:
137+
// Should never happen
138+
panic("Invalid parameter: " + parameterName)
118139
}
119140
}
120-
return fmt.Errorf("invalid value for parameter %s: %s", parameterName, value)
141+
142+
// If configuration failed, rollback settings
143+
if configErr != nil {
144+
parameter.Selected = oldValue
145+
return configErr
146+
}
147+
return nil
121148
}
122149

123150
// Open is the handler for the pluggable-monitor OPEN command
@@ -128,7 +155,6 @@ func (d *SerialMonitor) Open(boardPort string) (io.ReadWriter, error) {
128155
serialPort, err := serial.Open(boardPort, d.getMode())
129156
if err != nil {
130157
return nil, err
131-
132158
}
133159
d.openedPort = true
134160
d.serialPort = serialPort
@@ -179,6 +205,18 @@ func (d *SerialMonitor) getMode() *serial.Mode {
179205
Parity: parity,
180206
DataBits: dataBits,
181207
StopBits: stopBits,
208+
InitialStatusBits: &serial.ModemOutputBits{
209+
DTR: d.getDTR(),
210+
RTS: d.getRTS(),
211+
},
182212
}
183213
return mode
184214
}
215+
216+
func (d *SerialMonitor) getDTR() bool {
217+
return d.serialSettings.ConfigurationParameter["dtr"].Selected == "on"
218+
}
219+
220+
func (d *SerialMonitor) getRTS() bool {
221+
return d.serialSettings.ConfigurationParameter["rts"].Selected == "on"
222+
}

0 commit comments

Comments
 (0)