# node-zemrpc **Repository Path**: zeyou-anhui/node-zemrpc ## Basic Information - **Project Name**: node-zemrpc - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2026-02-14 - **Last Updated**: 2026-02-14 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 🔬 node-zemrpc ![node-zemrpc banner](assets/banner.png) [![npm version](https://badge.fury.io/js/node-zemrpc.svg)](https://badge.fury.io/js/node-zemrpc) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Node.js Version](https://img.shields.io/node/v/node-zemrpc.svg)](https://nodejs.org) > 📡 Node.js remote control library for ZEPTOOLS scanning electron microscope (SEM) 一个用于控制 ZEPTOOLS 扫描电镜的 Node.js 远程控制库,支持设备发现、样品台控制、图像采集等功能。 --- ## ✨ Features - 🔍 **设备发现** - UDP广播自动发现局域网内的电镜设备 - 🎛️ **设备控制** - 高压、倍率、工作距离等参数设置 - 🎯 **样品台控制** - XY轴精确定位与移动 - 📷 **图像采集** - 支持多种分辨率,自动保存PNG/RAW格式 - 🔐 **权限管理** - BASIC/ADVANCED 两级命令权限 - 📦 **TypeScript** - 完整类型定义,优秀的IDE支持 --- ## 📦 Installation ```bash npm install node-zemrpc ``` --- ## 🚀 Quick Start ```typescript import { ZemApi, EnumCmdLevel } from 'node-zemrpc'; async function main() { const api = new ZemApi(); // 初始化 await api.init(); // 发现设备 const devices = await api.handshake(2000); console.log(`发现 ${devices.length} 台设备`); // 连接设备 await api.updateRemoteAddr(devices[0].addr, true); // 获取设备信息 console.log(`型号: ${api.model.model}`); console.log(`倍率: ${api.mag}`); console.log(`高压: ${api.hvInfo.accV / 1000} kV`); // 移动样品台(需要ADVANCED权限) api.setWorkMode(EnumCmdLevel.ADVANCED); await api.stageXyGotoClosed([100, 200], 500); // 拍摄图像 const image = await api.snap(); image.savePng('sem_image.png'); image.saveRaw('sem_image.raw'); image.saveMeta('sem_image_meta.json'); // 关闭连接 api.close(); } main().catch(console.error); ``` --- ## 📖 API Reference ### 🔌 连接管理 | Method | Description | | ------------------------------ | ------------------ | | `init()` | 初始化UDP Socket | | `handshake(timeout)` | 广播发现设备 | | `updateRemoteAddr(addr, sync)` | 连接并同步设备状态 | | `close()` | 关闭连接 | | `sync()` | 同步设备状态 | ### ⚙️ 设备控制 | Method | Description | | ------------------- | ------------ | | `setHv(kv, beamI)` | 设置加速电压 | | `setMag(mag)` | 设置倍率 | | `setWd(wd)` | 设置工作距离 | | `setBeamSize(size)` | 设置束斑大小 | ### 🎯 样品台控制 | Method | Description | | --------------------------------- | -------------- | | `stageXyGoto(pos)` | 移动到绝对位置 | | `stageXyGotoClosed(pos, timeout)` | 移动并等待完成 | | `stageXyRmove(offset)` | 相对移动 | | `getStagePos()` | 获取当前位置 | ### 📷 图像采集 | Method | Description | | -------------------------------------------- | ---------------- | | `snap()` | 拍摄图像 | | `snapRpc(width, height, pixelAvg, frameAvg)` | JSON-RPC方式拍摄 | | `runAutofocus()` | 运行自动对焦 | ### 🖼️ ZemImage ```typescript interface ZemImage { img: Buffer | null; // 16位灰度图像数据 meta: Map; // 元数据 width: number; // 宽度 height: number; // 高度 // Methods savePng(filepath, options); // 保存PNG (自动对比度) saveRaw(filepath); // 保存原始数据 saveMeta(filepath); // 保存元数据JSON } ``` --- ## 🔐 Command Levels | Level | Description | | ---------- | ---------------------------------------- | | `BASIC` | 只读操作,安全命令(获取状态、拍摄等) | | `ADVANCED` | 需要授权的操作(设置高压、移动样品台等) | ```typescript api.setWorkMode(EnumCmdLevel.ADVANCED); // ... 执行高级操作 ... api.setWorkMode(EnumCmdLevel.BASIC); ``` --- ## 📁 Project Structure ``` node-zemrpc/ ├── src/ │ ├── index.ts # 入口文件 │ ├── zem-api.ts # 高层API │ ├── zem-rpc-device.ts # 设备通信 │ ├── models.ts # 数据模型 │ ├── types.ts # 类型定义 │ ├── constants.ts # 常量配置 │ ├── utils.ts # 工具函数 │ └── conn/ │ ├── protocol.ts # 二进制协议 │ ├── rpc-protocol.ts # JSON-RPC协议 │ └── img-receiver.ts # TCP图像接收 ├── examples/ │ ├── demo.ts # 基础演示 │ ├── snap.ts # 图像采集 │ ├── snap-3x3.ts # 3x3网格扫描 │ └── cmd-level.ts # 权限演示 └── dist/ # 编译输出 ``` --- ## 🔧 Development ```bash # 安装依赖 npm install # 构建 npm run build # 运行示例 npm run example:demo npm run example:snap npm run example:snap-3x3 npm run example:cmd-level ``` --- ## 📋 Requirements - Node.js >= 18.0.0 - ZEPTOOLS 电镜设备(或虚拟电镜) - 局域网连接 --- ## 📄 License [MIT](LICENSE) --- ## 🙏 Acknowledgments - 基于 [pyzemrpc](https://github.com/your-repo/pyzemrpc) Python版本移植 - 支持 ZEPTOOLS ZEM系列扫描电镜 ---

Made with ❤️ for SEM researchers