fix: cache relay-board drivers so Denkovi/USB-serial boards stay connected
The station-control code rebuilt a fresh driver on every status poll and every relay set. Stateful boards (Denkovi FTDI D2XX, USB-serial) hold an OS handle only one opener can own, so the first poll opened the board and leaked the handle, and every poll after failed with 'device in use' — the relays greyed out a second after Save and auto-control never switched. Drivers are now cached per device and reused, closed on config change. Adds a Test-connection button + detect feedback in the device editor (reported by VK4MA).
This commit is contained in:
@@ -37,6 +37,19 @@ func NewSerialRelay(port string, count int) Device {
|
||||
|
||||
func (s *serialRelay) Count() int { return s.count }
|
||||
|
||||
// Close releases the COM port so it can be reopened later (only one handle may
|
||||
// hold a serial port at a time).
|
||||
func (s *serialRelay) Close() error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if s.port != nil {
|
||||
err := s.port.Close()
|
||||
s.port = nil
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *serialRelay) ensureOpen() error {
|
||||
if s.port != nil {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user