Skip to content

Commit 9d95695

Browse files
committed
Added RTS/DTR configuration values
1 parent e9210fa commit 9d95695

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ 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
88
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e
99
)
1010

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+l
1111
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
1212
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1313
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
14-
go.bug.st/serial v1.3.5 h1:k50SqGZCnHZ2MiBQgzccXWG+kd/XpOs1jUljpDDKzaE=
15-
go.bug.st/serial v1.3.5/go.mod h1:z8CesKorE90Qr/oRSJiEuvzYRKol9r/anJZEb5kt304=
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=
1616
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA=
1717
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA=
1818
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k=

main.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ func NewSerialMonitor() *SerialMonitor {
8282
Values: []string{"1", "1.5", "2"},
8383
Selected: "1",
8484
},
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+
},
8597
},
8698
},
8799
openedPort: false,
@@ -114,7 +126,17 @@ func (d *SerialMonitor) Configure(parameterName string, value string) error {
114126
// Apply configuration to port
115127
var configErr error
116128
if d.openedPort {
117-
configErr = d.serialPort.SetMode(d.getMode())
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)
139+
}
118140
}
119141

120142
// If configuration failed, rollback settings
@@ -133,7 +155,6 @@ func (d *SerialMonitor) Open(boardPort string) (io.ReadWriter, error) {
133155
serialPort, err := serial.Open(boardPort, d.getMode())
134156
if err != nil {
135157
return nil, err
136-
137158
}
138159
d.openedPort = true
139160
d.serialPort = serialPort
@@ -184,6 +205,18 @@ func (d *SerialMonitor) getMode() *serial.Mode {
184205
Parity: parity,
185206
DataBits: dataBits,
186207
StopBits: stopBits,
208+
InitialStatusBits: &serial.ModemOutputBits{
209+
DTR: d.getDTR(),
210+
RTS: d.getRTS(),
211+
},
187212
}
188213
return mode
189214
}
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)