Skip to content

Commit

Permalink
fix: fix tcp connection nil pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
wwhai committed Aug 7, 2023
1 parent 5bb8458 commit 94bc163
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions device/custom_protocol_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func (mdev *CustomProtocolDevice) Start(cctx typex.CCTX) error {
mdev.Ctx = cctx.Ctx
mdev.CancelCTX = cctx.CancelCTX
mdev.errorCount = 0
mdev.status = typex.DEV_DOWN

// 现阶段暂时只支持RS485串口, 以后有需求再支持TCP、UDP
if mdev.mainConfig.CommonConfig.Transport == "rawserial" {
Expand Down Expand Up @@ -165,10 +166,14 @@ func (mdev *CustomProtocolDevice) Stop() {
mdev.CancelCTX()
mdev.status = typex.DEV_DOWN
if mdev.mainConfig.CommonConfig.Transport == rawtcp {
mdev.tcpcon.Close()
if mdev.tcpcon != nil {
mdev.tcpcon.Close()
}
}
if mdev.mainConfig.CommonConfig.Transport == rawserial {
mdev.serialPort.Close()
if mdev.serialPort != nil {
mdev.serialPort.Close()
}
}
}

Expand Down

0 comments on commit 94bc163

Please sign in to comment.