Serial Communication for React Native Windows apps
npm install react-native-serialport-windows
import {
listPorts,
openPort,
closePort,
write,
eventEmitter,
} from 'react-native-serialport-windows';
const availablePorts = await listPorts();
await openPort('COM1', 9600, 8, 1, 0, 0);
// Parameters: portName, baudRate, dataBits, stopBits, parity, flowControl
const data = [0x48, 0x65, 0x6c, 0x6c, 0x6f]; // "Hello"
await write(data);
useEffect(() => {
const subscription = eventEmitter.addListener(
'SerialPortDataReceived',
({ data }) => {
const text = String.fromCharCode(...data);
console.log('Received:', text);
}
);
return () => subscription.remove();
}, []);
await closePort();
git clone https://github.com/MihirGrand/react-native-serialport-windows.git
cd react-native-serialport-windows
npm install
cd example
npm run windows
git checkout -b my-feature-branch
git add .
git commit -m "feat: New feature description"
git push origin my-feature-branch
and create a PR!
MIT