Skip to content

In socat pts port, got 'Serial port busy' error when program restart after killed #199

@dabeibao

Description

@dabeibao

Describe the problem

Failed to reopen the port with error 'Serial port busy'

To reproduce

Reproduce steps:

  1. Create pts paris with socat
socat -d -d PTY,link=/tmp/ttyV0,raw,echo=0 PTY,link=/tmp/ttyV1,raw,echo=0
  1. Start the program to open the port, then kill it

  2. Restart the program, got this error:

WRN Open failed error="Serial port busy" Port=/tmp/ttyV0

The code to open the port:

type SerOption struct {
	PortName string
	BaudRate uint
}

type SerFile struct {
	file serial.Port
}

func OpenSerFile(option *SerOption) (*SerFile, error) {
	mode := serial.Mode{
		BaudRate: int(option.BaudRate),
		DataBits: 8,
		Parity:   serial.NoParity,
		StopBits: serial.OneStopBit,
	}

	file, err := serial.Open(option.PortName, &mode)
	if err != nil {
		return nil, err
	}
	file.SetDTR(false)
	file.SetRTS(false)
	return &SerFile{file}, nil
}

Please double-check that you have reported each of the following

before submitting the issue.

  • I've provided the FULL source code that causes the problem
  • I've provided all the actions required to reproduce the problem

Expected behavior

Open the port successfully after restart

Operating system and version

Linux

Please describe your hardware setup

socat pts pair

Additional context

No response

Issue checklist

  • I searched for previous requests in the issue tracker
  • My request contains all necessary details

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions