-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Only detecting 1 or 0 printers #40
Comments
@rissois Hi! Could you please try to update to version 1.5.0 and try to increase discovery timeout to 10 sec i.e. ? EscPosPrinter.discover({ scanningTimeoutIOS: 10000, scanningTimeoutAndroid: 10000 })
.then(printers => {
console.log('done!', printers);
}) |
@tr3v3r Thanks for the response, and sorry for the delay. I upgrade to Version 1.5.0 and increased the scanningTimeoutIOS to 10 seconds. Both issues persisted: Printing out a network status sheet and hardcoding the name, mac address, ip address, and target (presumed Please advise if there are any further tests I can perform to help troubleshoot this. Thanks. |
i have same problem |
@rissois Hi! I can confirm that TM-T20II is supported as well as multiple printers discovery ( since we have such functionality in our app ). Can you confirm that during the search the printers are not reserved by someone else? ( I mean not printing/connected at the moment of searching from another device ). Have you tried on Android? Could you please share the exact code you're using? |
Hi
I am sorry for not clarify. I use Epson tm m30. The problem is some time it can detect found the printer, and sometime it cannot detect the printer. It very difficult to detect.
I detect 10 times, it will be found the printer in 2 time only
Thank you
From: Aliaksei Astafyeu ***@***.***>
Sent: Monday, December 6, 2021 2:51 PM
To: tr3v3r/react-native-esc-pos-printer ***@***.***>
Cc: chukiatt ***@***.***>; Comment ***@***.***>
Subject: Re: [tr3v3r/react-native-esc-pos-printer] Only detecting 1 or 0 printers (Issue #40)
@rissois<https://github.com/rissois> Hi!
I can confirm that TM-T20II is supported as well as multiple printers discovery ( since we have such functionality in our app ). Can you confirm that during the search the printers are not reserved by someone else? ( I mean not printing/connected at the moment of searching from another device ).
Have you tried on Android?
Could you please share the exact code you're using?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#40 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AEEYLICEJIILWOKPGVP4SGLUPRTNXANCNFSM5IM4L4LA>.
Triage notifications on the go with GitHub Mobile for iOS<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Thanks again for getting back to me. Unfortunately I do not have an Android device to test with, if I speak to my friend later this week perhaps they can lend me one. Yes, each restaurant has 4-6 printers, and while I am testing none of the printers are actively in use. Please find below the code exactly as it is in my app, with restaurant information deidentified as #
|
Thank you very much
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows
From: ***@***.***>
Sent: 6 ธันวาคม 2564 22:44
To: ***@***.***>
Cc: ***@***.***>; ***@***.***>
Subject: Re: [tr3v3r/react-native-esc-pos-printer] Only detecting 1 or 0 printers (Issue #40)
@tr3v3r<https://github.com/tr3v3r>
Thanks again for getting back to me. Unfortunately I do not have an Android device to test with, if I speak to my friend later this week perhaps they can lend me one.
Yes, each restaurant has 4-6 printers, and while I am testing none of the printers are actively in use.
Please find below the code exactly as it is in my app, with restaurant information deidentified as #
import React, { useState, useEffect, useCallback } from 'react';
import Encoder from 'esc-pos-encoder';
import { StyleSheet, View, Button } from 'react-native';
import EscPosPrinter, {
getPrinterSeriesByName,
IPrinter,
} from 'react-native-esc-pos-printer';
import { base64Image } from './base64Image';
// Discovered these printers one-by-one
const restaurant1 = [
{
bt: "",
ip: "###.###.###.###",
mac: "##:##:##:##:##",
name: "TM-T20",
target: "TCP:###.###.###.###",
usb: "",
station: "Bar",
},
{
bt: "",
ip: "###.###.###.###",
mac: "##:##:##:##:##",
name: "TM-T20",
target: "TCP:###.###.###.###",
usb: "",
station: "Kitchen",
},
{
bt: "",
ip: "###.###.###.###",
mac: "##:##:##:##:##",
name: "TM-T20",
target: "TCP:###.###.###.###",
usb: "",
station: "Server station",
},
];
// Unable to find any printers
const restaurant2 = [];
export default function App() {
const [init, setInit] = useState(false);
const [printer, setPrinter] = useState(null);
useEffect(() => {
EscPosPrinter.addPrinterStatusListener(status => {
console.log('current printer status:', status);
});
}, []);
useEffect(() => {
console.log(printer);
}, [printer]);
const printSpecific = useCallback(async p => {
const encoder = new Encoder();
encoder
.initialize()
.line('The quick brown fox jumps over the lazy dog')
.newline()
.newline()
.newline();
try {
console.log('pre-init');
await EscPosPrinter.init({
target: p.target,
seriesName: getPrinterSeriesByName(p.name),
language: 'EPOS2_LANG_EN',
});
console.log('post-init');
setInit(true);
console.log('pre-print');
const printing = new EscPosPrinter.printing();
console.log('post-print');
const status = await printing.data(encoder.encode()).cut().send();
console.log('print', status);
}
catch (error) {
console.log('error', error);
}
}, []);
return (
<View style={styles.container}>
{
restaurant1.map(p => {
return <Button
key={p.station}
title={`Print ${p.station}`}
color={'blue'}
onPress={() => {
printSpecific(p)
}}
/>;
})
}
<Button
title="Discover"
onPress={() => {
console.log('discovering');
// EscPosPrinter.discover()
EscPosPrinter.discover({ scanningTimeoutIOS: 60000, scanningTimeoutAndroid: 10000 })
.then(printers => {
console.log('done!', printers);
if (printers[0]) {
setPrinter(printers[0]);
}
})
.catch(console.log);
}}
/>
<Button
title="Get lines per row"
disabled={!printer}
color={!printer ? 'gray' : 'blue'}
onPress={async () => {
if (printer) {
if (!init) {
await EscPosPrinter.init({
target: printer.target,
seriesName: getPrinterSeriesByName(printer.name),
language: 'EPOS2_LANG_EN',
});
setInit(true);
}
const status = await EscPosPrinter.getPrinterCharsPerLine(
getPrinterSeriesByName(printer.name),
);
console.log('print', status);
}
}}
/>
<Button
title="Start monitor printer status"
disabled={!printer}
color={!printer ? 'gray' : 'blue'}
onPress={async () => {
if (printer) {
if (!init) {
await EscPosPrinter.init({
target: printer.target,
seriesName: getPrinterSeriesByName(printer.name),
language: 'EPOS2_LANG_EN',
});
setInit(true);
}
const status = await EscPosPrinter.startMonitorPrinter();
console.log('Printer status:', status);
}
}}
/>
<Button
title="Stop monitor printer status"
disabled={!printer}
color={!printer ? 'gray' : 'blue'}
onPress={async () => {
if (printer) {
if (!init) {
await EscPosPrinter.init({
target: printer.target,
seriesName: getPrinterSeriesByName(printer.name),
language: 'EPOS2_LANG_EN',
});
setInit(true);
}
const status = await EscPosPrinter.stopMonitorPrinter();
console.log('Printer status:', status);
}
}}
/>
<Button
title="Print from data"
disabled={!printer}
color={!printer ? 'gray' : 'blue'}
onPress={async () => {
const encoder = new Encoder();
encoder
.initialize()
.line('The quick brown fox jumps over the lazy dog')
.newline()
.newline()
.newline();
try {
if (printer) {
if (!init) {
await EscPosPrinter.init({
target: printer.target,
seriesName: getPrinterSeriesByName(printer.name),
language: 'EPOS2_LANG_EN',
});
setInit(true);
}
const printing = new EscPosPrinter.printing();
const status = await printing.data(encoder.encode()).cut().send();
console.log('print', status);
}
} catch (error) {
console.log('error', error);
}
}}
/>
<Button
title="Test print chaining"
disabled={!printer}
color={!printer ? 'gray' : 'blue'}
onPress={async () => {
try {
if (printer) {
if (!init) {
await EscPosPrinter.init({
target: printer.target,
seriesName: getPrinterSeriesByName(printer.name),
language: 'EPOS2_LANG_EN',
});
setInit(true);
}
const printing = new EscPosPrinter.printing();
const status = await printing
.initialize()
.align('center')
.size(3, 3)
.line('DUDE!')
.smooth(true)
.line('DUDE!')
.smooth(false)
.size(1, 1)
.text('is that a ')
.bold()
.underline()
.text('printer?')
.bold()
.underline()
.newline(2)
.align('center')
.image(require('./store.png'), {
width: 75,
halftone: 'EPOS2_HALFTONE_THRESHOLD',
})
.image({ uri: base64Image }, { width: 75 })
.image(
{
uri: 'https://raw.githubusercontent.com/tr3v3r/react-native-esc-pos-printer/main/ios/store.png',
},
{ width: 75 },
)
.barcode({
value: 'Test123',
type: 'EPOS2_BARCODE_CODE93',
width: 2,
height: 50,
hri: 'EPOS2_HRI_BELOW',
})
.qrcode({
value: 'Test123',
level: 'EPOS2_LEVEL_M',
width: 5,
})
.cut()
.send();
console.log('printing', status);
}
} catch (error) {
console.log('error', error);
}
}}
/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
box: {
width: 60,
height: 60,
marginVertical: 20,
},
});
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#40 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AEEYLIGZQN6OF2A7QVTGG5LUPTK7JANCNFSM5IM4L4LA>.
Triage notifications on the go with GitHub Mobile for iOS<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
@rissois are you trying to connect via Wi-Fi or LAN? Can you confirm that ip |
@tr3v3r For the second question, are you referring to physical proximity or the subnet? I have printed the status sheet for each printer, and the TCP/IP status lists the same network address for both (they share the same first 9 digits). Hopefully that is helpful, please let me know if I misinterpreted any your questions. I appreciate the response. EDIT: Subnet mask is 255.255.255.0, so pretty standard there. |
Another observation I forgot to mention: the Discovery returns the single printer before the full 10 seconds completes, so this may be a premature response. |
@rissois Actually 10 sec it's just a timeout to stop discovery if nothing is found. Since I have only one printer currently it would be nice if you could figure out the problem. Here is how the discovery of the printer works: JS side: ...
discoveryEventEmmiter.addListener(
'onDiscoveryDone',
(printers: IPrinter[]) => {
res(printers);
removeListener();
}
);
... iOS native side - node_modules/react-native-esc-pos-printer/ios/EscPosPrinterDiscovery.m - (void) onDiscovery:(Epos2DeviceInfo *)deviceInfo
{
[_printerList addObject:deviceInfo];
NSMutableArray *stringArray = [[NSMutableArray alloc] init];
// you can log what actually is returned by SDK
for (int i = 0; i < [_printerList count]; i++)
{
Epos2DeviceInfo *info = _printerList[i];
NSString *name = [info getDeviceName];
NSString *ip = [info getIpAddress];
NSString *mac = [info getMacAddress];
NSString *target = [info getTarget];
NSString *bt = [info getBdAddress];
NSString *usb = [self getUSBAddress: target];
[stringArray addObject:@{
@"name": name,
@"ip": ip,
@"mac": mac,
@"target": target,
@"bt": bt,
@"usb": usb
}];
}
[self sendEventWithName:@"onDiscoveryDone" body:stringArray];
NSLog(@"Discovery done!");
}
I left a comment on the iOS native side. Could you please try to LOG what is returned by native SDK? |
@tr3v3r I am still having the issue mentioned on #37, which I am now thinking that passing longer timeout isn't a real solution but just a coincidence that it found the printer (but still probably not a bad thing to allow passing the timeout from JS side). So I have TM-m30 Bluetooth, which works perfectly on ios, immediately discovered every time, but on Android, it is still not consistent, it doesn't return the printer sometimes. I have tried adding some logs in |
After more debugging, I noticed that the printer discovery may take considerably longer, so I just did 50 seconds as a timeout and sometimes the |
@fragilehm Hi! I suppose the reason could not be with discovery but with establishing the connection between device and printer. Also, have you tried to test on different devices with different OS versions? The problem may lie with Android/Arc. version. Then we need to research this problem in the context of native Android apps since this library is just a simple wrapper above native SDK, moreover, we can try to test it using the latest SDK ( possibly the problem has been already fixed by Epson). Current SDK ver. used in this lib is 2.17.1. P.S. Unfortunately I have only one LAN printer all hopes for contributors ) |
@tr3v3r Yes, I have tried updating to the latest SDK just replacing the necessary files in node_modules directly and rebuilding the app, but nothing changed. Maybe I was updating the wrong way.
This should work right or any other files I have missed maybe? |
@fragilehm should work. Ok what about other points I’ve mentioned? |
Had the same issue so decided to debug it to best of my knowledge.
I added a breakpoint in xCode to EscPosPrinterDiscovery.m to see whats happening in onDiscovery. I'll try to dig into it a bit more tomorrow and I can also test out other scenarios if you want. |
Wow! Thanks a lot so instead
We need
Right now I can’t prove it because of huge workload ( |
@tr3v3r that is indeed the case, so what happens is the discovery gets resolved as soon as the first printer is found as the |
As a workaround please try using this. |
QUICK STARTING QUESTION: Does this package work with the TM-T20II?
I found some businesses kind enough to let me test printing on their systems. I created a new React Native app solely for testing the package, and copied App.tsx directly from the example.
At the first location, EscPosPrinter.discover() only returned one printer at random. I could discover additional printers by reloading the app.
At the second location, EscPosPrinter.discover() did not discover any printers. I printed the Network Settings ticket from one of the printers and tried to connect directly through the IP address there, but received ERR_CONNECT.
Both locations were using the same POS system, and the POS system readily displayed all printers on the network. Terminal command arp -a verified that I could detect devices at both locations as well.
Unfortunately, my programming skills are too weak to contribute directly to this code, but I wanted to report this issue as it may help identify some bug within the code.
My App.js was copied directly from the example, but modified from tsx to js:
The text was updated successfully, but these errors were encountered: