资源简介

C# wince 蓝牙控制、搜索设备、文件发送

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using InTheHand.Net;
using InTheHand.Net.Bluetooth;
using InTheHand.Net.Ports;
using InTheHand.Net.Sockets;
using System.Threading;

namespace NewHMIBth
{
    public partial class MainFrm : Form
    {
        private BluetoothListener Listener;
        private List clientList = new List();
       
        private bool listening = true;
        public MainFrm()
        {
            InitializeComponent();
            btnSend.Enabled = false;
            btnStop.Enabled =false;

        }

       private  delegate void SafeWinFormsThreadDelegate(string msg);

        private void WriteMsg(string msg)
        {
            SafeWinFormsThreadDelegate d = new SafeWinFormsThreadDelegate(UpdateUI);
            Invoke(d new object[] { msg });
        }
        private void UpdateUI(string msg)
        {
            this.listBoxMsg.Items.Add(msg);
        }

        private void btnStart_Click(object sender EventArgs e)
        {
            BluetoothRadio radio = BluetoothRadio.PrimaryRadio;
            if (radio == null)
            {
                UpdateUI(“没有发现蓝牙设备或者不支持蓝牙协议栈!“);
                return;
            }
            radio.Mode = RadioMode.Discoverable;
            Listener = new BluetoothListener(BluetoothService.SerialPort);
            Listener.Start();
            listening = true;
            Thread ListenerThread = new Thread(ListenLoop);
            ListenerThread.Start();
            btnStop.Enabled = true;
            btnStart.Enabled = false;
            btnSend.Enabled = true;
            UpdateUI(“蓝牙服务开始!“);
       
        }
        private void ListenLoop()
        { 
              string dataToSend = “感谢您的蓝牙信息订阅\r\n“;
              byte[] dataBuffer = System.Text.Encoding.Unicode.GetBytes(dataToSend);
          while(listening)
          {
             
              try
              {
                  BluetoothClient Client = Listener.AcceptBluetoothClient();
                  WriteMsg(“获得从“+Client.RemoteMachineName+“蓝牙信息订阅“);
                  clientList.Add(Client);
                  System.IO.Stream ns = Client.GetStream();
                  ns.Write(dataBuffer 0 dataBuffer.Length);
              }
              catch
              {
                  break;
              }
          }
          Listener.Stop();
        }

        private void btnSend_Click(object sender EventArgs e)
        {
            BroadLoop(this.txtMsg.Text);
        }

        private void BroadLoop(string Msg)
        {
            List tempClientList = new List();
            string  dataSend=“蓝牙发送的信息内容:“+Msg+“\r\n“;
            Byte[]  dataBuffer=System.Text.Encoding.Unicode.GetBytes(dataSend);
            foreach

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        346  2010-02-13 10:24  Bluetooth\NewHMIBth\NewBthDeviceCab\Debug\CabWiz.log

     文件     245542  2010-02-13 10:24  Bluetooth\NewHMIBth\NewBthDeviceCab\Debug\NewBthDeviceCab.CAB

     文件       1826  2010-02-13 10:24  Bluetooth\NewHMIBth\NewBthDeviceCab\Debug\NewBthDeviceCab.inf

     文件      15960  2010-02-13 10:24  Bluetooth\NewHMIBth\NewBthDeviceCab\NewBthDeviceCab.vddproj

     文件     229888  2009-09-09 08:40  Bluetooth\NewHMIBth\NewHMIBth\bin\Debug\InTheHand.Net.Personal.dll

     文件      13824  2010-03-28 19:28  Bluetooth\NewHMIBth\NewHMIBth\bin\Debug\NewHMIBth.exe

     文件      28160  2010-03-28 19:28  Bluetooth\NewHMIBth\NewHMIBth\bin\Debug\NewHMIBth.pdb

     文件       6392  2010-02-13 10:24  Bluetooth\NewHMIBth\NewHMIBth\MainFrm.cs

     文件      11170  2010-02-13 10:24  Bluetooth\NewHMIBth\NewHMIBth\MainFrm.Designer.cs

     文件       6298  2010-02-13 10:24  Bluetooth\NewHMIBth\NewHMIBth\MainFrm.resx

     文件       4196  2009-12-05 14:21  Bluetooth\NewHMIBth\NewHMIBth\NewHMIBth.csproj

     文件        198  2010-03-28 19:28  Bluetooth\NewHMIBth\NewHMIBth\NewHMIBth.csproj.user

     文件        844  2010-02-13 10:24  Bluetooth\NewHMIBth\NewHMIBth\obj\Debug\NewHMIBth.csproj.GenerateResource.Cache

     文件      13824  2010-03-28 19:28  Bluetooth\NewHMIBth\NewHMIBth\obj\Debug\NewHMIBth.exe

     文件        180  2010-02-13 10:24  Bluetooth\NewHMIBth\NewHMIBth\obj\Debug\NewHMIBth.MainFrm.resources

     文件      28160  2010-03-28 19:28  Bluetooth\NewHMIBth\NewHMIBth\obj\Debug\NewHMIBth.pdb

     文件        180  2009-12-05 21:48  Bluetooth\NewHMIBth\NewHMIBth\obj\Debug\NewHMIBth.Properties.Resources.resources

     文件      13609  2010-04-07 11:04  Bluetooth\NewHMIBth\NewHMIBth\obj\Debug\ResolveAssemblyReference.cache

     文件        284  2010-02-13 10:24  Bluetooth\NewHMIBth\NewHMIBth\obj\NewHMIBth.csproj.FileList.txt

     文件        796  2010-03-28 19:28  Bluetooth\NewHMIBth\NewHMIBth\obj\NewHMIBth.csproj.FileListAbsolute.txt

     文件        356  2009-12-05 13:17  Bluetooth\NewHMIBth\NewHMIBth\Program.cs

     文件       1147  2009-12-05 13:15  Bluetooth\NewHMIBth\NewHMIBth\Properties\AssemblyInfo.cs

     文件       2355  2009-12-05 13:15  Bluetooth\NewHMIBth\NewHMIBth\Properties\Resources.Designer.cs

     文件       5618  2009-12-05 13:15  Bluetooth\NewHMIBth\NewHMIBth\Properties\Resources.resx

     文件       1402  2009-12-05 15:30  Bluetooth\NewHMIBth\NewHMIBth.sln

    ..A..H.     20480  2010-06-17 09:28  Bluetooth\NewHMIBth\NewHMIBth.suo

     文件     139264  2009-10-01 22:40  Bluetooth\NewPCBth\NewPCBth\bin\Debug\InTheHand.Net.Personal.dll

     文件       5632  2005-12-08 14:51  Bluetooth\NewPCBth\NewPCBth\bin\Debug\NewPCBth.vshost.exe

    ..A.SH.      9728  2010-03-28 19:34  Bluetooth\NewPCBth\NewPCBth\bin\Debug\Thumbs.db

     文件       7313  2010-02-13 10:31  Bluetooth\NewPCBth\NewPCBth\Form1.cs

............此处省略43个文件信息

评论

共有 条评论