npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

node-zemrpc

v1.0.0

Published

Node.js remote control library for ZEPTOOLS scanning electron microscope (SEM)

Readme

🔬 node-zemrpc

node-zemrpc banner

npm version License: MIT Node.js Version

📡 Node.js remote control library for ZEPTOOLS scanning electron microscope (SEM)

一个用于控制 ZEPTOOLS 扫描电镜的 Node.js 远程控制库,支持设备发现、样品台控制、图像采集等功能。


✨ Features

  • 🔍 设备发现 - UDP广播自动发现局域网内的电镜设备
  • 🎛️ 设备控制 - 高压、倍率、工作距离等参数设置
  • 🎯 样品台控制 - XY轴精确定位与移动
  • 📷 图像采集 - 支持多种分辨率,自动保存PNG/RAW格式
  • 🔐 权限管理 - BASIC/ADVANCED 两级命令权限
  • 📦 TypeScript - 完整类型定义,优秀的IDE支持

📦 Installation

npm install node-zemrpc

🚀 Quick Start

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

interface ZemImage {
  img: Buffer | null;       // 16位灰度图像数据
  meta: Map<string, any>;   // 元数据
  width: number;            // 宽度
  height: number;           // 高度
  
  // Methods
  savePng(filepath, options);  // 保存PNG (自动对比度)
  saveRaw(filepath);           // 保存原始数据
  saveMeta(filepath);          // 保存元数据JSON
}

🔐 Command Levels

| Level | Description | | ---------- | ---------------------------------------- | | BASIC | 只读操作,安全命令(获取状态、拍摄等) | | ADVANCED | 需要授权的操作(设置高压、移动样品台等) |

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

# 安装依赖
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


🙏 Acknowledgments

  • 基于 pyzemrpc Python版本移植
  • 支持 ZEPTOOLS ZEM系列扫描电镜