136 lines
3.5 KiB
C++
136 lines
3.5 KiB
C++
|
|
/**
|
|
* @brief is11相关底层函数
|
|
*
|
|
*/
|
|
#ifndef __IS3COMON_H__
|
|
#define __IS3COMON_H__
|
|
|
|
#ifndef IS3COMMON_H
|
|
#define IS3COMMON_H
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
#include <string>
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
#define COMMAND_GET 0x03
|
|
#define COMMAND_SET 0x06
|
|
#define COMMAND_MULTSET 0x10
|
|
#define POLYNOMIAL 0xa001 //modbus crc
|
|
#include "comon.h"
|
|
|
|
|
|
const u_char GET_ADDRESS[]={0x01,0x03,0x00,0x01,0x00,0x01};
|
|
const u_char GET_BANDRATE[]={0x01,0x03,0x00,0x02,0x00,0x01};
|
|
const u_char GET_INTEGRAL_TIME[]={0x01,0x03,0x00,0x06,0x00,0x01};
|
|
const u_char GET_AVERAGE_NUMBER[]={0x01,0x03,0x00,0x07,0x00,0x01};
|
|
const u_char GET_WAVELENTH_AT_BAND[]={0x01, 0x03, 0x00,0x10, 0x00,0x02};
|
|
const u_char GET_VALUE_AT_BAND[]={0x01, 0x03, 0x00,0x30, 0x00,0x02};
|
|
const u_char GET_SETTING_OF_LAMP[]={0x01, 0x03, 0x00,0x04, 0x00,0x01};
|
|
const u_char GET_WAVELENTH_COEFF[]={0x01, 0x03, 0x00,0x20, 0x00,0x08};
|
|
const u_char GET_ALL_DN[]={0x01, 0x03, 0x01,0x00, 0x10,0x00};
|
|
const u_char GET_SERIAL_NUMBER[]={0x01, 0x03, 0x00,0x40, 0x00,0x00};
|
|
const u_char GET_PRODUCT_NAME[]={0x01, 0x03, 0x00,0x50, 0x00,0x00};
|
|
|
|
const u_char SET_ADDRESS[]={0x01,0x06, 0x00,0x01};
|
|
const u_char SET_BandRATE[]={0x01,0x06, 0x00,0x02};
|
|
const u_char SET_INTEGRAL_TIME[]={0x01,0x06, 0x00,0x06};
|
|
const u_char SET_AVERAGE_NUMBER[]={0x01,0x06, 0x00,0x07};
|
|
const u_char SET_WORK_MODE[]={0x01,0x06, 0x00,0x01};
|
|
const u_char SET_WAVELENTH_COEFF[]={0x01,0x10,0x00,0x20,0x00,0x08,0x16};
|
|
|
|
/**
|
|
* @brief 判断传感器是否初始化完成
|
|
*
|
|
* @return true
|
|
* @return false
|
|
*/
|
|
bool isSensorInit();
|
|
/**
|
|
* @brief 初始化传感器
|
|
*
|
|
* @param writefunc 写函数
|
|
* @param readfunc 读函数
|
|
*/
|
|
void InitFunction(SERIALWRITE writefunc,SERIALWRITE readfunc);
|
|
|
|
/**
|
|
* @brief 获取 BufferForRead 的指针 用于读取返回的数据
|
|
*
|
|
*/
|
|
u_char * GetDataBufferPTR();
|
|
|
|
/**
|
|
* @brief 发送获取设备信息的指令 适用于Get指令
|
|
*
|
|
* @param Command 指令 预定的数组
|
|
* @param lenth 指令长度 可以用sizeof来求算
|
|
* @return size_t 返回数据的长度 输出存放于 BufferForRead;
|
|
*/
|
|
size_t SendGetSensorInfo(u_char * Command,size_t lenth);//此过程不适合获取数据
|
|
|
|
/**
|
|
* @brief
|
|
*
|
|
* @param shutter
|
|
* @return size_t
|
|
*/
|
|
size_t SendGetData(int shutter);
|
|
/**
|
|
* @brief 发送设置指令
|
|
*
|
|
* @param Command 指令内容
|
|
* @param CommandLenth 指令长度
|
|
* @param Value 设置值
|
|
* @param ValueLenth 值长度 默认是两个字节
|
|
* @return size_t 返回值长度
|
|
*/
|
|
size_t SendSettingCommand(u_char * Command,size_t CommandLenth,u_char *Value,size_t ValueLenth=2);
|
|
|
|
//big
|
|
/**
|
|
* @brief 用来获取信息的返回的数据
|
|
*
|
|
* @param isbig 是指用几个字节表示数据长度 暂时只发现采集数据时用两个字节
|
|
* @return size_t 接收到的数据大小
|
|
*/
|
|
size_t GetInfoBackFromSensor(bool isbig=false);
|
|
/**
|
|
* @brief 获取设置后返回数据
|
|
*
|
|
* @return size_t 返回数据长度;
|
|
*/
|
|
size_t GetSetBackFromSensor();
|
|
|
|
|
|
|
|
/**
|
|
* @brief
|
|
*
|
|
* @param data
|
|
* @param lenth
|
|
* @return size_t
|
|
*/
|
|
|
|
size_t SerialWrite(u_char* data,size_t lenth);
|
|
size_t SerailRead(u_char* data,size_t lenth=0);
|
|
/**
|
|
* @brief 计算crc16
|
|
*
|
|
* @param data 数据
|
|
* @param len 数据长度
|
|
* @param polynomial crc16多项式 默认是A001H
|
|
* @return uint16_t crc16的值
|
|
*/
|
|
uint16_t crc16(const uint8_t *data, size_t len, uint16_t polynomial=POLYNOMIAL) ;
|
|
|
|
bool panduanHeader();
|
|
|
|
|
|
void CoverLittleAndBig(char *data,int lenth);
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
#endif
|
|
#endif // __IS11COMON_H__
|