Exemplo n.º 1
0
        public BluetoothStream(BluetoothDevice btdev)
        {
            socket = new Socket((AddressFamily)32, SocketType.Stream, (ProtocolType)3);
            byte[] btAddress = btdev.Address;
            try
            {
                BluetoothEndPoint btep = new BluetoothEndPoint(btAddress, guid_spp);
                utils.ddump("connecting to " + btdev.AddressStr);
                socket.Connect(btep);
                utils.ddump("connected! Create networkstream...");
                networkstream = new NetworkStream(socket, true);

                utils.ddump("starting threads...");
                thSend = new Thread(new ThreadStart(sendThread));
                thSend.Name = "SendThread"; thSend.IsBackground = true;
                thSend.Start();
                utils.ddump("Thread started: " + thSend.Name + ", " + thSend.ManagedThreadId.ToString("x08"));

                thRecv = new Thread(new ThreadStart(recvThread));
                thRecv.Name = "RecvThread"; thRecv.IsBackground = true;
                thRecv.Start();
                utils.ddump("Thread started: " + thRecv.Name + ", " + thRecv.ManagedThreadId.ToString("x08"));
            }
            catch (Exception ex)
            {
                connected = false;
                utils.ddump("BluetoothStream init failed with " + ex.Message);
            }
        }
Exemplo n.º 2
0
 void testConnect2(BluetoothDevice btdev)
 {
     try
     {
         Cursor.Current = Cursors.WaitCursor;
         Application.DoEvents();
         if (button1.Text == "print")
         {
             btstream = new BluetoothStream(btdev);
             btstream.recvThreadEvent += new BluetoothStream.recvThreadEventHandler(btstream_recvThreadEvent);
             int iTry = 3;
             while (iTry > 0 && btstream._connected == false)
             {
                 System.Threading.Thread.Sleep(1000);
                 iTry--;
             }
             if (btstream._connected)
             {
                 if(radioFP.Checked)
                     btstream.write(Intermec.Printer.Language.Fingerprint.Demo.FP_2_WalmartLabel());
                 else if(radioIPL.Checked)
                     btstream.write(Intermec.Printer.Language.Fingerprint.Demo.IPL_2_WalmartLabel());
                 button1.Text = "disconnect";
             }
             else
                 btstream.Dispose();
         }
         else if (button1.Text == "disconnect")
         {
             btstream.recvThreadEvent -= btstream_recvThreadEvent;
             btstream.Dispose();
             button1.Text = "print";
         }
     }
     catch (Exception ex)
     {
         ddump("testConnect2 Exception " + ex.Message);
     }
     finally
     {
         Cursor.Current = Cursors.Default;
         Application.DoEvents();
     }
 }
Exemplo n.º 3
0
        void testConnect(BluetoothDevice btdev)
        {
            byte[] bta = new byte[8];
            bta[0] = 0x00;
            bta[1] = 0x00;
            bta[2] = 0x00;
            bta[3] = 0x06;
            bta[4] = 0x66;
            bta[5] = 0x03;
            bta[6] = 0x09;
            bta[7] = 0xE8;

            BluetoothDevice btd = btdev;// new BluetoothDevice("test", bta);
            System.Net.Sockets.NetworkStream nws;
            //first download the layout program
            byte[] buf;
            try
            {
                ddump("connecting to "+btd.AddressStr);
                nws = btd.Connect(StandardServices.SerialPortServiceGuid);
                if (nws == null)
                {
                    ddump("Connect failed!");
                    return;
                }
                buf = null;
                if(radioFP.Checked)
                    buf = Encoding.Unicode.GetBytes(Intermec.Printer.Language.Fingerprint.Demo.FP_2_WalmartLabel());
                else if(radioIPL.Checked)
                    buf = Encoding.Unicode.GetBytes(Intermec.Printer.Language.Fingerprint.Demo.IPL_2_WalmartLabel());
                if (buf == null)
                {
                    return;
                }
                ddump("writing 1...");
                nws.Write(buf, 0, buf.Length);
                ddump("...writing 1 done");

                if (nws.DataAvailable)
                {
                    ddump("reading...");
                    readData(nws);
                    ddump("...reading done");
                }

                ddump("closing net stream...");
                nws.Close();
                ddump("... net stream closed");

            }
            catch (System.IO.IOException ex)
            {
                ddump("Exception: " + ex.Message);
            }
            catch (System.Net.Sockets.SocketException ex)
            {
                ddump("Exception: " + ex.Message);
            }
            catch (Exception ex)
            {
                ddump("Exception: " + ex.Message);
            }
        }
Exemplo n.º 4
0
 public BluetoothEndPoint(BluetoothDevice device, Guid serviceGuid)
 {
     this.deviceAddress = (byte[])device.Address.Clone();
     this.serviceGuid = serviceGuid;
     this.port = 0;
 }
Exemplo n.º 5
0
 public void Remove(BluetoothDevice value)
 {
     devices.Remove(value);
 }
Exemplo n.º 6
0
 public void Insert(System.Int32 index, BluetoothDevice value)
 {
     devices.Insert(index, value);
 }
Exemplo n.º 7
0
 public System.Int32 IndexOf(BluetoothDevice value)
 {
     return devices.IndexOf(value);
 }
Exemplo n.º 8
0
 public Boolean Contains(BluetoothDevice value)
 {
     return devices.Contains(value);
 }
Exemplo n.º 9
0
 public System.Int32 Add(BluetoothDevice value)
 {
     return devices.Add(value);
 }
 public Boolean Contains(BluetoothDevice value)
 {
     return(devices.Contains(value));
 }
 public System.Int32 IndexOf(BluetoothDevice value)
 {
     return(devices.IndexOf(value));
 }
 public System.Int32 Add(BluetoothDevice value)
 {
     return(devices.Add(value));
 }
 public void Remove(BluetoothDevice value)
 {
     devices.Remove(value);
 }
 public void Insert(System.Int32 index, BluetoothDevice value)
 {
     devices.Insert(index, value);
 }
Exemplo n.º 15
0
 public BluetoothEndPoint(BluetoothDevice device, Guid serviceGuid)
 {
     this.deviceAddress = (byte[])device.Address.Clone();
     this.serviceGuid   = serviceGuid;
     this.port          = 0;
 }