简体   繁体   中英

stariosdk getport failure advice needed

I have developed an app in phonegap (html5, JQuery, JS) and I want to develop a plugin to print to a BT printer.

I download printer manufacturer's SDK and I imported the appropriate .jar file to my project with all the methods I will need in my project.

I create a plugin, following an internet tutorial, in order to call from JS the JAVA methods from printer manufacturers SDK.

When i run my testing app always i receive "Failed to connect to printer".

my java code is as follow

public PluginResult execute(String action, JSONArray data, String callbackId) {


    if (NATIVE_ACTION_STRING.equals(action)) {


        this.ctx.runOnUiThread(new Runnable()
        {
            public void run()
            {
                String resultType = null;
                StarIOPort port = null;
                String message = null;
                String portName = "bt:";
                String portSettings = "mini";
                byte[] texttoprint = new byte[]{0x1b,0x74,0x0D,(byte) 0x91,(byte) 0x92,(byte) 0x93,(byte) 0x94,(byte) 0x95,(byte) 0x96,(byte) 0x97,(byte) 0x98,(byte) 0x99,0x0A,0x0A,0x0A,0x0A,0x0A};


                try 
                {
                    port = StarIOPort.getPort(portName, portSettings, 10000, (Context)ctx);

                    try
                    {
                        Thread.sleep(500);
                    }
                    catch(InterruptedException e) {}


                    port.writePort(texttoprint, 0, texttoprint.length);

                    try
                    {
                        Thread.sleep(3000);
                    }
                    catch(InterruptedException e) {}    

                }
                catch (StarIOPortException e)
                {

                    Builder dialog = new AlertDialog.Builder((Context)ctx);
                    dialog.setNegativeButton("Ok", null);
                    AlertDialog alert = dialog.create();
                    alert.setTitle("Failure");
                    alert.setMessage("Failed to connect to printer");
                    alert.show();
                }
                finally
                {
                    if(port != null)
                    {
                        try 
                        {
                            StarIOPort.releasePort(port);
                        } catch (StarIOPortException e) {}
                    }
                }
            }
        });

    }
     return null;
}}

If someone has any knowledge on StarMicronics SDK please advice.

add

    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <uses-permission android:name="android.permission.BLUETOOTH"></uses-permission>

in your manifest

确保在便携式打印机上将蓝牙模式设置为与您使用的操作系统相同:蓝牙模式-> Android,蓝牙(IAP)-> I-phone

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM