实训台接线:串口要选对。接线做成数据(BoardState.wiring),默认按教材布局图 COM2 ADAM-4017+、COM3 ADAM-4150、COM4 ZigBee 协调器、COM5 LED 屏,实验可在 meta.json 的 wiring 里改:项目 7 的书上代码在一个串口上打开两个模块,这三个实验把 4150 并到 COM2 的 485 总线上。选错串口时返回值照反编译的真机版 dll(4017 全 null、4150 全 false,4150 的 OnOff 和 LED 推送返回成功但设备不动作,ZigBee 返回 false);串口没打开时照教材仿真版。Open / Close / 没打开就读写报告给服务器,实训台最上方用红字提示("程序在 COM2 上打开 ADAM-4150,它接在 COM3""ADAM-4150 的串口没有打开,程序却在读写它"),评分不通过时也附上。只读接线展示:鼠标移到实训台设备上,标题栏写出线路,对应通道、模块、串口高亮;串口服务器按接线列出设备,程序打开的口亮绿点;程序里串口下拉框的灰字按当前接线。打开实验时浏览器发 experiment 消息换接线,老师看学生提交时按作业的实验接线(提交接口返回 sampleId)。"4017"统一写成 ADAM-4017+
上课前逐个检查 23 个实验后的修改:补上三处评分漏洞(项目 3 任务 1、项目 4 任务 3 的关闭和项目 7 任务 2 的熄灯,程序什么都不做也能通过);评分说明的空格;任务说明按实测补充(项目 2 任务 1–3、项目 3 任务 2、项目 4 任务 2、项目 7 任务 1–3、项目 8 任务 5)。使用说明、设计方案同步,设计方案记下以后可能扩展"物联网设备安装与调试"课 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
163e553de4
commit
46e0f40cce
35 files changed
+637
-98
No files matched your search
+57
-3
@@ -66,6 +66,55 @@ export interface BoardState {
|
||||
camera: { on: boolean; x: number; y: number }
|
||||
/** 虚拟时钟;null 表示真实时间 */
|
||||
clock: VirtualClock | null
|
||||
/** 接线:每台串口设备接在哪个串口,随实验而定(示例 meta.json 的 wiring) */
|
||||
wiring: Wiring
|
||||
/** 学生程序在哪个串口上打开了各设备(Open / OpenLedCom);没打开或已 Close 为 null,程序结束时清空 */
|
||||
opened: Record<PortDevice, string | null>
|
||||
/** 串口没打开(或已关闭)时程序还在读写的设备(读数据、控制继电器、推送文字);打开后、程序结束时清除 */
|
||||
usedUnopened: PortDevice[]
|
||||
}
|
||||
|
||||
/** 实训台上经串口服务器连到电脑的设备 */
|
||||
export type PortDevice = 'adam4017' | 'adam4150' | 'zigbee' | 'led'
|
||||
export const PORT_DEVICES: PortDevice[] = ['adam4017', 'adam4150', 'zigbee', 'led']
|
||||
export const PORT_DEVICE_NAMES: Record<PortDevice, string> = { adam4017: 'ADAM-4017+', adam4150: 'ADAM-4150', zigbee: 'ZigBee 协调器', led: 'LED 屏' }
|
||||
/** 串口服务器的四个口(电脑自带的 COM1 不接设备,GetPortNames 也不返回) */
|
||||
export const BOARD_PORTS = ['COM2', 'COM3', 'COM4', 'COM5']
|
||||
|
||||
export type Wiring = Record<PortDevice, string>
|
||||
|
||||
/**
|
||||
* 教材实训台布局图的接线:ADAM-4017+、ADAM-4150 各经一个 485/232 转换器接串口服务器,ZigBee 协调器、LED 屏直接接(项目 8 的 AppSet 也是这样)。
|
||||
* 485 是总线,两个模块地址不同(4150 为 1、4017+ 为 2),也可以并在同一个口上:项目 7 的书上代码就在一个串口上打开两个模块。
|
||||
*/
|
||||
export const DEFAULT_WIRING: Wiring = { adam4017: 'COM2', adam4150: 'COM3', zigbee: 'COM4', led: 'COM5' }
|
||||
|
||||
/**
|
||||
* 串口问题,设备因此没有反应(和真机一样不报错):opened 是程序打开的串口名(打开错了),null 表示串口没打开程序就在读写它。
|
||||
* Windows 的串口名不分大小写
|
||||
*/
|
||||
export interface PortProblem {
|
||||
device: PortDevice
|
||||
opened: string | null
|
||||
wired: string
|
||||
}
|
||||
|
||||
export function portProblems(state: Pick<BoardState, 'wiring' | 'opened' | 'usedUnopened'>): PortProblem[] {
|
||||
return PORT_DEVICES.flatMap((device): PortProblem[] => {
|
||||
const opened = state.opened[device]
|
||||
const wired = state.wiring[device]
|
||||
if (opened === null) return state.usedUnopened.includes(device) ? [{ device, opened, wired }] : []
|
||||
return opened.trim().toUpperCase() !== wired ? [{ device, opened, wired }] : []
|
||||
})
|
||||
}
|
||||
|
||||
/** 一句话说明串口问题,如"程序在 COM2 上打开 ADAM-4150,它接在 COM3" */
|
||||
export function describePortProblem(p: PortProblem) {
|
||||
const name = PORT_DEVICE_NAMES[p.device]
|
||||
// 名字以中文结尾时直接接"的"("LED 屏的串口"),以字母、数字结尾时空一格("ADAM-4150 的串口")
|
||||
const owner = /[\x00-\x7f]$/.test(name) ? `${name} 的` : `${name}的`
|
||||
if (p.opened === null) return `${owner}串口没有打开,程序却在读写它(它接在 ${p.wired})`
|
||||
return p.opened.trim() ? `程序在 ${p.opened.trim()} 上打开 ${name},它接在 ${p.wired}` : `程序没有选串口就打开了 ${name},它接在 ${p.wired}`
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,7 +166,10 @@ export type RunnerMessage =
|
||||
| { type: 'media'; id: string; action: 'play' | 'stop'; key?: string; name?: string }
|
||||
/** 学生程序用 Image.Save 保存了图片;path 相对程序所在目录,如 Camera/20241022_10 30 00.jpg */
|
||||
| { type: 'imageSaved'; path: string; image: string }
|
||||
/** 学生程序操作了实训台输出:led/text、adam4150/do、zigbee/relay、camera/on、camera/pan,data 见 DeviceCtrlHelper.cs、IPCameraHelper.cs */
|
||||
/**
|
||||
* 学生程序操作了实训台输出:led/text、adam4150/do、zigbee/relay、camera/on、camera/pan,data 见 DeviceCtrlHelper.cs、IPCameraHelper.cs;
|
||||
* 以及打开、关闭串口设备:adam4017/open(data 是串口名)、adam4017/close,串口没打开时程序还在读写:adam4017/unopened(每次打开后最多报一次),4150、zigbee、led 同样
|
||||
*/
|
||||
| { type: 'device'; device: string; action: string; data: unknown }
|
||||
| { type: 'console'; text: string }
|
||||
/** 学生程序没有处理的异常;file、line 是出错的那行学生代码(找得到时才有),网页上点击可以跳过去 */
|
||||
@@ -150,14 +202,16 @@ export type UserAction =
|
||||
export type RunnerInput =
|
||||
| ({ type: 'action'; id: string } & UserAction)
|
||||
| { type: 'reply'; requestId: number; result: unknown }
|
||||
/** 实训台传感器读数,按通道号排列(见 ANALOG_CHANNELS、DIGITAL_CHANNELS),以及虚拟时钟(不带时表示不变) */
|
||||
| { type: 'board'; analog: number[]; digital: boolean[]; clock?: VirtualClock | null }
|
||||
/** 实训台传感器读数,按通道号排列(见 ANALOG_CHANNELS、DIGITAL_CHANNELS),以及虚拟时钟、接线(不带时表示不变) */
|
||||
| { type: 'board'; analog: number[]; digital: boolean[]; clock?: VirtualClock | null; wiring?: Wiring }
|
||||
| { type: 'stop' }
|
||||
|
||||
/** 浏览器发给服务器的消息 */
|
||||
export type ClientMessage =
|
||||
/** sampleId:当前实验,第一次运行时自动建好实验预置的数据库(学生还没有这些库时) */
|
||||
| { type: 'run'; files: SourceFile[]; sampleId?: string }
|
||||
/** 打开了哪个实验:实训台换成这个实验的接线(没有 sampleId 时用默认接线) */
|
||||
| { type: 'experiment'; sampleId?: string }
|
||||
/** 调节实训台环境:拖动滑块、触发传感器 */
|
||||
/** clock:拨到某个时刻(time:yyyy-MM-ddTHH:mm:ss)、改倍速,或 null 恢复真实时间 */
|
||||
| { type: 'boardInput'; analog?: Partial<BoardState['analog']>; digital?: Partial<BoardState['digital']>; clock?: { time?: string; speed?: number } | null }
|
||||
|
||||
Reference in new issue
Block a user