我正在尝试为某人提供一个“点击拨号”解决方案,以便移动电话等蓝牙设备。我一直试图使用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");
由于它似乎贯穿了这些代码行,因此需要花费适当的时间在相关位置进行连接,或者如果设备地址错误且无法连接则会崩溃。显然,AT命令不是发送它的正确方法。
任何人都可以通过免提配置文件告诉我可能需要发送到蓝牙设备以使其拨号吗?
开始编辑-------------------------------------------
我决定从流中读取并查看在发送AT命令后是否有任何类型的响应。由于我只是在测试是否可以使其工作,我只是将响应转储到文本框中。
我从流中读到的响应是:
ERROR
似乎没有错误代码或任何内容。
结束编辑---------------------------------------------
编辑---------------------------------------------- ----
发送命令:AT + CMER \ r
结果:确定
然后
已发送命令:AT + CIND =?\ r
结果: + CIND :(“service”,(0-1)),(“call”,(0-1)),(“callsetup”,(0-3)),(“battchg”,(0-5)) ,( “信号”,(0-5)),( “漫游”,(0-1)),( “callheld”,(0-2))
然后
发送命令:ATD 0000000000 \ r
结果: 好 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();
答案 0 :(得分:3)
尝试查找AT \ r \ n(或)ATH \ r \ n的响应。 如果响应为“OK \ r \ n”,请尝试在ATD和编号后没有空格的拨号命令。
答案 1 :(得分:1)
作为32feet.NET的维护者,我很乐意找到答案。希望有HSP / HFP知识的人能解释为什么这不起作用。我唯一的猜测是,由于我们不接受/创建音频通道的SCO频道,因此手机拒绝连接。
在你的情况下,然而...... AT命令由CR(0Dh)终止;或者分号是否一样?