C# - Windows Mobile - 与Zebra RW 420配对

时间:2012-05-10 18:55:27

标签: c# windows-mobile bluetooth windows-mobile-6

更新:这可能不是“配对”。这可能只需要启动服务并绑定到端口。但是,此代码也不存储它。即使应用程序关闭,我也需要存储设备。

我正在Windows Mobile 6手持设备上构建一个特别适合Zebra RW 420的程序。应用程序需要允许移动设备与COM1上的打印机配对。我相信我非常接近它,但我无法让这对请求发挥作用。

我可以通过直接连接和打印与打印机进行通信甚至打印,但我无法让移动设备实际配对。我尝试过各种针脚,包括null"1""0000""1234"。无论如何,该方法总是返回false。任何建议或想法为什么这可能会失败?我可以将设备配对,只需在WM6蓝牙菜单中找到,但不能在我的应用程序中找到。

重要的是要注意打印机上的小灯泡图标会在程序尝试配对时亮起,但在大约5到10秒后,它会失败。

BluetoothSecurity.PairRequest(device, "1"))

其他信息:

我已成功使用此代码与我的Android手机配对。

然后我登录并在Zebra打印机上设置了PIN。但是,即使我知道打印机中的引脚是正确的/设置,此代码仍然无法与打印机配对。


来自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蓝牙的移动打印机只是“奴隶”设备。打印机将与尝试建立有效连接的任何“主”设备配对。由于只有主设备可以启动连接,因此打印机不存储配对数据,该功能始终在主设备上完成。打印机一次只能连接到一个主设备,但任何数量的已存储打印机配对信息的主设备都可以启动与打印机的连接而无需重新发现。

我猜这意味着InTheHand.Net BluetoothSecurity.PairRequest可能无法用于此类配对?


在WM掌上电脑的蓝牙部分,在“设备”选项卡下,我可以添加设备。我需要基本上这样做。我需要在该列表中注册该设备,然后将其设置为在“COM端口”部分中使用COM 1。我正在使用的应用程序实际上并不打印。它的唯一目的是为其他应用程序准备打印机。

2 个答案:

答案 0 :(得分:0)

Zebra的引用让人觉得配对实际上根本不需要配对。你是从你的应用程序打印?如果是这样,只需连接到SPP服务并发送文本。

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 ...

(来自General Bluetooth Data Connections

答案 1 :(得分:0)

在配对此方法之前,需要正确配置Zebra移动打印机。这是我做的:

  • 首先,我在打印机上运行以下命令:

! 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"
  • 然后,使用此代码的应用程序成功运行。

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);