Connect to a printer that is offline

HI,

 

I notice that when connecting to an printer that is either offline or not visible on the network by using a wrong IP the [printer conn] call takes a while to complete. Is there a way to prevent this long wait?

Is there a timeout that I can set somewhere?

 

Thanks

Sonu Kapoor
Anybody?

Anybody?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Hi Sonu,You can set the

Hi Sonu,

You can set the maxTimeoutForRead when you create a new connection.  Keep in mind, if you do this, it may miss your printer.  If the network is slow, or the printer is at the limit of it's range, or there are a lot of printers availible, all can cause it to take longer to find. 

Hope this helps,

Robin

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Hi Sonu, I'm going to correct

Hi Sonu, I'm going to correct myself and tell you to use the NetworkDiscovery class in the SDK.  The findPrinters(DiscoveryHandler discoveryHandler, List<String> printersToFind, int waitForResponsesTimeout) function has a parameter for timeout (int waitForResponsesTimeout).  You can use this function even if you know the IP of the printer you want (List<String> printersToFind).  My same warnings will hold true though, if you make the timeout too low, it may miss printers.  It's a callback function as well, so you don't have to worry about freezing the app while you wait.

Robin

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Sonu Kapoor
Thanks. I will try this out

Thanks. I will try this out and report back.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Sonu Kapoor
Any chance you can help out

Any chance you can help out with some sample code?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
This is modified from the SDK

This is modified from the SDK documentation.  There is also examples in the SDK install: android\v2.8.2148\demos\src\com\zebra\android\devdemo\discovery.


import java.util.ArrayList;

import java.util.List;

import com.zebra.sdk.printer.discovery.DiscoveredPrinter;

import com.zebra.sdk.printer.discovery.DiscoveryException;

import com.zebra.sdk.printer.discovery.DiscoveryHandler;

import com.zebra.sdk.printer.discovery.NetworkDiscoverer;

public class NetworkDiscovererExample {

     public static void main(String[] args) {

         DiscoveryHandler discoveryHandler = new DiscoveryHandler() {

             List<DiscoveredPrinter> printers = new ArrayList<DiscoveredPrinter>();

             public void foundPrinter(DiscoveredPrinter printer) {

                 printers.add(printer);

             }

             public void discoveryFinished() {

                 for (DiscoveredPrinter printer : printers) {

                     System.out.println(printer);

                 }

                 System.out.println("Discovered " + printers.size() + " printers.");

             }

             public void discoveryError(String message) {

                 System.out.println("An error occurred during discovery : " + message);

             }

         };

         try {

             int timeout = 3000;

             List<Sring> ipList = new List<string>();

             ipList.add("10.80.127.80");

             System.out.println("Starting printer discovery.");

             NetworkDiscoverer.findPrinters(discoveryHandler, ipList, timeout);

         } catch (DiscoveryException e) {

             e.printStackTrace();

         }

     }

}

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Sonu Kapoor
Hi Robin,I am using iOS. I

Hi Robin,

I am using iOS. I found the method: directedBroadcastWithIpAddress in the documentation. However the description says the following:

Sends a directed broadcast discovery packet to the subnet specified by ipAddress.


I tried to use that function, but it finds a list of other devices. Unfortunately the array doesn't give me the IPAddress of the returned devices, otherwise I could compare that to the one I need. Here is my code I have used. Any ideas?


NSArray *ar = [NetworkDiscoverer

                   directedBroadcastWithIpAddress:ipAddress

                   andWaitForResponsesTimeout:10000 error:&error];

   

    if (ar.count == 0)

    {

        pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:error.localizedDescription];

        NSLog(@"printer not available => %@", error.localizedDescription);

        [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];

        return;

    }

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Sonu Kapoor
Any idea?

Any idea?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Hi Sonu,If you go to the

Hi Sonu,

If you go to the Zebra API documentation on your computer, in the I want to.. section choose Print Over TCP/IP. There are some code examples there and you can specify which IP address you are looking for. There is an instance method setMaxTimeoutForOpen which is the default time, in milliseconds, to wait for a TCP connection to open, I think that is what you are looking for.

Let me know if this helps,

Beverly

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Sonu Kapoor
I can't seem to set the

I can't seem to set the timeout or I am doing something wrong:

id<ZebraPrinterConnection, NSObject> printer = [[TcpPrinterConnection

alloc] initWithAddress:ipAddress andWithPort:6101];

// printer setMaxTimeoutForOpen doesnt exist???

On Thu, Nov 5, 2015 at 2:14 PM, Beverly Vinson <

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Try this:id

Try this:

id<ZebraPrinterConnection, NSObject> printer = [[TcpPrinterConnection

alloc] initWithAddress:ipAddress andWithPort:6101];

[((TcpPrinterConnection*)printer) setMaxTimeoutForOpen:30];

Thanks,

Beverly

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Sonu Kapoor
That timeout should be set in

That timeout should be set in milliseconds right?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Sonu,Yes you are correct, the

Sonu,

Yes you are correct, the timeout is in milliseconds.

Thank you,

Beverly

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Sonu Kapoor
Thank you. This works

Thank you. This works beautiful.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Sonu,Great! I am glad it is

Sonu,

Great! I am glad it is working out well.

Thank you,

Beverly

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments