蓝牙拨号32feet.net和c#

Tim*_*Tim 7 c# mobile telephony bluetooth

我正在尝试为某人提供一个"点击拨号"解决方案,如蓝牙设备,如手机.我一直试图使用32feet.net bluetooth api这样做.

我没有真正用蓝牙做任何事情(因为通过蓝牙串口发出命令的日子)但我已经配对有问题的设备,它支持pc的免提服务.我有以下代码尝试连接并发送拨号命令.

String deviceAddr = "11:11:11:11:11:11";
BluetoothAddress addr = BluetoothAddress.Parse(deviceAddr);
BluetoothEndPoint rep = new BluetoothEndPoint(addr, BluetoothService.Handsfree);
BluetoothClient cli = new BluetoothClient();
cli.Connect(rep);
Stream peerStream = cli.GetStream();

String dialCmd = "ATD 0000000000\r\n";
Byte[] dcB = System.Text.Encoding.ASCII.GetBytes(dialCmd);
peerStream.Write(dcB, 0, dcB.Length);

// Begin Edit ------------------------------------------------------------
Byte[] sResponse = new Byte[100];
peerStream.Read(sResponse, 0, 99);
TextBox1.Text = System.Text.Encoding.ASCII.GetString(sResponse);
// End Edit --------------------------------------------------------------

peerStream.Close();
cli.Close();
MessageBox.Show("Done");
Run Code Online (Sandbox Code Playgroud)

因为它似乎贯穿了这些代码行,所以在适当的时间连接相关的位置,如果设备地址错误且无法连接,则会崩溃.显然,AT命令不是发送它的正确方法.

任何人都可以通过免提配置文件告诉我可能需要发送到蓝牙设备以使其拨号吗?

开始编辑-------------------------------------------

我决定从流中读取并查看在发送AT命令后是否有任何类型的响应.由于我只是在测试是否可以使其工作,我只是将响应转储到文本框中.

我从流中读到的响应是:

ERROR
Run Code Online (Sandbox Code Playgroud)

似乎没有错误代码或任何东西.

结束编辑---------------------------------------------

编辑------------------------------------------------- -

发送命令:AT + CMER\r \n

结果:好的

然后

发送命令:AT + CIND =?\ r \n

结果:+ CIND :("service",(0-1)),("call",(0-1)),("callsetup",(0-3)),("battchg",(0-5) )),( "信号",(0-5)),( "漫游",(0-1)),( "callheld",(0-2))

然后

发送命令:ATD 0000000000\r

结果:OK D :("service",(0-1)),("call",(0-1)),("callsetup",(0-3)),("battchg",(0-5) )),( "信号",(0-5)),( "漫游",(0-1)),( "callheld",(0-2))

仍然它实际上不拨号:(

结束编辑----------------------------------------------

解决方案----------------------------------------------

以下代码现在可以通过我的iPhone拨号.这一刻真的非常粗糙,因为我刚刚进行了测试,看看能不能让它发挥作用.对于想要做类似事情的其他人来说,这已经足够了.

String deviceAddr = "00:00:00:00:00:00"; 
        BluetoothAddress addr = BluetoothAddress.Parse(deviceAddr);
        BluetoothEndPoint rep = new BluetoothEndPoint(addr, BluetoothService.Handsfree);

        BluetoothClient cli = new BluetoothClient();
        cli.Connect(rep);
        Stream peerStream = cli.GetStream();

        String dialCmd1 = "AT+CMER\r";
        String dialCmd2 = "AT+CIND=?\r";
        String dialCmd3 = "AT+BRSF=\r";
        String dialCmd4 = "ATD 0000000000;\r";

        Byte[] dcB = System.Text.Encoding.ASCII.GetBytes(dialCmd1);
        peerStream.Write(dcB, 0, dcB.Length);

        Byte[] sRes = new Byte[200];
        peerStream.Read(sRes, 0, 199);
        textBox1.Text = textBox1.Text + "\n\r----------\n\r" + System.Text.Encoding.ASCII.GetString(sRes);

        dcB = System.Text.Encoding.ASCII.GetBytes(dialCmd2);
        peerStream.Write(dcB, 0, dcB.Length);

        peerStream.Read(sRes, 0, 199);
        textBox1.Text = textBox1.Text + "\n\r----------\n\r" + System.Text.Encoding.ASCII.GetString(sRes);

        dcB = System.Text.Encoding.ASCII.GetBytes(dialCmd3);
        peerStream.Write(dcB, 0, dcB.Length);

        peerStream.Read(sRes, 0, 199);
        textBox1.Text = textBox1.Text + "\n\r----------\n\r" + System.Text.Encoding.ASCII.GetString(sRes);

        dcB = System.Text.Encoding.ASCII.GetBytes(dialCmd4);
        peerStream.Write(dcB, 0, dcB.Length);

        peerStream.Read(sRes, 0, 199);
        textBox1.Text = textBox1.Text + "\n\r----------\n\r" + System.Text.Encoding.ASCII.GetString(sRes);

        peerStream.Close();
        cli.Close();
Run Code Online (Sandbox Code Playgroud)

Ume*_*AKA 3

尝试找出 AT\r(或)ATH\r 的响应是什么。如果响应为“OK\r\n”,请尝试拨号命令,ATD 和号码后不要有空格。