Skip to content

Commit

Permalink
data reading improved
Browse files Browse the repository at this point in the history
  • Loading branch information
Amanmahe committed Oct 4, 2024
1 parent 8499297 commit 31817c1
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/components/Connection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const Connection: React.FC<ConnectionProps> = ({
const writerRef = useRef<WritableStreamDefaultWriter<Uint8Array> | null>(
null
);
const buffer: number[] = []; // Buffer to store incoming data
const bufferdRef =useRef<number[][][]>([[], []]); // Two buffers: [0] and [1]

const togglePause = () => {
Expand Down Expand Up @@ -238,12 +239,13 @@ const Connection: React.FC<ConnectionProps> = ({

const reader = port.readable?.getReader();
readerRef.current = reader;

const writer = port.writable?.getWriter();
if (writer) {
writerRef.current = writer;
const message = new TextEncoder().encode("START\n");
await writer.write(message);
setTimeout(function () {
writerRef.current = writer;
const message = new TextEncoder().encode("START\n");
writerRef.current.write(message);
}, 2000);
} else {
console.error("Writable stream not available");
}
Expand Down Expand Up @@ -306,7 +308,7 @@ const Connection: React.FC<ConnectionProps> = ({

// Function to read data from a connected device and process it
const readData = async (): Promise<void> => {
const buffer: number[] = []; // Buffer to store incoming data

const HEADER_LENGTH = 3; // Length of the packet header
const NUM_CHANNELS = 6; // Number of channels in the data packet
const PACKET_LENGTH = 16; // Total length of each packet
Expand Down

0 comments on commit 31817c1

Please sign in to comment.