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

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

问题描述

我想为别人蓝牙设备点击拨号的解决方案,如移动电话。我一直在努力这样做,使用32feet.net蓝牙API。

我还没有真正做到与蓝牙任何东西(因为在命令通过蓝牙串行端口的日子),但我已经配对有问题的设备,它支持与PC免提服务。我有以下的code尝试连接并发送一个拨号命令。

 字符串deviceAddr =11:11:11:11:11:11;
BluetoothAddress地址= BluetoothAddress.Parse(deviceAddr);
BluetoothEndPoint代表=新BluetoothEndPoint(地址,BluetoothService.Handsfree);
BluetoothClient CLI =新BluetoothClient();
cli.Connect(REP);
流peerStream = cli.GetStream();字符串dialCmd =ATD 0000000000 \\ r \\ n;
字节[] = 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(完成);

由于它似乎看透了code,这些线路的运行,采取适当的时候在有关现场连接或崩溃了,如果设备的地址是错误的,它不能连接。显然,AT命令是不正确的事情被发送。

谁能赐教,以什么我可能需要通过免提模式发送到蓝牙设备才能正常拨号?

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

我决定从流中读取,看看是否有任何形式的通过发送AT命令后的响应。因为我只是测试,看看我是否可以把它的工作,我只是倾销响应到一个文本框。

我从流中读取的响应是:

 错误

似乎没有是一个错误codeS或任何东西。

编辑完---------------------------------------------

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

发送命令:AT + CMER \\ r

结果:OK

然后

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

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

然后

发送命令:ATD 0000000000 \\ r

结果:

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

不过它实际上并没有拨打:(

编辑完--------------------------------------------- -

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

以下code现在工作通过我的iPhone拨号。这是此刻真的粗​​糙,正如我刚才一直在测试,看看我能使其发挥作用。这足以开始为别人想要做类似的事情。

 字符串deviceAddr =00:00:00:00:00:00;
        BluetoothAddress地址= BluetoothAddress.Parse(deviceAddr);
        BluetoothEndPoint代表=新BluetoothEndPoint(地址,BluetoothService.Handsfree);        BluetoothClient CLI =新BluetoothClient();
        cli.Connect(REP);
        流peerStream = cli.GetStream();        字符串dialCmd1 =AT + CMER \\ R;
        字符串dialCmd2 =AT + CIND = \\ R;
        字符串dialCmd3 =AT + BRSF = \\ R;
        字符串dialCmd4 =ATD 0000000000; \\ R;        字节[] = DCB System.Text.Encoding.ASCII.GetBytes(dialCmd1);
        peerStream.Write(DCB,0,dcB.Length);        字节[] = SRES新的字节[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();


解决方案

试着找到什么是AT \\ R(或)ATH \\ r的响应。
如果响应是OK \\ r \\ n,尝试用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\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");

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\r

Result : OK

then

Sent command : AT+CIND=?\r

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\r

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\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();

解决方案

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

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

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