kl-ins
v1.0.10
Published
上位机与PLC通信指令
Downloads
23
Readme
kl-ins
安装
npm install kl-ins
用法
const proxy = new PlcTcpProxy("PLC", "127.0.0.1", 3000);
proxy.connect();
// 发送同步指令
const ins = new HomeInstruction([1, 2, 3, 4]);
await proxy.sendInstruction(ins);
// 设置监听函数
proxy.setPlcReportDataHandler({
moduleNum: number,
instructionNum: number,
data: number[]
} => {
// 处理数据
});
指令集
- 轴控制
- EnumAxisInstruction(枚举有效轴号指令)
new EnumAxisInstruction();
- HomeInstruction(复位回零指令)
new HomeInstruction(axisList: number[]);
- JogStartInstruction(手动示教移动开始指令)
new JogStartInstruction(axisNum: number, speed: number, direction: number);
- JogStopInstruction(手动示教移动停止指令)
new JogStopInstruction(axisNum: number);
- MoveInstruction(运动指令)
new MoveInstruction(moveItemInfoList: [{
axisNum: number,
speed: number,
dest: number,
isRelative: boolean
}]
- GetPosInstruction(获取轴速与位置指令)
new GetPosInstruction(axisList: number[]);
IO 控制
周期性包
自定义指令
- 同步指令
import { Instruction, IsSync } from "kl-ins";
// 同步方法需要使用IsSync注解,并传入超时时长,单位为毫秒
@IsSync({ TIMEOUT: 2_000 })
class YourInstruction extends Instruction {
public static readonly NAME = "你的指令名称";
public static readonly MODULE_NUM = 1; // 模块号
public static readonly NUM = 1; // 指令号,同一模块指令号需保证唯一
protected getPayload(): number[] {
// 你需要实现这个方法,返回payload数组
return [];
}
}
- 异步指令
import { Instruction } from "kl-ins";
class YourInstruction extends Instruction {
public static readonly NAME = "你的指令名称";
public static readonly MODULE_NUM = 1; // 模块号
public static readonly NUM = 1; // 指令号,同一模块指令号需保证唯一
protected getPayload(): number[] {
// 你需要实现这个方法,返回payload数组
return [];
}
}