Skip to content

About

Serial Communication for React Native Windows

Resources

Code of conduct

Contributing

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

42 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Serial Communication for React Native Windows apps

Installation

npm install react-native-serialport-windows
import {
  listPorts,
  openPort,
  closePort,
  write,
  eventEmitter,
} from 'react-native-serialport-windows';

Usage

1. List available ports

Retrieve a list of all available serial ports:

const availablePorts = await listPorts();

1. Open a port

Open a port with the desired settings:

await openPort('COM1', 9600, 8, 1, 0, 0);
// Parameters: portName, baudRate, dataBits, stopBits, parity, flowControl

2. Write data

Send data to the serial port. Data should be an array of byte values:

const data = [0x48, 0x65, 0x6c, 0x6c, 0x6f]; // "Hello"
await write(data);

3. Receive data

Listen for incoming data using the eventEmitter:

useEffect(() => {
  const subscription = eventEmitter.addListener(
    'SerialPortDataReceived',
    ({ data }) => {
      const text = String.fromCharCode(...data);
      console.log('Received:', text);
    }
  );

  return () => subscription.remove();
}, []);

4. Close the port

When finished, ensure the port is closed:

await closePort();

Example

git clone https://github.com/MihirGrand/react-native-serialport-windows.git

cd react-native-serialport-windows

npm install

cd example

npm run windows

react-native-serialport-windows

Contributing

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!

License

MIT

About

Serial Communication for React Native Windows

Resources

Code of conduct

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages