Comments (5)
Hello @EthanCents ,
First, accept my apology for the poor documentation for the discovery service.
After you start discovery, it will push the result by LocalBroadcastReceiver.
the code should be more or less look like this:
You need to import DeviceEventEmitter from react-native
import { DeviceEventEmitter } from 'react-native'
Depending on how you write on React, whether you use React Hooks, or Class, or Redux. I use hooks,
useEffect(()=>{ var listener = DeviceEventEmitter.addListener("TMPrinterFound", (item)=>{ //DO TO WHAT YOU WANT TO DO WITH ITEM. //item consist of {PrinterName:String, Target:String} . in this case, Target is the IP Address }) return ()=>{ listener.remove() } },[])
or in the class component you could use similar like this:
`
var listener;
componentDidMount(){
listener = DeviceEventEmitter.addListener("TMPrinterFound", (item) => {
//DO TO WHAT YOU WANT TO DO WITH ITEM.
//item consist of {PrinterName:String, Target:String} . in this case, Target is the IP Address
})
}
componentWillUnmount(){
if(listener) listener.remove();
}
`
DeviceEventListener will start getting called if you call TM.startDiscover() and will stop on TM.stopDiscovery();
I hope this will help you.. By the way, the code is written for Epson TM-T82 for Wifi model as I have only this model. The code might not work on USB and Bluetooth model and I couldn't test on real device.
If you are able to implement on bluetooth or usb device, please give me a feedback so I could update on the README for other to use
from rn-epson-tm82.
Not a problem at all! Thanks for getting back to me!
I'm just setting up my code in a regular class/component structure right now. I'm guessing within the addListener() method, you would add your printer to state? Or something to that nature? I'm just trying to determine where exactly the listener variable gets called or referenced, because it appears that whenever I run startDiscovery(), the actual LocalBroadcastReceiver isn't called.
Or at least on the React side, when I reference the DeviceEventEmitter, the result is undefined.
Is it possible that there is interference with my emulator?
from rn-epson-tm82.
Pardon me, I am a bit confuse to the question. Let me guess:
-
I'm guessing within the addListener() method, you would add your printer to state?
in the addListener method, you would listen to the channel "TMPrinterFound" and it is case-sensitive. If any printer on the same network was found by ePOS, it will push the message, and you will get the object consist of PrinterName and Target. Target is the IP Address of the Printer. -
I'm just trying to determine where exactly the listener variable gets called or referenced
Listener variable get called if there is Epson TM-T82 on the same network found. -
whenever I run startDiscovery(), the actual LocalBroadcastReceiver isn't called
the LocalBroadcastReceiver is not called directly as it need time to find especially if there is a lot of devices connected to your network.
By the way, it might not work on emulator because emulator use bridging connection to the host. You may try debugging on real device to get the actual result
from rn-epson-tm82.
Ah, it could've been because I was using the emulator. I also added:
<activity android:name="com.epson.epos2_printer.DiscoverActivity"></activity>
to my AndroidManifest.
Now I'm able to retrieve the device and pass it into startPrint(). However, when I do that, I get an error: Epos2Exception.ERR_CONNECT
. Which is strange to me given that I am retrieving the target in my event listener and can verify it's being passed through to the android code. Did you run into any connection issues when configuring things?
from rn-epson-tm82.
According to https://reference.epson-biz.com/modules/ref_epos_sdk_and_en/index.php?vid=ref_epos_sdk_and_en_printerclass_connect#BCFFFFBI ERR_CONNECT error is when it couldn't connect to the printer.
Could you give me the sample code?
from rn-epson-tm82.
Related Issues (9)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rn-epson-tm82.