From 868daf94f29ce1ffdd799a68c07bb668cd373bcd Mon Sep 17 00:00:00 2001 From: HP\李良庭 <liliangting@lanpucloud.cn:1111> Date: 星期二, 08 七月 2025 11:49:03 +0800 Subject: [PATCH] 提交分辨率自适应版本V3.1.0.1500 --- src/lib/ActuatorLib.~pas | 191 +++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 191 insertions(+), 0 deletions(-) diff --git a/src/lib/ActuatorLib.~pas b/src/lib/ActuatorLib.~pas new file mode 100644 index 0000000..5f8d6ce --- /dev/null +++ b/src/lib/ActuatorLib.~pas @@ -0,0 +1,191 @@ +{------------------------------------------------------------------------------} +{项目名称:actuatorlib动态库 } +{单元名称:actuatorlib.pas } +{版本版次:3.2.1 } +{功能描述:基于粮食水分仪Actuator驱动封装的 Dll接口通讯库 } +{建立日期:2023-10-27 } +{修改修改:2025-01-20 } +{版权所有:李良庭 liangtingli@outlook.com } +{------------------------------------------------------------------------------} + +unit ActuatorLib; + +interface + +//静态声明 lib库 +const + actuator_dll = 'core\Actuator.dll'; {自定义库} + +//PLC指令代码 +const + PLC_READY_GRAIN = $01; //粮种准备命令代码(粮种已修改) + PLC_READY_FINISH = $02; //返回准备完成 + PLC_DETECT_START = $03; //检测启动命令 + PLC_DETECT_FINISH = $04; //返回检测完毕 + PLC_DEVICE_WR_RESET = $FE; //设备水分仪复位命令 + PLC_DEVICE_WR_FAULT = $FF; //返回水分仪故障代码 + +//WR水分仪指令代码 +const + WR_READY = $01; //水分仪准备指令 + WR_DETECT = $02; //水分仪检测指令 + WR_VERIFY = $03; //水分仪校验指令 + WR_RESET = $04; //水分仪复位指令 + WR_GOODS = $05; //粮种变更指令 + + WR_VALV01 = $07; //上阀门开 + WR_VALV02 = $08; //上阀门关 + WR_VALV03 = $09; //下阀门开 + WR_VALV04 = $0A; //下阀门关 + WR_VALV05 = $0B; //双阀门开 + WR_VALV06 = $0C; //双阀门关 + WR_VIBRATE_01 = $0D; //振动开 + WR_VIBRATE_02 = $0E; //振动关 + + + {定义 Dll函数调用申明} + //创建初始化客户PLC设备句柄ctx + //strIp: IP地址 + //nPort: 网络端口 + //ACTUATOR_API void* CreatePlcDevice(const char* strIp, int nPort); + function CreatePlcDevice(strIp:PChar; nPort:Integer):Pointer; stdcall; external actuator_dll; + + //创建水分仪句柄ctx + //szSerialPort: 串口名 + //baud: 波特率 + //parity: 校验类型 + //data_bit: 数据位 + //stop_bit: 停止位 + //ACTUATOR_API void* CreateWrDevice(const char* szSerialPort, int baud, char parity, int data_bit, int stop_bit); + function CreateWrDevice(szSerialPort:PChar; baud:Integer; parity:Char; data_bit:Integer; stop_bit:Integer):Pointer; stdcall; external actuator_dll; + + //连接客户设备或水分仪装置 + //ctxDev : 设备句柄 + //返回值:小于0 表示 错误, + //ACTUATOR_API int ConnectDevice(void* ctxDev); + function ConnectDevice(ctxDev:Pointer):Integer; stdcall; external actuator_dll; + + //获取状态或粮种更改信息 + //ctxDev : 设备句柄 + //nState :状态字,如下状态不会重复 + // 0x01: 粮种已修改 + // 0x03: 开始测试 + // 0xFE: 复位命令,优先级最高 + // 其他: 为写入状态 + //nGoodType: 粮种编号 + // 0x01: 小麦, + // 0x02: 水稻 + // 0x03: 黄豆 + // 0x04: 玉米 + //返回值:从入参返回 状态字、粮种编号、执行结果(小于0--错误) + //ACTUATOR_API int ReadState(void* ctxDev, unsigned short* nState, unsigned short* nGrainType); + function ReadState(ctxDev:Pointer; nState:PWord; nGrainType:PWord):Integer; stdcall; external actuator_dll; + + //写回状态 + //ctxDev : 设备句柄 + //nState :状态字,如下状态不会重复 + // 0x02: 准备已完成 + // 0x04: 检测完成 + // 0xFF: 水分仪故障 + //返回值:小于0 表示 错误, + //ACTUATOR_API int WriteState(void* ctxDev, unsigned short nState); + function ResponseState(ctxDev:Pointer; nState:Word):Integer; stdcall; external actuator_dll; + + //回传检测数据 + //ctxDev : 设备句柄 + //nDatas :数组,数据顺序如下 + // 粮种编码 + // 含水率, 取整 = 原值*100 + // 容重比, 取整 = 原值*100 + //nSize : 数据个数 + //返回值:小于0 表示 错误, + //ACTUATOR_API int UploadData(void* ctxDev, unsigned short* nDatas, unsigned short nSize = 3); + function UploadData(ctxDev:Pointer; nDatas:PWord; nSize:Word=3):Integer; stdcall; external actuator_dll; + + //下发命令信息 + //ctxDev : 设备句柄 + //nCmdType :命令字,如下描述 + // 0x01: 粮种已修改 + // 0x02: 开始测试 + // 0x03: 校准命令,即为标定页面检测按钮命令, + //nGoodType: 粮种编号 + // 0x01: 小麦, + // 0x02: 水稻 + // 0x03: 黄豆 + // 0x04: 玉米 + // 当nCmdType 为0x02,0x03时,不用考虑粮种编号 + // nResponseSeconds: 响应时间,以秒计算 + // nResponseUSeconds: 响应时间,以微妙计算,若小于秒,全部用微妙表示。 + //返回值:小于0 表示 错误, + //ACTUATOR_API int SendCommands(void* ctxDev, unsigned short nCmdType, unsigned short nGrainType = 0, unsigned int nResponseSeconds = 0, unsigned int nResponseUSeconds = 500000); + function SendCommands(ctxDev:Pointer; nCmdType:Word; nGrainType:Word=0; nResponseSeconds:Integer=20; nResponseUSeconds:Integer=0):Integer; stdcall; external actuator_dll; + + //复位命令 + //ctxDev : 设备句柄指针 + //返回值:无, + //ACTUATOR_API int __stdcall ResetCommand(void* ctxDev); + function ResetCommand(ctxDev:Pointer):Integer;stdcall; external actuator_dll; + + //下发参数 + //ctxDev : 设备句柄 + //nStartFreq :起始频率 + //nStopFreq : 终止频率 + //nStepFreq : 步长 + //nDecayCode :衰减码 + //nAscValid : ASC 内部/外部有效, 取值为 0:内部有效, 1:外部有效 + //返回值:小于0 表示 错误, + //ACTUATOR_API int WriteParams(void* ctxDev, unsigned short nStartFreq, unsigned short nStopFreq, + // unsigned short nStepFreq, unsigned short nDecayCode, unsigned short nAscValid); + function WriteParams(ctxDev:Pointer; nStartFreq,nStopFreq,nStepFreq,nDecayCode,nAscValid:Word):Integer; stdcall; external actuator_dll; + + //读取检测信息 + //ctxDev : 设备句柄 + //nDatas :数组,数据顺序如下 + // 电压值 + // 重量 /100 + // 温度 /100 + // 湿度 /100 + // nSize : 读取4个寄存器 + //返回值:小于0 表示 错误, + //ACTUATOR_API int ReadDatas(void* ctxDev, unsigned short* nDatas, unsigned short nSize = 4); + function ReadDatas(ctxDev:Pointer; nDatas:PWord; nSize:Word=4):Integer; stdcall; external actuator_dll; + + //读取扫频值,其实为电平值, + //ctxDev : 设备句柄 + //nVcc :电平值指针 + //返回值:小于0 表示 错误, + //ACTUATOR_API int ReadVcc(void* ctxDev, unsigned short* nVcc); + function ReadVcc(ctxDev:Pointer; nVcc:PWord):Integer; stdcall; external actuator_dll; + function ReadWeight(ctxDev:Pointer; nWg:PWord):Integer; stdcall; external actuator_dll; + function CalcValue(nDValue:Word; Coef0,Coef1,Coef2,Coef3,Coef4:double):double; stdcall; external actuator_dll; + + //销毁水分仪或PLC设备 + //ctxDev : 设备句柄指针 + //返回值:小于0 表示 错误, + //ACTUATOR_API int DestroyDevice(void* ctxDev); + function DestroyDevice(ctxDev:Pointer):Integer; stdcall; external actuator_dll; + + //断开水分仪或PLC设备连接 + //ctxDev : 设备句柄指针 + //返回值:小于0 表示 错误, + //ACTUATOR_API int __stdcall Disconnect(void* ctxDev) + function Disconnect(ctxDev:Pointer):Integer; stdcall; external actuator_dll; + + + //算法函数 + //x 为测量值 + //y 为实际值 + //n 为拟合次数 + //nSampleNumber 样本数量 + //返回值:小于0 表示 错误, + //ACTUATOR_API int Linearize(float x[], float y[], double Coefficient[], const int n = 2, const int nSampleNumber = 5); + function Linearize(x,y:PSingle; Coefficient:PDouble; n:integer=2; nSampleNumber:integer=5):Integer; stdcall; external actuator_dll; + //ACTUATOR_API int __stdcall PolyNomialFit(double x[], double y[], double Coefficient[], const int nDegree = 3, const int nSampleNumber = 5); + function PolyNomialFit(x,y:PDouble; Coefficient:PDouble; n:integer=2; nSampleNumber:integer=5):Integer; stdcall; external actuator_dll; + + //读固件版本号 + function ReadVersion(ctxDev:Pointer; Version:PWord; nSize:Word=2):Integer; stdcall; external actuator_dll; + +implementation + +end. -- Gitblit v1.9.3