带 32feet.net 和 c# 的蓝牙拨号 [英] Bluetooth dial with 32feet.net and c#

查看:17
本文介绍了带 32feet.net 和 c# 的蓝牙拨号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为使用蓝牙设备(如手机)的人提供点击拨号"解决方案.我一直在尝试使用 32feet.net 蓝牙 API.

我真的没有用蓝牙做过任何事情(自从通过蓝牙串行端口执行命令的日子以来),但我已经将有问题的设备配对,它支持免提服务与电脑.我有以下代码尝试连接并发送拨号命令.

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);流 peerStream = cli.GetStream();String dialCmd = "ATD 0000000000
";字节[] dcB = System.Text.Encoding.ASCII.GetBytes(dialCmd);peerStream.Write(dcB, 0, dcB.Length);//开始编辑------------------------------------------------------------字节[] sResponse = 新字节[100];peerStream.Read(sResponse, 0, 99);TextBox1.Text = System.Text.Encoding.ASCII.GetString(sResponse);//结束编辑 -----------------------------------------------peerStream.Close();cli.Close();MessageBox.Show("完成");

由于好像是通过这几行代码运行的,所以需要花点时间在相关位置连接,否则如果设备地址错误而无法连接则崩溃.显然,发送 AT 命令不是正确的事情.

谁能告诉我我可能需要通过免提配置文件向蓝牙设备发送什么才能让它拨号?

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

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

我从流中读取的响应是:

错误

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

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

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

发送指令:AT+CMER

结果:好的

然后

发送指令:AT+CIND=?

结果:+CIND: ("service",(0-1)),("call",(0-1)),("callsetup",(0-3)),("batchg",(0-5)),("信号",(0-5)),("漫游",(0-1)),("呼叫保持",(0-2))

然后

发送命令:ATD 0000000000

结果:行D: ("service",(0-1)),("call",(0-1)),("callsetup",(0-3)),("batchg",(0-5)),("信号",(0-5)),("漫游",(0-1)),("呼叫保持",(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);流 peerStream = cli.GetStream();String dialCmd1 = "AT+CMER
";String dialCmd2 = "AT+CIND=?
";String dialCmd3 = "AT+BRSF=
";String dialCmd4 = "ATD 0000000000;
";字节[] dcB = System.Text.Encoding.ASCII.GetBytes(dialCmd1);peerStream.Write(dcB, 0, dcB.Length);字节[] sRes = 新字节[200];peerStream.Read(sRes, 0, 199);textBox1.Text = textBox1.Text + "

---------

" + 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 + "

---------

" + 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 + "

---------

" + 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 + "

---------

" + System.Text.Encoding.ASCII.GetString(sRes);peerStream.Close();cli.Close();

解决方案

尝试找出对 AT (或)ATH 的响应是什么.如果响应为OK ",请尝试在 ATD 和号码后不要空格的拨号命令.

I am trying to provide a "click to dial" solution for someone to a bluetooth device such as a mobile phone. I have been trying to do so using the 32feet.net bluetooth api.

I haven't really done anything with bluetooth (since the days of at commands via a bluetooth serial port) but I have paired the device in question, which supports the handsfree service with the pc. I have the following code to attempt to connect and send a dial command.

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
";
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");

Since it seems to run through these lines of code, taking an appropriate time to connect at the relevant spot or crashing out if the device address is wrong and it can't connect. Obviously the AT command is not the right thing to be sending it.

Can anyone enlighten me as to what I might need to send to a bluetooth device via the handsfree profile to get it to dial?

Begin Edit -------------------------------------------

I decided to read from the stream and see if there was a response of any sort after sending the AT command through. Since I am just testing to see if I can make it work I am just dumping the response into a textbox.

The response I read from the stream is :

ERROR

There doesn't seem to be an error codes or anything.

End Edit ---------------------------------------------

Edit --------------------------------------------------

Sent command : AT+CMER

Result : OK

then

Sent command : AT+CIND=?

Result : +CIND: ("service",(0-1)),("call",(0-1)),("callsetup",(0-3)),("battchg",(0-5)),("signal",(0-5)),("roam",(0-1)),("callheld",(0-2))

then

Send command : ATD 0000000000

Result: OK D: ("service",(0-1)),("call",(0-1)),("callsetup",(0-3)),("battchg",(0-5)),("signal",(0-5)),("roam",(0-1)),("callheld",(0-2))

Still it doesn't actually dial :(

End Edit ----------------------------------------------

Solution ----------------------------------------------

The following code now works to dial via my iPhone. It's really rough at the moment, as I have just been testing to see if I could make it work. It's enough to get started for anyone else wanting to do a similar thing.

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
";
        String dialCmd2 = "AT+CIND=?
";
        String dialCmd3 = "AT+BRSF=
";
        String dialCmd4 = "ATD 0000000000;
";

        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 + "

----------

" + 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 + "

----------

" + 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 + "

----------

" + 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 + "

----------

" + System.Text.Encoding.ASCII.GetString(sRes);

        peerStream.Close();
        cli.Close();

解决方案

Try to find what is the response for AT (or) ATH . If the response is "OK ", try your dial command with no space after ATD and number.

这篇关于带 32feet.net 和 c# 的蓝牙拨号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆