Domanda

Update: This may not be "Pairing". This may just need to have a service started and bound to a port. However, this code is not storing it either. I need the device to be stored even after the application is closed.

I am building a program specifically suited for Zebra RW 420's on a Windows Mobile 6 Handheld device. The application needs to allow a mobile device to pair with the printer on COM1. I believe I am very close to getting it, but I can't get the pair request to work.

I am able to communicate with the printer and even print by directly connecting and printing, but I can't get the mobile device to actually pair with it. I've tried a variation of pins to include null, "1", "0000", and "1234". No matter what, the method always returns false. Any suggestions or ideas why this might be failing? I can pair the device just find in the WM6 Bluetooth menu, but not in my application.

It might be important to note that the little light bulb icon on the printer comes on when the program says it is attempting to pair, but after about 5 to 10 seconds, it fails.

BluetoothSecurity.PairRequest(device, "1"))

Additional Information:

I've successfully paired with my Android phone using this code.

I then logged in and set a PIN on the Zebra printer. However, this code still fails to pair with the printer even when I know the pin is correct / set in the printer.


From https://km.zebra.com/kb/index?page=answeropen&type=open&searchid=1336682809706&answerid=16777216&iqaction=5&url=https%3A%2F%2Fkm.zebra.com%2Fkb%2Findex%3Fpage%3Dcontent%26id%3DSO8031%26actp%3Dsearch%26viewlocale%3Den_US&highlightinfo=6292341,26,43#

Zebra Bluetooth enabled mobile printers are 'slave' devices only. The printers will pair with any 'master' device that tries to make a valid connection. Since only a master device can initiate a connection, the printer does not store pairing data, that function is always done on the master device. The printer can only be connected to one master device at a time, but any number of master devices that have stored pairing information for the printer would be able to initiate a connection to the printer without having to rediscover it.

I'm guessing that this means the InTheHand.Net BluetoothSecurity.PairRequest might not work for this type of pairing?


In the Bluetooth section of the WM handheld, under the "Devices" tab, I can add the device. I need to essentially do that. I need to register the device in that list and then set it to use COM 1 in the "COM Ports" section. The application I am using doesn't actually print. It's sole purpose is to prepare the printer for other applications.

È stato utile?

Soluzione

The quote from Zebra make it sounds as pairing is actually not required at all. Are you printing from your app? If so just connect to the SPP service and send the text.

BluetoothAddress addr = ...
Guid serviceClass;
serviceClass = BluetoothService.SerialPort;
var ep = new BluetoothEndPoint(addr, serviceClass);
var cli = new BluetoothClient();
cli.Connect(ep);
Stream peerStream = cli.GetStream();
peerStream.Write ...

(From General Bluetooth Data Connections)

Altri suggerimenti

The Zebra Mobile Printer needed to be properly configured before pairing with this method will work. Here is what I did:

  • First, I ran the following commands on the printer:

.

! U1 setvar "bluetooth.authentication" "setpin"

! U1 getvar "bluetooth.authentication"

! U1 getvar "bluetooth.enable"

! U1 getvar "bluetooth.discoverable"

! U1 setvar "bluetooth.bluetooth_pin" "0000"

! U1 getvar "bluetooth.bluetooth_pin"
  • Then, the application with this code ran successfully.

.

int pair_req = 0;
try
{
    if (BluetoothSecurity.SetPin(device, "0000")) {
        while (status == false && pair_req < 3)
        {
            ++pair_req;
            status_box.Text = status_box.Text + '\n' + "Attempt " + pair_req.ToString();
            status_box.Update();


            if (BluetoothSecurity.PairRequest(device, "0000"))
            {
                status = true;
                client.Refresh();
                status_box.Text = "Paired Successfully.";
                status_box.Update();
                Thread.Sleep(5000);
            }
            else
            {
                status = false;

            }

        }
    }
}
catch (ArgumentNullException e)
{
    status_box.Text = "Pair failed.";
    status_box.Update();
    Thread.Sleep(5000);
}

status_box.Update();
Thread.Sleep(400);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top