You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 22, 2024. It is now read-only.
import'./App.css';import{useWebSerial}from'react-webserial-hook';interfaceSerialPortFilter{usbVendorId?: number;usbProductId?: number;// Add other properties as needed for your specific filtering criteria}functionApp(){constdecoder=newTextDecoder();constencoder=newTextEncoder();constfilters: SerialPortFilter={usbVendorId: 1155,usbProductId: 22336,};constserial=useWebSerial({onData: (data: Uint8Array)=>{constdecodedData=decoder.decode(data);console.log('Received:',decodedData);},});consthandleGetPort=async()=>{awaitserial.requestPort(filters);};consthandleOpenPort=async()=>{awaitserial.openPort();if(serial.port){console.log(serial.portInfo(serial.port));}};conststartReading=async()=>{if(!serial.isReading&&serial.isOpen){awaitserial.startReading();}};conststopReading=()=>{if(serial.isReading&&serial.isOpen){serial.stopReading();}};constsendLog=async()=>{if(serial.isReading){awaitserial.write(encoder.encode('log'));console.log('Sent: log');}else{console.error('Serial port is not open.');}};return(<divclassName="App"><headerclassName="App-header"><buttononClick={()=>handleGetPort()}>Pairanewport</button><buttononClick={()=>handleOpenPort()}>Opentheselectedport</button><buttononClick={startReading}>Startreading</button><buttononClick={stopReading}>Stopreading</button><buttononClick={sendLog}>SendLog</button></header></div>);}exportdefaultApp;
i only get error:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'port')
at Object.write (index.js:296:1)
at sendLog (App.tsx:49:1)
at HTMLUnknownElement.callCallback (react-dom.development.js:4164:1)
at Object.invokeGuardedCallbackDev (react-dom.development.js:4213:1)
at invokeGuardedCallback (react-dom.development.js:4277:1)
at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:4291:1)
at executeDispatch (react-dom.development.js:9041:1)
at processDispatchQueueItemsInOrder (react-dom.development.js:9073:1)
at processDispatchQueue (react-dom.development.js:9086:1)
at dispatchEventsForPlugins (react-dom.development.js:9097:1)
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
i only get error:
The text was updated successfully, but these errors were encountered: