Appearance
使用本地硬件
使用读卡器
注:使用读卡器,需要安装本地硬件服务
js
// 导入本地硬件包
import { Hardware, HardwareNames, HardwareResult } from 'jingjian-hardware'
const hardware: Hardware = Global.ioc.get<Hardware>(HardwareNames.key)
// 调用会员卡
const readCard = async () => {
let result: HardwareResult = await hardware.icCardReader.readCardAsync(ickey) // ickey不传则使用默认秘钥
console.log(result)
}
// 读取设置卡
const readConfig = async () => {
let result: HardwareResult = await hardware.icCardReader.readConfigAsync()
console.log(result)
}
// 写入设置卡
const writeConfig = async () => {
let result: HardwareResult = await hardware.icCardReader.writeConfigAsync(shopId, ickey, apikey, ssid, sspw, svrip, svrport)
console.log(result)
}打开远程控制
js
import { Hardware, HardwareNames, HardwareResult } from 'jingjian-hardware'
const hardware: Hardware = Global.ioc.get<Hardware>(HardwareNames.key)
const open = async () => {
await hardware.windows.openRemoteAideAsync()
}使用柜台售币机
出币
js
import { HardwareNames, HardwareResult } from 'jingjian-hardware'
const currentCoin = ref(0)
const outCoins = async () => {
let result: HardwareResult = await jingjian.hardware.coinMachine.outCoins(20, process, completed, error)
}
const process = coin => currentCoin = coin
const completed = coin => currentCoin = coin
const error = msg => console.log(msg)暂停
js
import { HardwareNames, HardwareResult } from 'jingjian-hardware'
const pause = async () => console.log(await jingjian.hardware.coinMachine.pause())继续
js
import { HardwareNames, HardwareResult } from 'jingjian-hardware'
const onContinue = async () => {
let result: HardwareResult = await jingjian.hardware.coinMachine.continue()
}清币
js
import { HardwareNames, HardwareResult } from 'jingjian-hardware'
const clearCoin = async () => {
let result: HardwareResult = await jingjian.hardware.coinMachine.clearCoin(process, completed, error)
}
const process = coin => currentCoin = coin
const completed = coin => currentCoin = coin
const error = msg => console.log(msg)是否连接
js
import { Hardware, HardwareNames, HardwareResult } from 'jingjian-hardware'
const clearCoin = async () => {
let result: HardwareResult = await jingjian.hardware.coinMachine.isLink()本地硬件二次开发
柜台硬件通信包括:打印机,读卡器,售币机等硬件设备。 客户端与本地framework程序JingJianCashierHardware进行通信。 JingJianCashierHardware对本地硬件进行管理。
项目结构
- JingJianCashierHardware:本地硬件主程序,提供命名管道通信和Http通信两种接口,并提供通用方法
- JingJianCashierHardware.CardReader.D3U:D3U型号的读卡器
- JingJianCashierHardware.CounterCoinMachine.V8:V8售币机
- JingJianCashierHardware.CounterCoinMachine.ZiRanYuan:自然源售币机
- JingJianCashierHardware.ReceiptPrinter.XP58:芯烨58打印机
- ......
新增设备
当新增一个设备时,可新增一个项目,并实现 IDevice 和 IDeviceProvider 接口。 IDevice:设备接口,会被注入到服务中,主程序收到的消息,将被转发到该设备。
C#
namespace JingJianCashierHardware.ReceiptPrinter.XP58
{
public class XP58ReceiptPrinter : DeviceBase
{
public override string DeviceName => "ReceiptPrinter"; // 设备类型名称
public override string DeviceModel => "XP58"; // 型号
}
}IDeviceProvider:设备提供者,提供该设备的创建方法,将被主程序自动搜索。
C#
namespace JingJianCashierHardware.ReceiptPrinter.XP58
{
/// <summary>
/// 芯烨58打印机
/// </summary>
public class XP58DeviceProvider : IDeviceProvider
{
public IDevice Create()
{
return new XP58ReceiptPrinter();
}
}
}