star-micronics / StarXpand-SDK-Android

StarXpand SDK for Android is a software development kit for supporting application development for Star Micronics devices.
https://star-m.jp/starxpandsdk-oml.html
Other
13 stars 0 forks source link

Can we have callback when printer power on/off #22

Open mehtahardikr opened 5 months ago

mehtahardikr commented 5 months ago

Description

We have printer mC-Print3 connected through LAN. We want to reconnect printer or monitor printer when power turn back on. Case is simple

  1. Connect printer through LAN and keep monitor printer.
  2. Power off printer
  3. Power on printer

When its trun back on from off state we are not able to make it monitor again

Your device where the bug occurs

Your printer

Can we have any callback for the same ?

Tatsuki-Yamamoto2731 commented 4 months ago

@mehtahardikr I understand that you're looking for a callback mechanism to automatically reconnect or monitor the printer when it's powered back on after being turned off.

At the moment, our library does not support a callback feature for detecting the printer's power state changes (off to on transitions). Therefore, we recommend implementing a solution on your application's side where you would explicitly attempt to reopen the connection with the printer once you detect it's back online. This could involve periodically checking the printer's availability on the network and attempting a reconnection once it's found to be accessible again.

We take your feedback seriously and will continue to explore the possibility of adding such a specification in future updates.

mehtahardikr commented 4 months ago

@Tatsuki-Yamamoto2731 : Thanks for the reply. Can you help us little for the same like as we have already printer in monitor mode like its already open and now turn off the power and turn back on. now in this case how we can identify that wether its online or not ? as we have instance of active printer is with us and thats monitoring the printer as well. can you suggest for the same. its really help us to get most of it.

Example steps.

  1. Find the printer
  2. Monitor the printer and keep the printer instance alive
  3. Turn off the printer
  4. Turn the printer back on
  5. Now try to print document on same instance.
  6. here we have exception while that operation

Can you please guide in this case that how we can again start monitor printer with same instance and continue print documentt as the last commad is that to print the document.

Here your help needed so, can you please guide for the same. Thanks

Tatsuki-Yamamoto2731 commented 4 months ago

@mehtahardikr If the printer is turned off while monitoring, onCommunicationError will be caused. After that, you have to redo from openAsync() in order to monitor the status or send printing data. What you want to do may be realized by the following steps:

  1. Find the printer
  2. Monitor the printer and keep the printer instance alive
  3. Turn off the printer ( -> onCommunicationError is caused)
  4. Repeat to execute openAsync() until openAsync() is successed
  5. Turn the printer back on ( -> openAsync() will be successed)
  6. Try to print a document on the same instance (and you can also monitor the status)

Could you please try these steps?

mehtahardikr commented 4 months ago

@Tatsuki-Yamamoto2731 : Thank you for the reply. onCommunicationError is called on printerDelegate or when we called openSync() ? as it should be on printerDelegate so can understand that there is something wrong with monitor printer no ?

Tatsuki-Yamamoto2731 commented 4 months ago

@mehtahardikr onCommunicationError will be called on printerDelegate. (For your reference, if openAsync() is executed when the printer is turned off, it will cause StarIO10NotFoundException.)

Do you mean that when you turn off the printer during monitoring, onCommunicationError is not called on printerDelegate? If so, the way to monitor the printer may have something wrong. Could you please let us know your situation?

mehtahardikr commented 4 months ago

Yes, when we turn off the printer during monitoring, onCommunicationError is not called on printerDelegate?

Here one thing noticed.

  1. Find the printer

  2. Start monitor the printer

  3. Print doc for print data

  4. Switch off the printer

  5. its goes to onCommunicationError method of printer delegate

    And another thing also noticed.

  6. Find the printer

  7. Start monitor the printer

  8. Switch off the printer

  9. its not going to onCommunicationError method of printer delegate ( here it has to go here so can acknowledge that there is commnucation error and app will write logic to reconnect and start monitoring.

Tatsuki-Yamamoto2731 commented 4 months ago

@mehtahardikr You found that onCommunicationError is called after printing, but onCommunicationError is not called without printing, is it correct? Then, I tried with our sample code, but I couldn't recreate your problem. In other words, in our sample code, onCommunicationError is called on printerDelegate without printing. Therefore, I want you to try our sample code.

mehtahardikr commented 4 months ago

@Tatsuki-Yamamoto2731 have you tried with MCprint 3 printer and using LAN Connection mode ?

Tatsuki-Yamamoto2731 commented 4 months ago

@mehtahardikr Yes, I tried it with mC-Print3 via LAN.

mehtahardikr commented 4 months ago

@Tatsuki-Yamamoto2731 : Tried by directly remove power cable from socket for printer ( switch off ) it did not fire up onCommunicationError event. You only checked by pressing power button on printer ?

Tatsuki-Yamamoto2731 commented 4 months ago

@mehtahardikr I initially turned off the printer by pressing the power button, but I additionally checked by removing the power cable from the printer to turn it off as you indicated. However, the results were the same, the onCommunicationError occurred even when the power cable was removed from the printer.

Did you try with our sample code?

mehtahardikr commented 4 months ago

yeah got it. getting callback now thanks. @Tatsuki-Yamamoto2731
Can you please update on specific callback that you are foing to implement for new version of this sdk?

https://github.com/star-micronics/StarXpand-SDK-Android/issues/22#issuecomment-2065652708

until can check with that work around onCommunicationError from which start trying to connect printer again.

Tatsuki-Yamamoto2731 commented 4 months ago

@mehtahardikr I understand that you are now able to receive onCommunicationError.

Can you please update on specific callback that you are foing to implement for new version of this SDK?

We received your feedback and we will consider adding the function in the future.