1: public enum BthEstadosRadio : int
2: { Desactivado, Activado, Detectable };
3:
4: public class BTHRadio : IDisposable
5: {
6: [DllImport("bthutil.dll", SetLastError = true)]
7: private static extern int BthGetMode(out BthEstadosRadio mode);
8: [DllImport("bthutil.dll", SetLastError = true)]
9: private static extern int BthSetMode(BthEstadosRadio mode);
10: [DllImport("Btdrt.dll", SetLastError = true)]
11: private static extern int BthReadLocalVersion(
12: ref byte phci_version, ref ushort phci_revision,
13: ref byte plmp_version, ref ushort plmp_subversion,
14: ref ushort pmanufacturer, ref byte plmp_features);
15: [DllImport("Btdrt.dll", SetLastError = true)]
16: private static extern int BthReadCOD(ref CategoriaDispositivo pcod);
17: [DllImport("Ws2.dll", SetLastError = true)]
18: public static extern int WSACleanup();
19: [DllImport("Ws2.dll", SetLastError = true)]
20: public static extern int WSAStartup(ushort version, byte[] wsaData);
21: //los enumeradores Fabricantes y CategoriaDispositivo son
22: //identificadores únicos (http://www.bluetooth.org)
23: private Fabricantes _fabricante;
24: private short _versionRadio;
25: private CategoriaDispositivo _claseDisp;
26: //constructor
27: public BTHRadio()
28: { // inicializamos sockets
29: ushort wsv =
30: ((ushort)(((byte)(2)) | ((ushort)((byte)(2))) << 8));
31: byte[] _data = new byte[512];
32: WSAStartup(wsv, _data);
33: //obt. versión y fabricante
34: byte version = 0, lversion = 0, caract = 0;
35: ushort revision = 0, lsubrevision = 0, fab = 0;
36: BthReadLocalVersion(ref version, ref revision,
37: ref lversion, ref lsubrevision, ref fab, ref caract);
38: this._fabricante = fab;
39: this._versionRadio = (short)lsubrevision;
40: //obtenemos categoría disp.
41: BthReadCOD(ref this._claseDisp);
42: }
43: //propiedad lectura/escritura del estado de radio
44: public BthEstadosRadio EstadoRadio
45: {
46: get
47: {
48: BthEstadosRadio currentMode;
49: BthGetMode(out currentMode);
50: return currentMode;
51: }
52: set
53: { BthSetMode(currentMode); }
54: }
55: //liberamos WS2.dll
56: public void Dispose()
57: { WSACleanup(); }
58: }