Skip to content

Commit 4287405

Browse files
authored
Merge pull request #3 from Amanmahe/reconnection
Connection issue resolved
2 parents 7058be7 + 942a022 commit 4287405

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/components/Connection.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ const Connection: React.FC<ConnectionProps> = ({
113113
const maxCanvasCountRef = useRef<number>(1);
114114
const [isAllEnabledSelected, setIsAllEnabledSelected] = useState(false);
115115
const channelNamesfil = Array.from({ length: maxCanvasCountRef.current }, (_, i) => `CH${i + 1}`);
116+
const initialSelectedChannel = useRef<any[]>([1]);
116117

117118

118119
const readerRef = useRef<
@@ -307,7 +308,6 @@ const Connection: React.FC<ConnectionProps> = ({
307308
}
308309
};
309310

310-
//////////////////////////////////
311311
const workerRef = useRef<Worker | null>(null);
312312

313313
const initializeWorker = () => {
@@ -410,8 +410,6 @@ const Connection: React.FC<ConnectionProps> = ({
410410

411411
};
412412

413-
//////////////////////////////////////////
414-
415413
const handleCustomTimeChange = (e: React.ChangeEvent<HTMLInputElement>) => {
416414
// Function to handle the custom time input change
417415
const value = e.target.value.replace(/[^0-9]/g, "");
@@ -478,6 +476,7 @@ const Connection: React.FC<ConnectionProps> = ({
478476
baudRate: number;
479477
}
480478

479+
481480
const connectToDevice = async () => {
482481

483482
try {
@@ -508,7 +507,6 @@ const Connection: React.FC<ConnectionProps> = ({
508507

509508
let baudRate;
510509
let serialTimeout;
511-
let initialSelectedChannels
512510
// If no saved port is found, request a new port and save it
513511
if (!port) {
514512
port = await navigator.serial.requestPort();
@@ -553,7 +551,7 @@ const Connection: React.FC<ConnectionProps> = ({
553551

554552
if (deviceIndex !== -1) {
555553
const savedChannels = savedPorts[deviceIndex].selectedChannels;
556-
initialSelectedChannels = savedChannels.length > 0 ? savedChannels : [1]; // Load saved channels or default to [1]
554+
initialSelectedChannel.current = savedChannels.length > 0 ? savedChannels : [1]; // Load saved channels or default to [1]
557555
}
558556

559557
baudRate = savedDevice?.baudRate || 230400; // Default to 230400 if no saved baud rate
@@ -605,7 +603,7 @@ const Connection: React.FC<ConnectionProps> = ({
605603
baudRate: extractedBaudRate,
606604
serialTimeout: extractedSerialTimeout,
607605
} = formatPortInfo(currentPortInfo, extractedName, usbProductId);
608-
const allSelected = initialSelectedChannels.length === channelCount;
606+
const allSelected = initialSelectedChannel.current.length == channelCount;
609607
setIsAllEnabledSelected(allSelected);
610608
// Update baudRate and serialTimeout with extracted values
611609
baudRate = extractedBaudRate ?? baudRate;

0 commit comments

Comments
 (0)