public DiscoveryEventArgs(DiscoveryType type, MAC mac, MacType macType, byte[] rawAdvertisement, sbyte rssi) { Type = type; MAC = mac; MacType = macType; RawAdvertisements = rawAdvertisement; Advertisements = new Dictionary <byte, byte[]>(); var i = 0; while (i < rawAdvertisement.Length) { // Notice that advertisement or scan response data must be formatted in accordance to the Bluetooth Core // Specification.See BLUETOOTH SPECIFICATION Version 4.0[Vol 3 - Part C - Chapter 11]. var length = rawAdvertisement[i++]; if (length == 0) { break; } var key = rawAdvertisement[i++]; var value = new byte[length - 1]; Array.Copy(rawAdvertisement, i, value, 0, value.Length); Advertisements[key] = value; i += value.Length; } Name = Advertisements.TryGetValue(0x08, out var nameValue) || Advertisements.TryGetValue(0x09, out nameValue) ? Encoding.UTF8.GetString(nameValue) : null; RSSI = rssi; }
public bool ConnectToDevice(MacType macType) { var bIsconnected = false; switch (macType) { case MacType.Net: if (IpAddress.Trim() == "" || Port == 0) { return(false); } bIsconnected = axCZKEM1.Connect_Net(IpAddress, Port); break; case MacType.Com: break; case MacType.Usb: break; default: bIsconnected = false; break; } return(bIsconnected); }
public async Task <Peripheral> ConnectAsync(MAC mac, MacType macType) { var connectionTCS = new TaskCompletionSource <byte>(); var onStatus = new EventHandler <StatusEventArgs>((s, e) => { var eMAC = new MAC(e.Address); var eMacType = (MacType)e.AddressType; if (eMAC != mac || eMacType != macType) { return; } connectionTCS.TrySetResult(e.Connection); }); _messageHub.Connection.Status += onStatus; try { var value = mac.ToArray(); var type = (AddressType)macType; await _messageHub.GAP.ConnectDirectAsync(value, type, 0x20, 0x30, 0x100, 0); var connection = await connectionTCS.Task; var peripheral = new Peripheral(connection, mac, macType); _peripherals[connection] = peripheral; return(peripheral); } finally { _messageHub.Connection.Status -= onStatus; } }
public Peripheral(byte connection, MAC mac, MacType macType) { Services = new Dictionary <ushort, GattService>(); Characteristics = new Dictionary <ushort, GattCharacteristic>(); Connection = connection; MAC = mac; MacType = macType; }
public bool ConnectNet(MacType macType, string ipAddress, int port, int machineNo) { _con = new ConnectToDevices { MacType = MacType.Net, IpAddress = ipAddress, Port = port, MachineNo = machineNo }; _bConnected = axCZKEM1.Connect_Net(ipAddress, port); if (!_bConnected) { axCZKEM1.GetLastError(_idwErrorCode); } return(_bConnected); }
private void LoadData() { DataTableReader dr = null; try { if (SysID == "") { dr = SystemInfo.db.GetDataReader(Pub.GetSQL(DBCode.DB_000300, new string[] { "103" })); if (dr.Read()) { int no = 0; int.TryParse(dr[0].ToString(), out no); if (no == 0) { no++; } txtMacSN.Text = no.ToString(); } } else { dr = SystemInfo.db.GetDataReader(Pub.GetSQL(DBCode.DB_000300, new string[] { "2", SysID })); if (dr.Read()) { txtMacSN.Text = dr["MacSN"].ToString(); txtDevGroup.Text = dr["DevGroupName"].ToString(); txtDevGroup.Tag = dr["DevGroupID"].ToString(); int id = 0; Int32.TryParse(dr["MacSeriesTypeId"].ToString(), out id); int InOutModeId = 0; Int32.TryParse(dr["InOutMode"].ToString(), out InOutModeId); cbbInOutMode.SelectedIndex = InOutModeId; int DevModeId = 0; Int32.TryParse(dr["DevModeID"].ToString(), out DevModeId); cbbMacMode.SelectedIndex = DevModeId; MacType type = GetMacType(id); if (type != null) { cbbMacType.SelectedItem = type; } switch (dr["MacConnType"].ToString()) { case MacConnTypeString.USB: rbUSB.Checked = true; break; case MacConnTypeString.LAN: rbLAN.Checked = true; txtLANIP.Text = dr["MacIP"].ToString(); txtLANPort.Text = dr["MacPort"].ToString(); txtLANPWD.Text = dr["MacConnPWD"].ToString(); chkGPRS.Checked = Pub.ValueToBool(dr["IsGPRS"]); break; } txtDesc.Text = dr["MacDesc"].ToString(); } } } catch (Exception E) { Pub.ShowErrorMsg(E); } finally { if (dr != null) { dr.Close(); } dr = null; } }