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
14 stars 2 forks source link

StarIO10InUseException when printer restarted or internet fluctuates #28

Open zaibniazinnowi opened 2 months ago

zaibniazinnowi commented 2 months ago

Description

The printer throws a StarIO10UnprintableException when it loses its internet connection during printing, and after retrying, the exception changes to StarIO10InUseException. The printer will not resume printing until it is restarted. The connection loss could be due to internet fluctuations, or the printer being unplugged.

When printer throws StarIO10UnprintableException or StarIO10InUseException. we always disconnect to make printer available for next iteration but failed.

Your device where the bug occurs

Your printer

Is it possible to expose method to release or reset printer instance from SDK so that we do not need to restart printer every time?

Tatsuki-Yamamoto2731 commented 2 months ago

@zaibniazinnowi StarIO10InUseException occurs when the printer has already connected a device. Please check if there is another device that connects to the printer on the network. If there are no other devices, perhaps the previous connection was left open because of some reason. In that case, executing closeAsync() might recover from the error.

zaibniazinnowi commented 2 months ago

@Tatsuki-Yamamoto2731 I called this method frequently, but it didn’t resolve the issue.

It was a one-on-one communication. The printer can recover if it enters an error state when it's not actively printing. However, if an error occurs during printing, it initially throws a StarIO10UnprintableException, and then gets stuck in a StarIO10InUseException state until the printer is restarted.

Tatsuki-Yamamoto2731 commented 2 months ago

@zaibniazinnowi Does the problem occur with our sample program? If not, could you provide a simple source code that recreates the problem?

zaibniazinnowi commented 2 months ago
suspend fun init() {
    logP("IsConnectedToNetwork: ${context._isNetworkAvailable()} SSID: ${context._getSSID()}")
    kotlin.runCatching {
        logP("StarPrintBatchUtil::init()::${appPrinter.name}(${appPrinter.portName}) (${appPrinter.interfaceType})")
        val identifier = appPrinter.portName
        val interfaceType = getInterfaceType(context, appPrinter.interfaceType)
        val settings = StarConnectionSettings(interfaceType, identifier)
        starPrinter = StarPrinter(settings, context)
        starPrinter!!.closeAsync().await()
        starPrinter!!.openAsync().await()

        isPrinterConnected = true
    }.onSuccess {
        logP("StarPrintBatchUtil::init()::${appPrinter.name}(${appPrinter.portName}): Star Printer Initialized Success")
        isPrinterConnected = true
    }.onFailure {
        if (it is StarIO10Exception) {

            Firebase.crashlytics.recordException(it)

        isPrinterConnected = false
    }
}

@Tatsuki-Yamamoto2731 
KHosozawa commented 2 months ago

@zaibniazinnowi

Thank you for the information. We assume that this issue is caused by the printer's inability to detect a physical disconnection of the communication path (Wi-Fi or LAN cable) and the printer maintains the TCP connection even after the disconnection.

The SDK does not provide a means to solve this problem However, the printer itself has a function called “#9100 Data Timeout” that causes the printer to discard TCP connections that have not been communicated with for a specified period of time. Enabling this setting may solve this problem. Can you try this?

Configuration steps.

  1. Open http://(Printer IP Address) in your browser.
  2. Click “Login” on the left side of the screen to log in.
  3. Click “System Configuration” on the left side of the screen.
  4. Change “#9100 Data Timeout (Sec.)” to “30” and click “Submit” button.
  5. Click “Save” on the left side of the screen, then click the “Execute” button.
zaibniazinnowi commented 2 months ago

@KHosozawa Thank you for the solution and it works. Is there any way to modify all printer's timeout that are currently deploy in the field?

KHosozawa commented 2 months ago

@zaibniazinnowi

Sorry, but there is no way to change the settings of multiple printers at the same time.

zaibniazinnowi commented 2 months ago

@KHosozawa while configuring printer using IP address via browser it sometimes keeps on asking for username and password instead of logging in.

KHosozawa commented 2 months ago

@zaibniazinnowi The default user name and password are as follows

If you change the password and forget it, please follow the procedure below to initialize the network settings.

To initialize the configuration information, set the push switches as follows. Press the switch for 1 to 5 seconds during normal operation. The green and red LEDs will flash in a regular pattern. The interface board settings will return to factory defaults. The printer will automatically restart after the interface board has been initialized.

zaibniazinnowi commented 2 months ago

@KHosozawa I have 4 four printers and i updated configuration of one printer. When entered username and password for the first time it asked me to update the password and i updated password with "public" again.

Now when I hit the IP address of other printers, and it keeps on asking for username and password as username and password is correct.

Tatsuki-Yamamoto2731 commented 1 month ago

@zaibniazinnowi I would like to confirm your situation.

My understanding:

If the above situation is true, the user name or password of PrinterB may have been changed. Could you please try the following operation and then access the web configuration again?

Press the push switch for 1 to 5 seconds during normal operation. The green and red LEDs will flash in a regular pattern. Then press the push switch again. The interface board settings will return to factory defaults. The printer will automatically restart after the interface board has been initialized.

*push switch: a small button located near the LAN port on the printer.

zaibniazinnowi commented 1 month ago

@zaibniazinnowi

Thank you for the information. We assume that this issue is caused by the printer's inability to detect a physical disconnection of the communication path (Wi-Fi or LAN cable) and the printer maintains the TCP connection even after the disconnection.

The SDK does not provide a means to solve this problem However, the printer itself has a function called “#9100 Data Timeout” that causes the printer to discard TCP connections that have not been communicated with for a specified period of time. Enabling this setting may solve this problem. Can you try this?

Configuration steps.

  1. Open http://(Printer IP Address) in your browser.
  2. Click “Login” on the left side of the screen to log in.
  3. Click “System Configuration” on the left side of the screen.
  4. Change “#9100 Data Timeout (Sec.)” to “30” and click “Submit” button.
  5. Click “Save” on the left side of the screen, then click the “Execute” button.

@KHosozawa I am facing issue with MCP31 (STR-001) Non-fatal Exception: com.starmicronics.stario10.StarIO10CommunicationException Open failed., and it is expected to resolve after updating configuration mention above but no success.

com.starmicronics.stario10.StarPrinter.a (SourceFile:11) com.starmicronics.stario10.StarPrinter.a (SourceFile:10) com.starmicronics.stario10.StarPrinter.b (SourceFile:3) com.starmicronics.stario10.StarPrinter.access$internalOpen com.starmicronics.stario10.StarPrinter$s.invokeSuspend (Unknown Source:78) kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith (ContinuationImpl.kt:33) kotlinx.coroutines.DispatchedTask.run (DispatchedTask.kt:106) kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely (CoroutineScheduler.kt:584) kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask (CoroutineScheduler.kt:793) kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker (CoroutineScheduler.kt:697) kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run (CoroutineScheduler.kt:684)

After restarting printer, it starts connecting and printing.