unable to discover any printer, its scanning but not showing any printers on expo. Below is m code #201
Replies: 1 comment
-
Please create an issue with the proper description. Specify printers model names please |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
import React, { useState, useEffect, useCallback } from 'react';
import { View, Text, Button, FlatList, Alert } from 'react-native';
import { usePrintersDiscovery, DiscoveryFilterOption, DiscoveryPortType } from 'react-native-esc-pos-printer'; // Printer discovery hook
const BluetoothPrinterApp = () => {
const [connectedPrinter, setConnectedPrinter] = useState(null);
const {
start,
printerError,
isDiscovering,
printers,
} = usePrintersDiscovery();
useEffect(() => {
// Handle any errors
if (printerError) {
console.error('Error during discovery:', printerError);
Alert.alert('Discovery Error', 'An error occurred during printer discovery.');
}
console.log(printers)
}, [printerError, printers]);
const handleSearchPress = useCallback(() => {
const startDiscoveryProcess = async () => {
try {
// Start discovery process with filter options
await start({
timeout: 10000, // Timeout after 10 seconds
filterOption: { portType: DiscoveryPortType.PORTTYPE_ALL }, // You can filter by port type if needed
});
} catch (error) {
console.error('Error starting printer discovery:', error);
}
};
}, [start]);
// Connect to the selected printer
const connectToPrinter = async (printer) => {
try {
// Assuming Printer instance requires the
target
as the printer's IDconst printerInstance = new Printer({ target: printer.id, deviceName: printer.name });
};
return (
<View style={{ padding: 20 }}>
{isDiscovering ? 'Discovering printers...' : 'Discovery complete'}
);
};
export default BluetoothPrinterApp;
Beta Was this translation helpful? Give feedback.
All reactions