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 🙏

© 2024 – Pkg Stats / Ryan Hefner

hc-electronic-label-controller

v0.1.21

Published

A Node.js project to control ST203 (AT703) pick-to-light devices

Downloads

165

Readme

ElectronicLabel

一个用于控制和管理 ST203 电子标签的 Node.js 包。提供了对 ST203 电子标签的基本操作,例如亮灯、灯光闪烁、数显、监听按钮事件等功能。

目录

安装

使用 npm 安装:

npm install hc-electronic-label-controller 

使用

初始化 ST203 控制器

import { ST203Controller } from 'hc-electronic-label-controller';

const HOST = '192.168.1.100';
const PORT = 4660;
const OPTIONS = {
  retryDelay: 5000, // 可选:socket初始重试间隔时间,默认值为 5s
  maxRetryDelay: 60000, // 可选:socket断连最大重试间隔时间,默认值为 1mins
  sendInterval: 100 // 可选:发送消息的时间间隔,默认值为0ms
  heartbeatInterval: 1000 * 120 // 可选:发送心跳的时间间隔,默认值为2 mins; 参数传0时关闭心跳
};

const controller = new ST203Controller(HOST, PORT, OPTIONS);

controller.connect().then(() => {
  console.log('Connected to ST203 controller');
}).catch((err) => {
  console.error('Failed to connect:', err);
});

亮灯

// 使指定地址的灯亮起
controller.turnOnLight(0x01).then(() => {
  console.log('Light turned on');
}).catch((err) => {
  console.error('Failed to turn on light:', err);
});

设置灯光颜色

// 设置指定地址的灯的颜色
controller.setColor(0x01, 'green').then(() => {
  console.log('Color set to green');
}).catch((err) => {
  console.error('Failed to set color:', err);
});

关闭灯光

// 关闭指定地址的灯
controller.turnOffLight(0x01).then(() => {
  console.log('Light turned off');
}).catch((err) => {
  console.error('Failed to turn off light:', err);
});

使灯光闪烁

// 使指定地址的灯闪烁
controller.blinkLight(0x01).then(() => {
  console.log('Light is blinking');
}).catch((err) => {
  console.error('Failed to blink light:', err);
});

停止灯光闪烁

// 停止指定地址的灯闪烁
controller.stopBlinkLight(0x01).then(() => {
  console.log('Stopped blinking light');
}).catch((err) => {
  console.error('Failed to stop blinking light:', err);
});

显示数字

// 在指定地址显示数字
controller.displayNumber(0x01, 123).then(() => {
  console.log('Number displayed');
}).catch((err) => {
  console.error('Failed to display number:', err);
});

清除显示

// 清除指定地址的显示
controller.clearDisplay(0x01).then(() => {
  console.log('Display cleared');
}).catch((err) => {
  console.error('Failed to clear display:', err);
});

停止所有 LED 数字显示闪烁

// 停止指定地址所有 LED 数字显示的闪烁
controller.stopAllNumBlinking(0x01).then(() => {
  console.log('Stopped all number blinking');
}).catch((err) => {
  console.error('Failed to stop all number blinking:', err);
});

监听按钮事件

// 在您的 ST203Controller 类中
import { utils } from 'hc-electronic-label-controller';

// 初始化 currentNumbers 变量用于存储每个地址的当前数值
let currentNumbers = {};

  controller.on('buttonPress', async (address, buttonCode, data) => {
    console.log(`Button pressed on address ${address} with code ${buttonCode}`);
  
    switch (buttonCode) {
      case 0x06: {
        const digits = data.slice(11, 14).map(digit => digit - 0x30);
        const confirmNumber = utils.digitsToNumber(digits);
        console.log(`Confirm Button pressed on tag ${address}, number: ${confirmNumber}`);
        break;
      }
      case 0x64: {
        // 子命令为0x64时,数据位1为43H “shortage button/down-count button” pressed, 为25H “function button/up-count button” pressed。
        const dataField1 = data[9];
        console.log(`Number Button pressed on tag ${address}: Data field 1 0x${dataField1.toString(16)}`);
        switch (dataField1) {
          case 0x25:
            currentNumbers[address] = utils.incrementNumber(currentNumbers[address]);
            await controller.displayNumber(address, currentNumbers[address]);
            break;
          case 0x43:
            currentNumbers[address] = utils.decrementNumber(currentNumbers[address]);
            await controller.displayNumber(address, currentNumbers[address]);
            break;
        }
        break;
      }
      default:
        console.log(`Button pressed on tag ${address}: Unknown button code ${buttonCode}`);
    }
  });

读取所有标签信息

// !未测试,不推荐使用
// 读取控制器下所有标签的信息
controller.readAllTagInfo().then(() => {
  console.log('Reading all tag info');
}).catch((err) => {
  console.error('Failed to read tag info:', err);
});

controller.on('tagsInfo', (tags) => {
  console.log('Tags Info:', tags);
});

关闭连接

// 关闭控制器的连接
controller.close();

广播地址, 心跳包

广播地址用于发送命令到所有连接的标签设备。通常广播地址为 0xFC

例如:

controller.turnOnLight(0xFC).then(() => {
  console.log('All lights turned on');
}).catch((err) => {
  console.error('Failed to turn on all lights:', err);
});

贡献

如果你有任何改进或建议,欢迎提交 pull request 或 issue。

许可证

MIT