实训台接线:串口要选对。接线做成数据(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+
CI/CD / test (push) Canceled after 0s
CI/CD / deploy (push) Canceled after 0s

上课前逐个检查 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:
xuyueandClaude Opus 5.5 committed 2026-10-28 17:40:57 +08:00
1 parent 163e553de4
commit 46e0f40cce
35 files changed
+637 -98

No files matched your search

+49
View File
@@ -1,5 +1,7 @@
import { expect, test } from 'bun:test'
import { DEFAULT_WIRING, describePortProblem, portProblems } from '@iot/shared'
import { Board } from '../src/board'
import { sampleWiring } from '../src/samples'
test('滑块输入取整并限制在范围内,开关输入只接受布尔值', () => {
const board = new Board()
@@ -31,3 +33,50 @@ test('学生程序控制输出设备:LED 屏、4150 继电器、ZigBee 继电
expect(board.state.relays.every((on) => !on)).toBe(true)
expect(board.state.ledText).toBe('')
})
test('接线:记下程序打开的串口,指出打开错了的设备;复位不改接线,程序结束时串口关闭', () => {
const board = new Board()
board.applyDevice({ type: 'device', device: 'adam4017', action: 'open', data: 'COM2' })
board.applyDevice({ type: 'device', device: 'adam4150', action: 'open', data: 'com2' })
board.applyDevice({ type: 'device', device: 'led', action: 'open', data: '' })
expect(portProblems(board.state).map(describePortProblem)).toEqual([
'程序在 com2 上打开 ADAM-4150,它接在 COM3',
'程序没有选串口就打开了 LED 屏,它接在 COM5',
])
// 项目 7:4150 并到 COM2 的 485 总线上
expect(board.setWiring({ ...DEFAULT_WIRING, adam4150: 'COM2' })).toBe(true)
expect(board.setWiring({ ...DEFAULT_WIRING, adam4150: 'COM2' })).toBe(false)
expect(board.runnerInputs().wiring?.adam4150).toBe('COM2')
expect(portProblems(board.state).map((w) => w.device)).toEqual(['led'])
board.applyDevice({ type: 'device', device: 'led', action: 'close', data: null })
expect(portProblems(board.state)).toEqual([])
board.reset()
expect(board.state.wiring.adam4150).toBe('COM2')
expect(board.state.opened.adam4017).toBe('COM2')
board.programExited()
expect(Object.values(board.state.opened).every((port) => port === null)).toBe(true)
})
test('串口没打开(或已关闭)时程序还在读写设备:提示一次,打开后、程序结束时清除', () => {
const board = new Board()
expect(board.applyDevice({ type: 'device', device: 'adam4150', action: 'unopened', data: null })).toBe(true)
expect(board.applyDevice({ type: 'device', device: 'adam4150', action: 'unopened', data: null })).toBe(false)
expect(portProblems(board.state).map(describePortProblem)).toEqual(['ADAM-4150 的串口没有打开,程序却在读写它(它接在 COM3)'])
board.applyDevice({ type: 'device', device: 'adam4150', action: 'open', data: 'COM3' })
expect(portProblems(board.state)).toEqual([])
board.applyDevice({ type: 'device', device: 'adam4150', action: 'close', data: null })
board.applyDevice({ type: 'device', device: 'adam4150', action: 'unopened', data: null })
expect(portProblems(board.state).map((p) => p.device)).toEqual(['adam4150'])
board.programExited()
expect(portProblems(board.state)).toEqual([])
})
test('实验的接线:项目 7 把 4150 并到 COM2,其他实验和未知实验用默认接线', async () => {
expect(await sampleWiring('p7-t1-智慧教室')).toEqual({ ...DEFAULT_WIRING, adam4150: 'COM2' })
expect(await sampleWiring('p4-t3-报警灯')).toEqual(DEFAULT_WIRING)
expect(await sampleWiring('../p7-t1-智慧教室')).toEqual(DEFAULT_WIRING)
expect(await sampleWiring()).toEqual(DEFAULT_WIRING)
})
+21 -3
View File
@@ -78,7 +78,7 @@ describe('改坏的代码', () => {
const result = await grade(dir, await checksOf(id), id)
const realtime = result.results.find((r) => r.title === '能实时显示入侵数据')!
expect(realtime.passed).toBe(false)
expect(realtime.message).toBe('期望6 秒内 txt_even 的文字包含"发现入侵",实际是"正常"')
expect(realtime.message).toBe('期望 6 秒内 txt_even 的文字包含"发现入侵",实际是"正常"')
// 开关按钮的两项不受影响
expect(result.results.filter((r) => r.passed).length).toBe(2)
}, 60000)
@@ -135,7 +135,11 @@ describe('改坏的代码', () => {
`),
]
const result = await grade(dir, checks, id)
expect(result.results.at(-1)).toMatchObject({ passed: false, message: '期望窗体上的 lamp 点开关后灯亮,实际是灭的' })
// 这一项没有先打开串口,程序控制 4150 时串口没开,说明后面附上提示
expect(result.results.at(-1)).toMatchObject({
passed: false,
message: '期望窗体上的 lamp 点开关后灯亮,实际是灭的。注意:ADAM-4150 的串口没有打开,程序却在读写它(它接在 COM2)',
})
}, 60000)
test('关闭时忘了挂起线程', async () => {
@@ -163,7 +167,7 @@ describe('改坏的代码', () => {
})
const result = await grade(dir, await checksOf(id), id)
const fire = result.results.find((r) => r.title === '能自动推送火情到 LED 屏')!
expect(fire).toMatchObject({ passed: false, message: '期望8 秒内实训台 LED 屏显示"发现火情"(勾选"自动推送火情"后有火焰),实际什么也没显示' })
expect(fire).toMatchObject({ passed: false, message: '期望 8 秒内实训台 LED 屏显示"发现火情"(勾选"自动推送火情"后有火焰),实际什么也没显示' })
expect(result.results.filter((r) => !r.passed)).toHaveLength(1)
}, 60000)
@@ -189,6 +193,20 @@ describe('改坏的代码', () => {
const result = await grade(dir, await checksOf(id), id)
expect(result.results[0]).toMatchObject({ passed: false, message: '期望实训台的报警灯(ADAM-4150 DO0)打开,实际是关闭的' })
}, 60000)
test('串口写死成 COM2:4150 收不到命令,说明里指出接在 COM3', async () => {
const id = 'p4-t3-报警灯'
const dir = await prepare(id, 'port', {
file: 'Form1.cs',
from: 'DeviceCtrlHelper.adam4150Helper.Open(com_port.Text);',
to: 'DeviceCtrlHelper.adam4150Helper.Open("COM2");',
})
const result = await grade(dir, await checksOf(id), id)
expect(result.results[0]).toMatchObject({
passed: false,
message: '期望实训台的报警灯(ADAM-4150 DO0)打开,实际是关闭的。注意:程序在 COM2 上打开 ADAM-4150,它接在 COM3',
})
}, 60000)
})
describe('评分规则写错时指出位置', () => {
+28 -8
View File
@@ -160,7 +160,7 @@ test('项目2 任务1:选串口、打开、推送文字到 LED 屏', async ()
runner.send({ type: 'action', id: id('btn_Open'), action: 'click' })
runner.send({ type: 'action', id: id('btn_Send'), action: 'click' })
const device = await runner.waitFor('device', (m) => m.device === 'led')
const device = await runner.waitFor('device', (m) => m.device === 'led' && m.action === 'text')
expect(device.data).toBe('欢迎学习物联网')
const led = id('led')
const ledPatch = await runner.waitFor('patch', (m) => m.changes.some((c) => c.id === led && c.prop === 'LedText'))
@@ -219,10 +219,11 @@ test('项目3 任务1:单选按钮切换,事件顺序与 WinForms 一致,
const { runner, id } = await startSample('p3-t1-ZigBee路灯')
const lamp = id('lamp1')
// 串口没打开时控制无效:没有继电器动作,但界面上的灯照样会亮(学生能看出两者不一致)
// 串口没打开时控制无效:没有继电器动作(实训台提示串口没打开),但界面上的灯照样会亮(学生能看出两者不一致)
runner.send({ type: 'action', id: id('rb_Open'), action: 'click' })
await runner.waitFor('patch', (m) => m.changes.some((c) => c.id === lamp && c.prop === 'IsOn' && c.value === true))
expect(runner.messages.some((m) => m.type === 'device')).toBe(false)
await runner.waitFor('device', (m) => m.device === 'zigbee' && m.action === 'unopened')
expect(runner.messages.some((m) => m.type === 'device' && m.action === 'relay')).toBe(false)
runner.send({ type: 'action', id: id('com_port'), action: 'select', index: 2 })
runner.send({ type: 'action', id: id('btn_open'), action: 'click' })
@@ -232,7 +233,7 @@ test('项目3 任务1:单选按钮切换,事件顺序与 WinForms 一致,
runner.send({ type: 'action', id: id('rb_Close'), action: 'click' })
const devices: unknown[] = []
await relayOff
for (const m of runner.messages) if (m.type === 'device') devices.push(m.data)
for (const m of runner.messages) if (m.type === 'device' && m.action === 'relay') devices.push(m.data)
expect(devices).toEqual([
[1, 1],
[1, 0],
@@ -329,6 +330,27 @@ test('项目4 任务1:红外对射被遮挡时显示"发现入侵"', async ()
await even('发现入侵')
}, 30000)
test('串口要选对:4150 接在 COM3,在 COM2 上打开读不到传感器;换成项目 7 的接线(并到 COM2)就能读到', async () => {
const { runner, id } = await startSample('p4-t1-红外对射')
const even = (value: string) => runner.next('patch', (m) => m.changes.some((c) => c.id === id('txt_even') && c.value === value), 5000)
runner.send({ type: 'board', analog: ANALOG_DEFAULT, digital: [false, false, false, true] })
const opened = runner.next('device', (m) => m.device === 'adam4150' && m.action === 'open')
runner.send({ type: 'action', id: id('com_port'), action: 'select', index: 0 })
runner.send({ type: 'action', id: id('btn_open'), action: 'click' })
// 实训台据此提示"程序在 COM2 上打开 ADAM-4150";收不到回应,和真机一样读到的全是 false
expect((await opened).data).toBe('COM2')
await even('正常')
const intrusion = even('发现入侵')
runner.send({
type: 'board',
analog: ANALOG_DEFAULT,
digital: [false, false, false, true],
wiring: { adam4017: 'COM2', adam4150: 'COM2', zigbee: 'COM4', led: 'COM5' },
})
await intrusion
}, 30000)
test('项目4 任务2:打开摄像机显示画面,转动后画面变化,有人翻墙时画面变化,拍照保存到 Camera 文件夹', async () => {
const { runner, id } = await startSample('p4-t2-网络摄像机')
const pictures = () => runner.next('patch', (m) => m.changes.some((c) => c.id === id('pictureBox1') && c.prop === 'Image'), 5000)
@@ -367,7 +389,7 @@ test('项目4 任务2:打开摄像机显示画面,转动后画面变化,
test('项目4 任务3:开报警灯——实训台 DO0 动作,窗体上的报警灯亮', async () => {
const { runner, id } = await startSample('p4-t3-报警灯')
await openAdam4150(runner, id)
const relay = runner.next('device', (m) => m.device === 'adam4150')
const relay = runner.next('device', (m) => m.device === 'adam4150' && m.action === 'do')
const lamp = runner.next('patch', (m) => m.changes.some((c) => c.id === id('alarm1') && c.prop === 'IsOn' && c.value === true))
runner.send({ type: 'action', id: id('btn_alarmOpen'), action: 'click' })
expect((await relay).data).toEqual([0, 1])
@@ -730,9 +752,7 @@ test('禁用:分组框禁用后里面的控件 Enabled 读出 false、触发 E
const output = runner.messages.flatMap((m) => (m.type === 'console' ? [m.text] : [])).join('')
// 浏览器只收到分组框自己的 Enabled,子控件按父控件画成禁用
expect(findByName(form, 'button').props.Enabled).toBe(true)
expect(output).toBe(
'button changed=False\ngroup=False button=False off=False\nbutton changed=True\ngroup=True button=True off=False\nclick\n',
)
expect(output).toBe('button changed=False\ngroup=False button=False off=False\nbutton changed=True\ngroup=True button=True off=False\nclick\n')
}, 30000)
test('透明背景:文本框、窗体等设透明背景色和 WinForms 一样报错,标签、面板可以', async () => {