馒头科技MTSerialBle AT指令手册V2.1

需积分: 10 13 下载量 196 浏览量 更新于2024-07-21 收藏 1.37MB PDF 举报
"MTSerialBle-AT指令手册 V2.1" MTSerialBle是馒头科技开发的一款基于蓝牙4.0 BLE(Bluetooth Low Energy)技术的透明传输模块。该手册详细介绍了模块的AT(Attention)指令集,用于配置和控制模块的功能。以下是手册中的关键知识点: 1. **版本更新**: - 模块固件经历了多次更新,从V101到V210,修复了多项问题,如协议栈更新、多路PWM设置冲突、默认设备名修改、IO控制指令修改等,并增加了新功能,如用户自定义数据、模块远控指令、IO主动上报和安全连接管理。 2. **使用注意事项**: - 用户在使用过程中需要注意模块的正确操作,避免导致指令操作失败。 - 手册提供了错误信息、状态信息的解读,帮助用户识别和解决问题。 3. **模块出厂设置**: - 出厂时模块可能已预设了特定的配置,如波特率、工作模式等,用户需了解这些设置以便正确使用。 4. **常用指令**: - **测试指令**:用于测试模块是否正常工作。 - **固件版本查询**:获取模块当前的固件版本信息。 - **设备名查询/设置**:更改或查看模块的设备名称。 - **恢复出厂设置**:将模块设置重置为出厂状态。 - **重启模块**:关闭并重新启动模块。 - **当前工作状态查询**:查看模块的工作模式和状态。 - **状态通知使能查询/设置**:控制模块是否发送状态变化的通知。 - **模块工作方式查询/设置**:切换模块的工作模式,如透传模式。 - **主从模式查询/设置**:设置模块为主设备或从设备。 - **远控指令**:允许远程控制模块,增强灵活性。 5. **串口指令**: - **串口波特率查询/设置**:调整串口通信的波特率。 - **串口停止位查询/设置**:设置串口通信的停止位。 - **串口发送延时时间查询/设置**:设置串口发送数据之间的延迟时间,以优化传输效率。 6. **从机指令**: - **广播间隔查询/设置**:调整从设备的广播间隔时间。 - **查询/设置其他从机指令**:手册中可能还包括其他从机模式下的指令,如连接参数设置、服务配置等。 7. **安全连接管理**: - 提供了安全连接的相关指令,确保无线通信的安全性。 8. **主机扫描配置指令**: - 允许用户配置主机扫描参数,提高蓝牙扫描的性能和效率。 通过这些指令,用户可以对MTSerialBle模块进行精细化配置,满足不同应用场景的需求,实现与蓝牙设备的有效通信。手册还提供了详细的指令格式和响应示例,方便用户理解和操作。
2015-08-03 上传
安卓蓝牙APP通讯。package com.mt.truthblue2_1; import java.util.ArrayList; import java.util.List; import com.mt.mtblesdk.MTBeacon; import com.mt.tools.Tools; import com.mt.truthblue2_1.BLEService.LocalBinder; import android.annotation.SuppressLint; import android.app.Activity; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.Message; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.BaseAdapter; import android.widget.ListView; import android.widget.TextView; public class MainActivity extends Activity { private final static int REQUEST_ENABLE_BT = 2001; private ServiceConnection connection = new ServiceConnection() { @Override public void onServiceDisconnected(ComponentName name) { } @Override public void onServiceConnected(ComponentName name, IBinder service) { LocalBinder binder = (LocalBinder) service; Tools.mBLEService = binder.getService(); if (Tools.mBLEService.initBle()) { // scanBle(); // 开始扫描设备 if (!Tools.mBLEService.mBluetoothAdapter.isEnabled()) { final Intent enableBtIntent = new Intent( BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } else { scanBle(); // 开始扫描设备 } } } }; @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_ENABLE_BT) { if (resultCode == RESULT_OK) { scanBle(); // 开始扫描设备 } else { // finish(); } } } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); bindService(new Intent(this, BLEService.class), connection, Context.BIND_AUTO_CREATE); } // 初始化控件 private LayoutInflater mInflater; private ListView ble_listview; private List<MTBeacon> scan_devices = new ArrayList<MTBeacon>(); private List<MTBeacon> scan_devices_dis = new ArrayList<MTBeacon>(); private BaseAdapter list_adapter = new BaseAdapter() { @SuppressLint("InflateParams") @Override public View getView(int position, View convertView, ViewGroup parent) { if (null == convertView) { convertView = mInflater.inflate(R.layout.devicefmt, null); } TextView device_name_txt = (TextView) convertView .findViewById(R.id.device_name_txt); TextView device_rssi_txt = (TextView) convertView .findViewById(R.id.device_rssi_txt); TextView device_mac_txt = (TextView) convertView .findViewById(R.id.device_mac_txt); device_name_txt.setText(getItem(position).GetDevice().getName()); device_mac_txt.setText("Mac: " + getItem(position).GetDevice().getAddress()); device_rssi_txt.setText("Rssi: " + getItem(position).GetAveragerssi()); return convertView; } @Override public long getItemId(int position) { return position; } @Override public MTBeacon getItem(int position) { return scan_devices_dis.get(position); } @Override public int getCount() { return scan_devices_dis.size(); } }; private void initView() { mInflater = LayoutInflater.from(this); ble_listview = (ListView) findViewById(R.id.ble_listview); ble_listview.setAdapter(list_adapter); ble_listview.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // scan_flag = false; // Tools.mBLEService.stopscanBle(mLeScanCallback); Intent intent = new Intent(getApplicationContext(), ServiceActivity.class); intent.putExtra("device", scan_devices_dis.get(position) .GetDevice()); startActivity(intent); } }); } // 开始扫描 private int scan_timer_select = 0; private boolean scan_flag = true; private Handler search_timer = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); search_timer.sendEmptyMessageDelayed(0, 500); if (!scan_flag) { return; } if (!Tools.mBLEService.mBluetoothAdapter.isEnabled()) { return; } // 扫描时间调度 switch (scan_timer_select) { case 1: // 开始扫描 Tools.mBLEService.scanBle(mLeScanCallback); break; case 3: // 停止扫描(结算) Tools.mBLEService.stopscanBle(mLeScanCallback); // 停止扫描 for (int i = 0; i < scan_devices.size();) { // 防抖 if (scan_devices.get(i).CheckSearchcount() > 2) { scan_devices.remove(i); } else { i++; } } scan_devices_dis.clear(); // 显示出来 for (MTBeacon device : scan_devices) { scan_devices_dis.add(device); } list_adapter.notifyDataSetChanged(); break; default: break; } scan_timer_select = (scan_timer_select + 1) % 4; } }; private BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() { @Override public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) { int i = 0; // 检查是否是搜索过的设备,并且更新 for (i = 0; i < scan_devices.size(); i++) { if (0 == device.getAddress().compareTo( scan_devices.get(i).GetDevice().getAddress())) { scan_devices.get(i).ReflashInf(device, rssi, scanRecord); // 更新信息 return; } } // 增加新设备 scan_devices.add(new MTBeacon(device, rssi, scanRecord)); } }; private void scanBle() { search_timer.sendEmptyMessageDelayed(0, 500); } @Override protected void onPause() { super.onPause(); scan_flag = false; Tools.mBLEService.stopscanBle(mLeScanCallback); } @Override protected void onResume() { super.onResume(); scan_flag = true; } @Override protected void onDestroy() { super.onDestroy(); unbindService(connection); } }