diff --git a/hardware/FTDIFinder.go b/hardware/FTDIFinder.go index e7a489c..3a640a8 100644 --- a/hardware/FTDIFinder.go +++ b/hardware/FTDIFinder.go @@ -232,10 +232,10 @@ func (f *FTDIFinder) scanPeripherals(ctx context.Context) error { scanner := bufio.NewScanner(stdout) for scanner.Scan() { peripheralString := scanner.Text() - // The program output is like '0:1:2' where 0 is the location, 1 is the S/N and 2 is the name + // The program output is like '0:1:2:3' where 0 is the location, 1 is the S/N, 2 is the name and 3 is the open flag [O/C] peripheralInfo := strings.Split(peripheralString, ":") - log.Trace().Str("file", "FTDIFinder").Str("scannedString", peripheralString).Str("peripheralName", peripheralInfo[2]).Str("peripheralSN", peripheralInfo[1]).Msg("new FTDI peripheral detected") + log.Trace().Str("file", "FTDIFinder").Str("scannedString", peripheralString).Str("peripheralOpenFlag", peripheralInfo[3]).Str("peripheralName", peripheralInfo[2]).Str("peripheralSN", peripheralInfo[1]).Msg("new FTDI peripheral detected") // Convert the location to an integer location, err := strconv.Atoi(peripheralInfo[0]) if err != nil { @@ -246,6 +246,7 @@ func (f *FTDIFinder) scanPeripherals(ctx context.Context) error { temporaryPeripherals[peripheralInfo[1]] = PeripheralInfo{ Name: peripheralInfo[2], SerialNumber: peripheralInfo[1], + IsOpen: peripheralInfo[3] == "O", ProtocolName: "FTDI", } @@ -253,7 +254,6 @@ func (f *FTDIFinder) scanPeripherals(ctx context.Context) error { peripheral, registered := f.registeredPeripherals[peripheralInfo[1]] if registered { runtime.EventsEmit(ctx, string(PeripheralStatus), peripheral.info, "connecting") - time.Sleep(2 * time.Second) err := peripheral.Connect(ctx, location) if err != nil { log.Err(err).Str("file", "FTDIFinder").Str("peripheralSN", peripheralInfo[1]).Msg("unable to connect the peripheral") diff --git a/hardware/interfaces.go b/hardware/interfaces.go index 629df01..09f568f 100644 --- a/hardware/interfaces.go +++ b/hardware/interfaces.go @@ -20,6 +20,7 @@ type PeripheralInfo struct { Name string `yaml:"name"` // Name of the peripheral SerialNumber string `yaml:"sn"` // S/N of the peripheral ProtocolName string `yaml:"protocol"` // Protocol name of the peripheral + IsOpen bool // Open flag for peripheral connection Settings map[string]interface{} `yaml:"settings"` // Peripheral settings } diff --git a/hardware/third-party/ftdi/detectFTDI.cpp b/hardware/third-party/ftdi/detectFTDI.cpp index c1e8722..d5c271f 100644 --- a/hardware/third-party/ftdi/detectFTDI.cpp +++ b/hardware/third-party/ftdi/detectFTDI.cpp @@ -28,8 +28,17 @@ int main() { for (int i = 0; i < numDevs; i++) { if (devInfo[i].SerialNumber[0] != '\0') { - std::cout << i << ":" << devInfo[i].SerialNumber << ":" << devInfo[i].Description << std::endl; + std::cout << i << ":" << devInfo[i].SerialNumber << ":" << devInfo[i].Description << ":"; + + // Add information about the hardware open state + if (devInfo[i].Flags & FT_FLAGS_OPENED) { + std::cout << "O" << std::endl; + } else { + std::cout << "C" << std::endl; + } } } + + free(devInfo); } } \ No newline at end of file