uniapp 小程序低功耗蓝牙配网 ble配网 物联网

 1.获取蓝牙列表  bleList.vue

<template><view><button @touchstart="startSearch">获取蓝牙列表</button><scroll-view :scroll-top="scrollTop" scroll-y class="content-pop"><viewclass="bluetoothItem"v-for="(item, index) in bluetoohList":key="index"@click="openControl(item)"><view class="textItem">蓝牙:{{ item.name }}</view><view>{{ item.deviceId }}</view></view></scroll-view></view>
</template><script>
export default {data() {return {bluetoohList: [],};},onLoad: function (options) {this.startSearch();},methods: {// 连接蓝牙startSearch() {let that = this;that.$ble.openBluetoothAdapter((res) => {that.$ble.getBluetoothAdapterState((res) => {if (res.available) {if (res.discovering) {that.$ble.stopBluetoothDevicesDiscovery();} else {that.getBluetoothDevices();}that.checkPemission();} else {that.$tip.toast("本机蓝牙不可用");}});},(err) => {that.openSetting();});},openSetting() {let params = {title: "检测到您没打开蓝牙权限,是否去设置打开?",showCancel: true,};this.$tip.showModal(params, (res) => {if (res.confirm) {this.$ble.openSetting();}});},checkPemission() {//android 6.0以上需授权地理位置权限var that = this;const sys = uni.getSystemInfoSync();if (sys.platform == "ios") {that.getBluetoothDevices();} else if (sys.platform == "android") {console.log(app.getSystem().substring(app.getSystem().length - (app.getSystem().length - 8),app.getSystem().length - (app.getSystem().length - 8) + 1));if (app.globalData.getSystem().substring(app.globalData.getSystem().length -(app.globalData.getSystem().length - 8),app.globalData.getSystem().length -(app.globalData.getSystem().length - 8) +1) > 5) {uni.getSetting({success: (res) => {console.log(res);if (!res.authSetting["scope.userLocation"]) {uni.authorize({scope: "scope.userLocation",complete: (res) => {that.getBluetoothDevices();},});} else {that.getBluetoothDevices();}},});}}},//获取蓝牙设备信息getBluetoothDevices() {that.$tip.loading("蓝牙搜索中");this.$ble.getBluetoothDevices((res) => {this.bluetoohList = res;this.$tip.loaded();});},// 连接蓝牙 跳转到连接页面openControl(item) {let params = {list: this.bluetoohList,info: item,};this.$tip.redirectTo("/pages/ble/ble", params);},},
};
</script><style scoped>
.content-pop {width: 100vw;max-height: 55vh;padding: 0 30rpx;
}
.bluetoothItem {padding: 20rpx 0;font-weight: 400;font-size: 28rpx;border-bottom: 1rpx solid #f4f4f4;text-align: left;
}
.textItem {display: block;margin-bottom: 10rpx;
}
</style>

2.选择蓝牙进行连接  ble.vue

<script>
export default {data() {return {bluInfo: {},services: [],bleServiceId: "",serviceId: 0,writeCharacter: false,readCharacter: false,notifyCharacter: false,BLEInformation: {serveiceId: "",config_write_char_id: "",cmd_write_char_id: "",config_read_char_id: "",cmd_read_char_id: "",},};},onLoad(option) {// 接收页面传递的数据this.bluInfo = JSON.parse(decodeURIComponent(option.info));this.bluetooh(this.bluInfo.info.deviceId);},methods: {bluetooh(deviceId) {var that = this;that.$ble.stopBluetoothDevicesDiscovery();that.$ble.createBLEConnection(deviceId,(res) => {that.getSeviceId(deviceId);},(err) => {console.log(err);that.bluetoothFail();});},// 连接成功后保存连接状态getSeviceId(deviceId) {var that = this;that.$ble.getBLEDeviceServices(deviceId,(res) => {that.services = res.services;that.bleServiceId = res.services[0].uuid;this.BLEInformation.serveiceId = res.services[0].uuid;that.getCharacteristics(deviceId);},(err) => {console.log(err);that.bluetoothFail();});},getCharacteristics(deviceId) {var that = this;var list = that.services;var num = that.serviceId;var write = that.writeCharacter;var read = that.readCharacter;var notify = that.notifyCharacter;that.$ble.getBLEDeviceCharacteristics(deviceId,that.bleServiceId,(res) => {for (var i = 0; i < res.characteristics.length; ++i) {var properties = res.characteristics[i].properties;if (!notify) {if (properties.notify) {notify = true;}}if (!write) {if (properties.write) {this.BLEInformation.config_write_char_id =res.characteristics[2].uuid;this.BLEInformation.cmd_write_char_id =res.characteristics[0].uuid;write = true;}}if (!read) {if (properties.read) {this.BLEInformation.config_read_char_id =res.characteristics[3].uuid;this.BLEInformation.cmd_read_char_id =res.characteristics[1].uuid;read = true;}}}if (!write || !notify || !read) {num++;(that.writeCharacter = write),(that.readCharacter = read),(that.notifyCharacter = notify),(that.serviceId = num);if (num == list.length) {// console.log("找不到该读写的特征值")that.bluetoothFail();} else {that.getCharacteristics(deviceId);}} else {that.bluetoothSuccess(res);}},(err) => {console.log(err);that.bluetoothFail();});},// 蓝牙连接打印机bluetoothSuccess(res) {uni.setStorageSync("blefiInfo", this.BLEInformation);let params = {title: "连接成功",confirmText: "继续",showCancel: false,};this.$tip.showModal(params, (res) => {if (res.confirm) {// 蓝牙连接成功this.$tip.redirectTo("/pages/ble/bleWifi");}});},bluetoothFail() {// 蓝牙连接失败this.$tip.redirectTo("/pages/ble/bleFail");},},
};
</script><style scoped>
.zai-box {padding: 0;margin: 0;height: 100%;background-color: #fff;
}.container {padding: 30rpx;margin: 0;font-size: 28rpx;color: #20212b;background-color: #fff;text-align: left;font-weight: 400;
}image {width: 362rpx;height: 362rpx;margin-top: 30rpx;
}.textTitle {display: block;font-size: 36rpx;font-weight: bold;color: #20212b;display: block;margin-bottom: 30rpx;
}.textItem {display: block;font-size: 24rpx;font-weight: 400;color: #999999;line-height: 36rpx;
}
</style>

3. 蓝牙连接WiFi  bleWifi.vue

<template><view><text>{{ SSID }}</text><input type="text" placeholder="请输入密码" v-model="password" /><button @click="settiing">连接</button></view></template><script>import APToast from "@/util/APToast.js";export default {data() {return {SSID: "your SSID",password: "",connected: true,wifiCountDown: 0,wifiCountInterval: null, // 定时器blefiInfo: {},};},// 二级页面清除onUnload() {this.$ble.offBLEConnectionStateChange();this.clearIntervalWifi();},onLoad(options) {this.blefiInfo = uni.getStorageSync("blefiInfo");let sys = uni.getStorageSync("phoneInfo");if (sys.platform == "android") {// this.$ble.onBLEMTUChange((res) => {//   console.log(res, "androidMTU");// });// this.$ble.getBLEMTU(this.blefiInfo.deviceId, (res) => {//   console.log(res, "mtu");// });// 安卓要手动更改MTU值const mtu = 512;this.$ble.setBLEMTU(this.blefiInfo.deviceId,mtu,(res) => {console.log(res);},(err) => {console.log(err);});}this.$ble.getBLEDeviceServices(this.blefiInfo.deviceId, (res) => {this.$ble.getBLEDeviceCharacteristics(this.blefiInfo.deviceId,this.blefiInfo.serveiceId,(res) => {this.$ble.notifyBLECharacteristicValueChange(true,this.blefiInfo.deviceId,this.blefiInfo.serveiceId,this.blefiInfo.readCharId,(res) => {console.log("启用notify成功");});});});this.$ble.onBLEConnectionStateChange((res) => {this.connected = res.connected;if (!res.connected) {this.$tip.loaded();// 蓝牙连接失败,跳转到失败页面this.$tip.redirectTo("/pages/ble/bleFail");}});// 接收配网打印机回传的数据this.$ble.onBLECharacteristicValueChange((res) => {if (!res || res.value.byteLength == 0) return;this.clearIntervalWifi();this.$tip.loaded();let num = new Int32Array(res.value)[0];console.log(num, "NUM");// 失败原因let tip = APToast.find((item) => item.id == num);if (num == 0) {// 连接wifi成功this.$tip.redirectTo("/pages/ble/WifiSuccess");} else {// 连接WiFi失败this.$tip.redirectTo("/pages/ble/WifiFile",tip);}});},methods: {settiing() {this.startSMSTimer("60");this.$tip.loading("连接中");if (this.connected) {this.sendWifi();} else {this.$tip.loaded();// 蓝牙连接失败,跳转到失败页面this.$tip.redirectTo("/pages/ble/bleFail");}},// 转UTF-8sendWifi() {let msg = {event: "network",data: { ssid: this.SSID, password: this.password, authmode: 4 },};let buffer = this.stringToUint8Array(JSON.stringify(msg));this.bleSendWifi(buffer);},// json字符串数据转Uint8ArraystringToUint8Array(str) {// 方法一// var arr = [];// for (var i = 0, j = str.length; i < j; ++i) {//   arr.push(str.charCodeAt(i));// }// var tmpUint8Array = new Uint8Array(arr);// return tmpUint8Array.buffer;// 方法二let buffer = new ArrayBuffer(str.length);let dataView = new DataView(buffer);for (var i = 0; i < str.length; i++) {dataView.setUint8(i, str.charCodeAt(i));}return buffer;},bleSendWifi(payload) {if (this.connected) {this.$ble.writeBLECharacteristicValueOnce(this.blefiInfo.deviceId,this.blefiInfo.serveiceId,this.blefiInfo.writecharId,payload);if (this.blefiInfo.readCharId) {this.$ble.readBLECharacteristicValue(this.blefiInfo.deviceId,this.blefiInfo.serveiceId,this.blefiInfo.readCharId);}}},startSMSTimer(val) {this.wifiCountDown = val;this.wifiCountInterval = setInterval(() => {this.wifiCountDown--;// console.log(this.wifiCountDown);if (this.wifiCountDown <= 0) {clearInterval(this.wifiCountInterval);this.wifiCountInterval = null;this.$tip.loaded();// 连接WiFi失败this.$tip.redirectTo("/pages/ble/WifiFile");}}, 1000);},clearIntervalWifi() {this.wifiCountDown = 0;if (this.wifiCountInterval) {clearInterval(this.wifiCountInterval);this.wifiCountInterval = null;}},},};</script>

4. 手机连接蓝牙失败、蓝牙连接WiFi成功/失败(关闭蓝牙连接)

<script>
export default {onLoad() {// 使用完成后在合适的时机断开连接和关闭蓝牙适配器this.$ble.closeBLEConnection(this.deviceId);this.$ble.closeBluetoothAdapter();},
};
</script>

5.ble.js

class ble {openBluetoothAdapter(success, failure) {uni.openBluetoothAdapter({success: (res) => {success(res);},fail: (err) => {failure(err);},});}getBluetoothAdapterState(success) {uni.getBluetoothAdapterState({success: (res) => {success(res);},});}//停止搜寻附近的蓝牙外围设备stopBluetoothDevicesDiscovery() {uni.stopBluetoothDevicesDiscovery();}//获取蓝牙设备信息getBluetoothDevices(success) {// 开始搜寻附近的蓝牙外围设备uni.startBluetoothDevicesDiscovery({success: (res) => {setTimeout(() => {// 获取搜索到的设备信息uni.getBluetoothDevices({success: (res) => {let bluetoohList = [];var num = 0;for (var i = 0; i < res.devices.length; ++i) {if (res.devices[i].name != "未知设备") {bluetoohList[num] = res.devices[i];num++;}}this.stopBluetoothDevicesDiscovery();success(bluetoohList);},});}, 5000);// that.onBluetoothDeviceFound();},});}openSetting() {uni.openSetting({//opensetting是调起设置页面的success: (res) => {if (res.authSetting == true) {//判断res.authsetting的值是true还是falseuni.openBluetoothAdapter();}},});}//断开与低功耗蓝牙设备的连接closeBLEConnection(deviceId) {uni.closeBLEConnection({deviceId: deviceId,});}offBLEConnectionStateChange() {wx.offBLEConnectionStateChange();}//连接低功耗蓝牙设备createBLEConnection(deviceId, success, failure) {uni.createBLEConnection({deviceId: deviceId,success: (res) => {success(res);},fail: (err) => {failure(err);},});}//获取蓝牙设备所有服务getBLEDeviceServices(deviceId, success, failure) {wx.getBLEDeviceServices({deviceId: deviceId,success: (res) => {success(res);},fail(err) {failure(err);},});}//获取蓝牙设备某个服务中所有特征值getBLEDeviceCharacteristics(deviceId, serviceId, success, failure) {wx.getBLEDeviceCharacteristics({deviceId: deviceId,serviceId: serviceId,success: (res) => {success(res);},fail(err) {failure(err);},});}notifyBLECharacteristicValueChange(state,deviceId,serviceId,characteristicId,success) {wx.notifyBLECharacteristicValueChange({state: state,deviceId: deviceId,serviceId: serviceId,characteristicId: characteristicId,success: function (res) {success(res);},});}onBLEConnectionStateChange(success) {wx.onBLEConnectionStateChange((res) => {success(res);});}// 接收配网打印机回传的数据onBLECharacteristicValueChange(success) {wx.onBLECharacteristicValueChange((res) => {success(res);});}//关闭蓝牙模块closeBluetoothAdapter() {wx.closeBluetoothAdapter();}// 不分包写入蓝牙writeBLECharacteristicValueOnce(deviceId,serviceId,characteristicId,value) {wx.writeBLECharacteristicValue({deviceId: deviceId,serviceId: serviceId,characteristicId: characteristicId,value: value,});}readBLECharacteristicValue(deviceId, serviceId, characteristicId) {wx.readBLECharacteristicValue({deviceId: deviceId,serviceId: serviceId,characteristicId: characteristicId,});}getBLEMTU(deviceId, success) {wx.getBLEMTU({deviceId: deviceId,writeType: "write",success(res) {success(res.mtu);},});}onBLEMTUChange(success) {wx.onBLEMTUChange(function (res) {success(res.mtu);});}setBLEMTU(deviceId, mtu, success, failure) {wx.setBLEMTU({deviceId: deviceId,mtu: mtu,success: (res) => {success(res);},fail: (res) => {failure(res);},});}
}
const bleDevice = new ble();
export default bleDevice;

6.APToast.js

const message = [{id:0,type:"WIFI_REASON_SUCCESS",message:"打印机连接成功"},{id:2,type:"WIFI_REASON_AUTH_EXPIRE",message:"身份验证超时"},{id:3,type:"WIFI_REASON_AUTH_LEAVE",message:"连接中断"},{id:8,type:"WIFI_REASON_ASSOC_LEAVE",message:"连接中断"},{id:15,type:"WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT",message:"密码错误"},{id:201,type:"WIFI_REASON_NO_AP_FOUND",message:"未找到可用的网络"},{id:202,type:"WIFI_REASON_AUTH_FAIL",message:"密码错误或身份验证超时"},{id:203,type:"WIFI_REASON_ASSOC_FAIL",message:"设备无法与WiFi成功关联"},{id:204,type:"WIFI_REASON_HANDSHAKE_TIMEOUT",message:"密码错误"},{id:205,type:"WIFI_REASON_CONNECTION_FAIL",message:"连接失败"}, 
]export default message;

7.tip.js

export default class Tips { /*** 弹出提示框*/static success(title, duration = 1000) {setTimeout(() => {uni.showToast({title: title,icon: "success",mask: true,duration: duration,});}, 300);if (duration > 0) {return new Promise((resolve, reject) => {setTimeout(() => {resolve();}, duration);});}}/*** 弹出加载提示*/static loading(title = "加载中") {if (Tips.isLoading) {return;}Tips.isLoading = true;uni.showLoading({title: title,mask: true,});}/*** 加载完毕*/static loaded() {if (Tips.isLoading) {Tips.isLoading = false;uni.hideLoading();}}/*** 关闭当前页面,跳转到新页面*/static redirectTo(urls, item) {uni.redirectTo({url: item? urls + "?info=" + encodeURIComponent(JSON.stringify(item)): urls, //  JSON.parse(decodeURIComponent(option.info));});}/*** 弹出确认窗口*/static showModal(val, success) {uni.showModal({title: val.title ? val.title : "",content: val.content ? val.content : "",showCancel: val.showCancel,confirmText: val.confirmText ? val.confirmText : "确定",cancelText: val.cancelText ? val.cancelText : "取消",cancelColor: "#999999", //取消按钮颜色confirmColor: "#00A0E9", //确定按钮颜色success: (res) => {success(res);},});}
}/*** 静态变量,是否加载中*/
Tips.isLoading = false;

8.main.js

import ble from "./common/util/ble.js";
import tip from "./common/util/tip.js";// ble
Vue.prototype.$ble = ble;
// tip
Vue.prototype.$tip = tip;

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/12745.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

java多线程——线程池

概述 线程池是管理java线程生命周期的工具 降低资源消耗。通过池化技术能够重复利用已创建的线程&#xff0c;降低线程频繁创建和销毁造成的资源消耗提高线程的可管理性。无需程序员手动销毁线程&#xff0c;控制线程创建的数量&#xff0c;避免无限制的创建影响系统稳定性 …

找不到kotlin.Pair的类文件

需要添加kotlin的依赖&#xff1a; implementation "org.jetbrains.kotlin:kotlin-stdlib:1.8.22"

OpenHarmony上移植memtester

1. 下载源码&#xff1a; wget https://pyropus.ca./software/memtester/old-versions/memtester-4.6.0.tar.gz 2. 解压并指定交叉编译方式 解压 tar -xvf memtester-4.6.0.tar.gz 修改conf-cc和conf-ld&#xff0c;指定交叉编译方式 conf-cc conf-ld 3. 编译 直接运行m…

Ubuntu安装ZLMediaKit

方式一 1、安装vcpkg 在Ubuntu上安装vcpkg的步骤如下&#xff1a; 安装必要的依赖&#xff1a; 首先&#xff0c;你可能需要安装cmake和ninja-build。你可以使用apt包管理器来安装它们&#xff1a; bash复制代码sudo apt install cmake ninja-build下载vcpkg源码&#xff1a;…

后端开发面经系列 -- 阿里C++二面面经

阿里C二面面经 公众号&#xff1a;阿Q技术站 来源&#xff1a;https://www.nowcoder.com/feed/main/detail/fc4a48403b534aafa6a6bce14b542c4e?sourceSSRsearch 1、智能指针&#xff1f; std::shared_ptr&#xff1a; 原理&#xff1a;std::shared_ptr是基于引用计数的智能指…

Stable Diffusion入门使用技巧及个人实例分享--大模型及lora篇

大家好&#xff0c;近期使用Stable Diffusion比较多&#xff0c;积累整理了一些内容&#xff0c;得空分享给大家。如果你近期正好在关注AI绘画领域&#xff0c;可以看看哦。 本文比较适合已经解决了安装问题&#xff0c;&#xff08;没有安装的在文末领取&#xff09; 在寻找合…

【RAG】Linux系统下ppt转pptx,读取解析pptx文本数据

前情提要 检索增强生成&#xff08;RAG&#xff09;技术&#xff0c;作为 AI 领域的尖端技术&#xff0c;能够提供可靠且最新的外部知识&#xff0c;极大地便利了各种任务。在 AI 内容生成的浪潮中&#xff0c;RAG 通过其强大的检索能力为生成式 AI 提供了额外的知识&#xff…

vue3 动态加载页面

首先&#xff0c;通过下面代码告诉编译器要编译哪些页面 static modules import.meta.glob(./views/**/*.vue);然后动态加载函数这样写&#xff1a; static asyncLoadView (path: string) > {return defineAsyncComponent({loader: <any>Global.modules[./views/${…

Redis的跳表:高效实现有序集合

在 Redis 中&#xff0c;跳表&#xff08;Skip List&#xff09;是一种常用的数据结构&#xff0c;用于实现有序集合&#xff08;Sorted Set&#xff09;。跳表是一种基于链表的数据结构&#xff0c;具有快速的查找、插入和删除操作&#xff0c;适用于有序集合的实现。 本文将…

分布式搜索——ElasticSeach简介

一般都用数据库存储数据&#xff0c;然后对数据库进行查询获取数据&#xff0c;但是当数据量很大时&#xff0c;查询效率就会很慢&#xff08;具体下面会讲到&#xff09;&#xff0c;所以这种情况下就会使用到ElasticSeach ElasticSeach的基本介绍 ElasticSeach是一 款非常强…

2024重庆高等教育博览会|2024重庆高教展|全国高等教育博览会

2024重庆高等教育博览会|2024重庆高教展|全国高等教育博览会 第62届全国高等教育博览会&#xff08;2024.秋季重庆&#xff09; 时间&#xff1a;2024年11月15-17日 地点&#xff1a;重庆国际博览中心 组织机构 主办单位&#xff1a;中国高等教育学会 承办单位&#xff1a;国药…

杰发科技AC7801——ADC之Bandgap和内部温度计算

0. 参考 电流模架构Bandgap设计与仿真 bandgap的理解&#xff08;内部带隙电压基准&#xff09; ​ ​ 虽然看不懂这些公式&#xff0c;但是比较重要的一句应该是这个&#xff1a;因为传统带隙基准的输出值为1.2V ​ 1. 使用 参考示例代码。 40002000是falsh控制器寄…

NXP RT1176(一)——二级BootLoader开发(安全引导加载程序SBL)

目录 1. 开发环境 2. 二级BOOT的功能 3. 步骤 3.1 配置源码 3.2 构建项目 3.2.1 MDK 3.2.2 IAR&#xff08;IAR也编译一下工程看看&#xff0c;这样两个平台都可以支持了&#xff09; 单核M7的开发&#xff01;&#xff01; 1. 开发环境 本文Windows下开发&#xff1a;…

【无标题】vo dto

在Java中&#xff0c;VO、PO、DTO都是常用的数据对象模型。 VO&#xff08;Value Object&#xff09;是值对象&#xff0c;通常用于表示一个业务实体或者页面展示的内容。VO通常包含了多个属性&#xff0c;并且这些属性的类型和名称与业务相关。VO并不一定与数据库中的表结构相…

MHD、MQA、GQA注意力机制详解

MHD、MQA、GQA注意力机制详解 注意力机制详解及代码前言&#xff1a;MHAMQAGQA 注意力机制详解及代码 前言&#xff1a; 自回归解码器推理是 Transformer 模型的 一个严重瓶颈&#xff0c;因为在每个解码步骤中加 载解码器权重以及所有注意键和值会产生 内存带宽开销 下图为三…

巩固学习8

在 Pandas 中&#xff0c;sep参数用于指定数据中字段之间的分隔符。常见的参数包括&#xff1a; 逗号&#xff1a;,&#xff0c;常用于CSV文件。 制表符&#xff1a;\t&#xff0c;常用于TSV文件。 空格&#xff1a;’ &#xff0c;用于空格分隔的数据。 分号&#xff1a;;&…

【合成孔径雷达】合成孔径雷达的多视角理解和时/频成像算法的统一解释

文章目录 一、什么是雷达成像&#xff08;1&#xff09;主要的遥感探测手段&#xff1a;光学、红外和雷达&#xff08;2&#xff09;从数学的角度&#xff1a;雷达成像主要研究什么&#xff1f;数据采集&#xff1a; y T x n yTxn yTxn信息提取&#xff1a; y − > x ? y…

编译错误:stray ‘\357’ in program的解决方法

目录 把报错文件更换编码格式&#xff0c;我试的utf-8 bom编码就可以了&#xff0c;可以多换几种试试。 网友的另一种案例&#xff1a; 编译错误&#xff1a;stray ‘\357’ in program的解决方法 把报错文件更换编码格式&#xff0c;我试的utf-8 bom编码就可以了&#xff0c…

LabVIEW做仪器测试不知道是否适用

LabVIEW&#xff08;Laboratory Virtual Instrument Engineering Workbench&#xff09;是一个用于系统工程和测量系统的图形编程平台&#xff0c;由National Instruments开发。它非常适用于仪器控制、数据采集、信号处理以及自动化测试与测量系统的开发。如果您的工作涉及到这…

如何同步管理1000个设备的VLAN数据?

什么是VLAN&#xff1f; VLAN&#xff0c;也就是虚拟局域网&#xff0c;是通过为子网提供数据链路连接来抽象出局域网的概念。在企业网中&#xff0c;一个企业级交换机一般是24口或者是48口&#xff0c;连接这些接口的终端在物理上形成一个广播域。广播域过大&#xff0c;就会导…