安卓通过蓝牙向下位机STM32连续发送数据问题 80
这是蓝牙BluetoothContactService的一个handler@OverridepublicvoidhandleMessage(Messagemsg){sup...
这是蓝牙BluetoothContactService的一个handler
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
int value16Bit = (Integer) msg.obj ;
switch (msg.what) {
case MassageHandler.MASSAGE_SEND:
try {
write(value16Bit) ;
} catch (IOException e) {
e.printStackTrace();
}
break;
default:
break;
}
}
这是BluetoothContactService发送函数
public void write(int value16Bit) throws IOException {
if(!APPConstant.getConnectedFlag()){
return;
}
byte[] msgBuffer = new byte[2];
msgBuffer[0] = (byte)(value16Bit >> 0 & 0xff);
outputStream.write(msgBuffer[0]);
msgBuffer[1] = (byte)(value16Bit >> 8 & 0xff);
outputStream.write(msgBuffer[1]);
}
这是主程序的一个开关,CMD_HAND=0xFEFD,CMD_START_TIM=0X00A2
private class SwitchButtonCheckListener implements OnCheckedChangeListener{
@Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
if (isChecked) {
BluetoothContactService.massageHandler.obtainMessage(MassageHandler.MASSAGE_SEND,0,0, APPConstant.CMD_HAND).sendToTarget() ;
BluetoothContactService.massageHandler.obtainMessage(MassageHandler.MASSAGE_SEND,0,0, APPConstant.CMD_START_TIM).sendToTarget() ;
}
}}
但是这样下位机总是只能接收到CMD_HAND,如果这两个分开来发却又接收的到,比如我把发送CMD_START_TIM放在另一个按钮里,先按这个SwitchButton在按放CMD_START_TIM就可以。
下位机中断函数
void USART3_IRQHandler(void)
{
u8 temp ;
if(USART_GetITStatus(USART3 , USART_IT_RXNE) != RESET)
{
temp = USART_ReceiveData(USART3) ;
printf("massage had receive form bluetooth:%x\n",temp) ;
massageAnalyse(temp) ; //处理接收数据的函数
}
}
我的问题就是连续快速的发送2个16位数据为什么只能接收1个16位数据,分开发就可以? 展开
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
int value16Bit = (Integer) msg.obj ;
switch (msg.what) {
case MassageHandler.MASSAGE_SEND:
try {
write(value16Bit) ;
} catch (IOException e) {
e.printStackTrace();
}
break;
default:
break;
}
}
这是BluetoothContactService发送函数
public void write(int value16Bit) throws IOException {
if(!APPConstant.getConnectedFlag()){
return;
}
byte[] msgBuffer = new byte[2];
msgBuffer[0] = (byte)(value16Bit >> 0 & 0xff);
outputStream.write(msgBuffer[0]);
msgBuffer[1] = (byte)(value16Bit >> 8 & 0xff);
outputStream.write(msgBuffer[1]);
}
这是主程序的一个开关,CMD_HAND=0xFEFD,CMD_START_TIM=0X00A2
private class SwitchButtonCheckListener implements OnCheckedChangeListener{
@Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
if (isChecked) {
BluetoothContactService.massageHandler.obtainMessage(MassageHandler.MASSAGE_SEND,0,0, APPConstant.CMD_HAND).sendToTarget() ;
BluetoothContactService.massageHandler.obtainMessage(MassageHandler.MASSAGE_SEND,0,0, APPConstant.CMD_START_TIM).sendToTarget() ;
}
}}
但是这样下位机总是只能接收到CMD_HAND,如果这两个分开来发却又接收的到,比如我把发送CMD_START_TIM放在另一个按钮里,先按这个SwitchButton在按放CMD_START_TIM就可以。
下位机中断函数
void USART3_IRQHandler(void)
{
u8 temp ;
if(USART_GetITStatus(USART3 , USART_IT_RXNE) != RESET)
{
temp = USART_ReceiveData(USART3) ;
printf("massage had receive form bluetooth:%x\n",temp) ;
massageAnalyse(temp) ; //处理接收数据的函数
}
}
我的问题就是连续快速的发送2个16位数据为什么只能接收1个16位数据,分开发就可以? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询