安卓蓝牙通讯组件。
图1 | 图2 | 图3 |
属性 |
属性说明 |
---|---|
BluetoothStatus |
蓝牙状态。 |
方法 |
方法说明 |
---|---|
Close |
关闭蓝牙。 |
CloseConnect |
断开连接上的蓝牙设备。 |
Connect |
连接指定蓝牙。 |
ConnectWithSearch |
连接指定蓝牙,在未配对的情况下会尝试搜索连接 |
GetStatus |
获取蓝牙连接状态。 |
Open |
打开蓝牙。 |
Search |
查找并连接蓝牙。 |
WriteData |
发送蓝牙信息。 |
C#: bluetooth1.Open((abj, args) => { if (args.isError == true) Toast(args.error); else Toast("success"); });
C#: bluetooth1.Close((abj, args) => { if (args.isError == true) Toast(args.error); else Toast("success"); });
C#: bluetooth1.Search((abj, args) => { if (args.isError == true) Toast(args.error); else Toast("success" + args.Name + " " + args.MacAddress); MessageBox.Show(args.Name + " " + args.MacAddress); });
C#: bluetooth1.Connect("00:0D:18:00:19:98", (abj, args) => { if (args.isError == true) Toast(args.error); else Toast("success"); });
C#: bluetooth1.ConnectWithSearch("00:0D:18:00:19:9C", (abj, args) => { if (args.isError) Toast(args.error); else { Toast(args.args.ToString()); } });
C#: bluetooth1.CloseConnect((abj, args) => { if (args.isError == true) Toast(args.error); else Toast("success"); });
C#: string str = "690000001"; string print = "SIZE 80 mm,40 mm\r\n" + "REFERENCE 0,0\r\n" + "SPEED 4.0\r\n" + "DENSITY 8\r\n" + "SET PEEL OFF\r\n" + "SET CUTTER OFF\r\n" + "SET TEAR ON\r\n" + "DIRECTION 0\r\n" + "SHIFT 0\r\n" + "OFFSET 0 mm\r\n" + "CLS\r\n" + "BARCODE 20,20,\"128M\",160,1,0,4,12,\"" + str + "\"\r\n" + "TEXT 20,190,\"ARIAL.TTF\",0,15,15,\"" + str + "\"\n" + "PRINT 3,1\r\n"; bluetooth1.WriteData(System.Text.Encoding.UTF8.GetBytes(print), (abj, args) => { if (args.isError == true) Toast(args.error); else Toast("success"); });
C#: bluetooth1.GetStatus((abj, args) => { if (args.isError == true) Toast(args.error); else Toast(args.Status + " " + args.Name + " " + args.MacAddress); MessageBox.Show(args.Status + " " + args.Name + " " + args.MacAddress); });
在设计器中选中Bluetooth,添加事件
C#: private void bluetooth1_DataReceived(object sender, Smobiler.Plugins.BluetoothDataReceivedEventArgs e) { Toast(e.Data.ToString()); // MessageBox.Show(System.Text.Encoding.GetEncoding("gbk").GetString(e.Data)); }