| | |
| | | |
| | | target_link_libraries(scpi_static PRIVATE Qt::Core) |
| | | |
| | | # if(MSVC) |
| | | # target_compile_options(scpi_static PRIVATE /TP) |
| | | # endif() |
| | | |
| | | project(scpi_static LANGUAGES CXX) |
| | | |
| | | # add_library(scpi SHARED ${SRC_FILES}) |
| | | |
| | | # target_include_directories(scpi |
| | | # PUBLIC |
| | | # "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/libscpi/inc>" |
| | | # ) |
| | | |
| | | enable_testing() |
| | | find_package(unofficial-cunit CONFIG REQUIRED) |
| | |
| | | scpi_result_t SCPI_CoreOpcQ(scpi_t * context); |
| | | scpi_result_t SCPI_CoreRst(scpi_t * context); |
| | | scpi_result_t SCPI_CoreSre(scpi_t * context); |
| | | scpi_result_t SCPI_NanCy(scpi_t * context); |
| | | scpi_result_t SCPICount(scpi_t * context); |
| | | scpi_result_t SCPI_CoreSreQ(scpi_t * context); |
| | | scpi_result_t SCPI_CoreStbQ(scpi_t * context); |
| | | scpi_result_t SCPI_CoreTstQ(scpi_t * context); |
| | | scpi_result_t SCPI_CoreWai(scpi_t * context); |
| | | |
| | | scpi_result_t SCPI_NanCy(scpi_t * context); |
| | | |
| | | |
| | | #define STB_R01 0x01 /* Not used */ |
| | | #define STB_PRO 0x02 /* Protection Event Flag */ |
| | |
| | | |
| | | #ifndef __SCPI_DEF_H_ |
| | | #define __SCPI_DEF_H_ |
| | | #ifdef __cplusplus |
| | | extern "C" { |
| | | #endif |
| | | |
| | | |
| | | #include "scpi/scpi.h" |
| | | |
| | | |
| | | /* |
| | | SCPI_IDN1 |
| | | SCPI_IDN2 |
| | | SCPI_IDN3 |
| | | SCPI_IDN4 |
| | | 这几个参数是用来注册时表示信息 |
| | | 对应*IDN? 查询命令的返回内容(设备标识查询命令) |
| | | 具体内容为(制造商,型号,序列号,固件版本) |
| | | 如果使用CPP版本的话使用scpi-def.h 和scpi-def.cpp |
| | | 这个提供了CPP版本的支持,.c的版本为旧标准版版本 |
| | | */ |
| | | #define SCPI_INPUT_BUFFER_LENGTH 256 |
| | | #define SCPI_ERROR_QUEUE_SIZE 17 |
| | | |
| | | |
| | | #define SCPI_IDN1 "MANUFACTURE" |
| | | #define SCPI_IDN2 "INSTR2013" |
| | | #define SCPI_IDN1 "MANUFACTURE\n" |
| | | #define SCPI_IDN2 "INSTR2013\n" |
| | | #define SCPI_IDN3 NULL |
| | | #define SCPI_IDN4 "01-02" |
| | | #define SCPI_IDN4 "01-02\n" |
| | | |
| | | extern const scpi_command_t scpi_commands[]; |
| | | extern scpi_interface_t scpi_interface; |
| | |
| | | |
| | | scpi_result_t SCPI_SystemCommTcpipControlQ(scpi_t * context); |
| | | |
| | | #ifdef __cplusplus |
| | | } |
| | | #endif |
| | | #endif /* __SCPI_DEF_H_ */ |
| | | |
| | |
| | | scpi_buffer_t buffer; |
| | | //解析命令的参数列表 |
| | | scpi_param_list_t param_list; |
| | | //SCPI的硬件接口,刷新 重置 写入 报错 |
| | | //SCPI的外部接口,刷新 重置 写入 报错 |
| | | scpi_interface_t * interface; |
| | | //输出数据的个数 |
| | | int_fast16_t output_count; |
| | |
| | | const char * idn[4]; |
| | | //剩余待传输的字节 |
| | | size_t arbitrary_remaining; |
| | | |
| | | //output为自增字段,保存返回结果,提供给程序响应内部输出 |
| | | char outPut[1024]; |
| | | }; |
| | | |
| | | enum _scpi_array_format_t { |
| | |
| | | if (stb & sre) { |
| | | ptrans = ((old_val ^ val) & val); |
| | | context->registers[SCPI_REG_STB] |= STB_SRQ; |
| | | if (ptrans & val) { |
| | | if (ptrans & val) |
| | | { |
| | | writeControl(context, SCPI_CTRL_SRQ, context->registers[SCPI_REG_STB]); |
| | | } |
| | | } else { |
| | | } else |
| | | { |
| | | context->registers[SCPI_REG_STB] &= ~STB_SRQ; |
| | | } |
| | | break; |
| | |
| | | */ |
| | | scpi_result_t SCPI_CoreIdnQ(scpi_t * context) { |
| | | int i; |
| | | for (i = 0; i < 4; i++) { |
| | | if (context->idn[i]) { |
| | | for (i = 0; i < 4; i++) |
| | | { |
| | | if (context->idn[i]) |
| | | { |
| | | char* outPut = "IDNS响应"; |
| | | memcpy(context->outPut,outPut,strlen(outPut)); |
| | | context->interface->write(context,context->idn[i],0); |
| | | SCPI_ResultMnemonic(context, context->idn[i]); |
| | | } else { |
| | | SCPI_ResultMnemonic(context, "0"); |
| | |
| | | * @param context |
| | | * @return |
| | | */ |
| | | scpi_result_t SCPI_CoreSreQ(scpi_t * context) { |
| | | SCPI_ResultInt32(context, SCPI_RegGet(context, SCPI_REG_SRE)); |
| | | scpi_result_t SCPI_CoreSreQ(scpi_t * context) |
| | | { |
| | | context->interface->write(context,"Registers request start",0); |
| | | for(int i =0;i<SCPI_REG_COUNT;i++) |
| | | { |
| | | context->interface->write(context,(char*)context->registers[i],0); |
| | | } |
| | | context->interface->write(context,"Registers request end",0); |
| | | return SCPI_RES_OK; |
| | | } |
| | | |
| | |
| | | return SCPI_RES_OK; |
| | | } |
| | | |
| | | scpi_result_t SCPI_NanCy(scpi_t * context) |
| | | { |
| | | |
| | | return SCPI_RES_OK; |
| | | } |
| | | scpi_result_t SCPICount(scpi_t * context) |
| | | { |
| | | return SCPI_RES_OK; |
| | | |
| | | |
| | | } |
| | | |
File was renamed from libscpi/src/scpi-def.c |
| | |
| | | return SCPI_RES_OK; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Reimplement IEEE488.2 *TST? |
| | | * |
| | |
| | | |
| | | return SCPI_RES_OK; |
| | | } |
| | | |
| | | /* |
| | | scpi_commands提供了所有的scpi命令以及命令的回调函数和处理 |
| | | 后续如果需要添加自定义的指令集则在此处添加 |
| | | */ |
| | | const scpi_command_t scpi_commands[] = { |
| | | /* IEEE Mandated Commands (SCPI std V1999.0 4.1.1) */ |
| | | { .pattern = "*CLS", .callback = SCPI_CoreCls,}, |
| | | { .pattern = "*ESE", .callback = SCPI_CoreEse,}, |
| | | { .pattern = "*ESE?", .callback = SCPI_CoreEseQ,}, |
| | | { .pattern = "*ESR?", .callback = SCPI_CoreEsrQ,}, |
| | | { .pattern = "*IDN?", .callback = SCPI_CoreIdnQ,}, |
| | | { .pattern = "*OPC", .callback = SCPI_CoreOpc,}, |
| | | { .pattern = "*OPC?", .callback = SCPI_CoreOpcQ,}, |
| | | { .pattern = "*RST", .callback = SCPI_CoreRst,}, |
| | | { .pattern = "*SRE", .callback = SCPI_CoreSre,}, |
| | | { .pattern = "*SRE?", .callback = SCPI_CoreSreQ,}, |
| | | { .pattern = "*STB?", .callback = SCPI_CoreStbQ,}, |
| | | { .pattern = "*TST?", .callback = My_CoreTstQ,}, |
| | | { .pattern = "*WAI", .callback = SCPI_CoreWai,}, |
| | | {"*CLS", SCPI_CoreCls, 0}, |
| | | {"*ESE", SCPI_CoreEse, 0}, |
| | | {"*ESE?", SCPI_CoreEseQ, 0}, |
| | | {"*ESR?", SCPI_CoreEsrQ, 0}, |
| | | {"*IDN?", SCPI_CoreIdnQ, 0}, |
| | | {"*OPC", SCPI_CoreOpc, 0}, |
| | | {"*OPC?", SCPI_CoreOpcQ, 0}, |
| | | {"*RST", SCPI_CoreRst, 0}, |
| | | {"*SRE", SCPI_CoreSre, 0}, |
| | | {"*SRE?", SCPI_CoreSreQ, 0}, |
| | | {"*STB?", SCPI_CoreStbQ, 0}, |
| | | {"*TST?", My_CoreTstQ, 0}, |
| | | {"*WAI", SCPI_CoreWai, 0}, |
| | | //用来测试 |
| | | //{"*NanCy", SCPI_NanCy, 0}, |
| | | |
| | | /* Required SCPI commands (SCPI std V1999.0 4.2.1) */ |
| | | {.pattern = "SYSTem:ERRor[:NEXT]?", .callback = SCPI_SystemErrorNextQ,}, |
| | | {.pattern = "SYSTem:ERRor:COUNt?", .callback = SCPI_SystemErrorCountQ,}, |
| | | {.pattern = "SYSTem:VERSion?", .callback = SCPI_SystemVersionQ,}, |
| | | {"SYSTem:ERRor[:NEXT]?", SCPI_SystemErrorNextQ, 0}, |
| | | {"SYSTem:ERRor:COUNt?", SCPI_SystemErrorCountQ, 0}, |
| | | {"SYSTem:VERSion?", SCPI_SystemVersionQ, 0}, |
| | | |
| | | /* {.pattern = "STATus:OPERation?", .callback = scpi_stub_callback,}, */ |
| | | /* {.pattern = "STATus:OPERation:EVENt?", .callback = scpi_stub_callback,}, */ |
| | | /* {.pattern = "STATus:OPERation:CONDition?", .callback = scpi_stub_callback,}, */ |
| | | /* {.pattern = "STATus:OPERation:ENABle", .callback = scpi_stub_callback,}, */ |
| | | /* {.pattern = "STATus:OPERation:ENABle?", .callback = scpi_stub_callback,}, */ |
| | | {"STATus:QUEStionable[:EVENt]?", SCPI_StatusQuestionableEventQ, 0}, |
| | | {"STATus:QUEStionable:ENABle", SCPI_StatusQuestionableEnable, 0}, |
| | | {"STATus:QUEStionable:ENABle?", SCPI_StatusQuestionableEnableQ, 0}, |
| | | |
| | | {.pattern = "STATus:QUEStionable[:EVENt]?", .callback = SCPI_StatusQuestionableEventQ,}, |
| | | /* {.pattern = "STATus:QUEStionable:CONDition?", .callback = scpi_stub_callback,}, */ |
| | | {.pattern = "STATus:QUEStionable:ENABle", .callback = SCPI_StatusQuestionableEnable,}, |
| | | {.pattern = "STATus:QUEStionable:ENABle?", .callback = SCPI_StatusQuestionableEnableQ,}, |
| | | |
| | | {.pattern = "STATus:PRESet", .callback = SCPI_StatusPreset,}, |
| | | {"STATus:PRESet", SCPI_StatusPreset, 0}, |
| | | |
| | | /* DMM */ |
| | | {.pattern = "MEASure:VOLTage:DC?", .callback = DMM_MeasureVoltageDcQ,}, |
| | | {.pattern = "CONFigure:VOLTage:DC", .callback = DMM_ConfigureVoltageDc,}, |
| | | {.pattern = "MEASure:VOLTage:DC:RATio?", .callback = SCPI_StubQ,}, |
| | | {.pattern = "MEASure:VOLTage:AC?", .callback = DMM_MeasureVoltageAcQ,}, |
| | | {.pattern = "MEASure:CURRent:DC?", .callback = SCPI_StubQ,}, |
| | | {.pattern = "MEASure:CURRent:AC?", .callback = SCPI_StubQ,}, |
| | | {.pattern = "MEASure:RESistance?", .callback = SCPI_StubQ,}, |
| | | {.pattern = "MEASure:FRESistance?", .callback = SCPI_StubQ,}, |
| | | {.pattern = "MEASure:FREQuency?", .callback = SCPI_StubQ,}, |
| | | {.pattern = "MEASure:PERiod?", .callback = SCPI_StubQ,}, |
| | | {"MEASure:VOLTage:DC?", DMM_MeasureVoltageDcQ, 0}, |
| | | {"CONFigure:VOLTage:DC", DMM_ConfigureVoltageDc, 0}, |
| | | {"MEASure:VOLTage:DC:RATio?", SCPI_StubQ, 0}, |
| | | {"MEASure:VOLTage:AC?", DMM_MeasureVoltageAcQ, 0}, |
| | | {"MEASure:CURRent:DC?", SCPI_StubQ, 0}, |
| | | {"MEASure:CURRent:AC?", SCPI_StubQ, 0}, |
| | | {"MEASure:RESistance?", SCPI_StubQ, 0}, |
| | | {"MEASure:FRESistance?", SCPI_StubQ, 0}, |
| | | {"MEASure:FREQuency?", SCPI_StubQ, 0}, |
| | | {"MEASure:PERiod?", SCPI_StubQ, 0}, |
| | | |
| | | {.pattern = "SYSTem:COMMunication:TCPIP:CONTROL?", .callback = SCPI_SystemCommTcpipControlQ,}, |
| | | {"SYSTem:COMMunication:TCPIP:CONTROL?", SCPI_SystemCommTcpipControlQ, 0}, |
| | | |
| | | {.pattern = "TEST:BOOL", .callback = TEST_Bool,}, |
| | | {.pattern = "TEST:CHOice?", .callback = TEST_ChoiceQ,}, |
| | | {.pattern = "TEST#:NUMbers#", .callback = TEST_Numbers,}, |
| | | {.pattern = "TEST:TEXT", .callback = TEST_Text,}, |
| | | {.pattern = "TEST:ARBitrary?", .callback = TEST_ArbQ,}, |
| | | {.pattern = "TEST:CHANnellist", .callback = TEST_Chanlst,}, |
| | | {"TEST:BOOL", TEST_Bool, 0}, |
| | | {"TEST:CHOice?", TEST_ChoiceQ, 0}, |
| | | {"TEST#:NUMbers#", TEST_Numbers, 0}, |
| | | {"TEST:TEXT", TEST_Text, 0}, |
| | | {"TEST:ARBitrary?", TEST_ArbQ, 0}, |
| | | {"TEST:CHANnellist", TEST_Chanlst, 0}, |
| | | |
| | | SCPI_CMD_LIST_END |
| | | }; |
| | | |
| | | scpi_interface_t scpi_interface = { |
| | | .error = SCPI_Error, |
| | | .write = SCPI_Write, |
| | | .control = SCPI_Control, |
| | | .flush = SCPI_Flush, |
| | | .reset = SCPI_Reset, |
| | | /*.error = */ SCPI_Error, |
| | | /*.write = */ SCPI_Write, |
| | | /*.control = */ SCPI_Control, |
| | | /*.flush = */ SCPI_Flush, |
| | | /*.reset = */ SCPI_Reset, |
| | | }; |
| | | |
| | | char scpi_input_buffer[SCPI_INPUT_BUFFER_LENGTH]; |