首次提交
This commit is contained in:
@@ -0,0 +1 @@
|
||||
/.idea
|
||||
@@ -0,0 +1,31 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
project(lv_cpp_demo LANGUAGES CXX)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
if(NOT WIN32)
|
||||
message(FATAL_ERROR "This sample builds a Windows DLL for LabVIEW.")
|
||||
endif()
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
message(WARNING "This is a 64-bit build. 32-bit LabVIEW needs a Win32 build.")
|
||||
endif()
|
||||
set(dir ${CMAKE_SOURCE_DIR}/src)
|
||||
file(GLOB_RECURSE srcs "${dir}/*.cpp" "${dir}/*.c" "${dir}/*.h")
|
||||
add_library(lv_cpp_demo SHARED ${srcs})
|
||||
target_compile_definitions(lv_cpp_demo PRIVATE LV_CPP_DEMO_BUILD)
|
||||
set_target_properties(lv_cpp_demo PROPERTIES OUTPUT_NAME lv_cpp_demo)
|
||||
if(MSVC)
|
||||
target_compile_options(lv_cpp_demo PUBLIC /utf-8)
|
||||
set(dumpbin "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/dumpbin.exe")
|
||||
add_custom_target(dump_exports
|
||||
COMMAND "${dumpbin}" /exports "$<TARGET_FILE:lv_cpp_demo>"
|
||||
DEPENDS lv_cpp_demo
|
||||
USES_TERMINAL
|
||||
)
|
||||
add_dependencies(dump_exports lv_cpp_demo)
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
add_executable(lv_cpp_demo_test test/main.cpp)
|
||||
target_link_libraries(lv_cpp_demo_test PRIVATE lv_cpp_demo)
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
实现 labview 调用c dll
|
||||
|
||||
使用msvc2019的时候 选择 好配置
|
||||

|
||||
|
||||
@@ -0,0 +1 @@
|
||||
[安装labview](https://zhuanlan.zhihu.com/p/1932866996887876485)
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 29 KiB |
Binary file not shown.
@@ -0,0 +1,2 @@
|
||||
[我的电脑]
|
||||
我的电脑 = "10.10.10.149"
|
||||
@@ -0,0 +1,2 @@
|
||||
[项目窗口数据(_D)]
|
||||
ProjectExplorer.ClassicPosition[String] = "261,767,882,1591"
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<Project Type="Project" LVVersion="25008000">
|
||||
<Property Name="NI.LV.All.SaveVersion" Type="Str">25.0</Property>
|
||||
<Property Name="NI.LV.All.SourceOnly" Type="Bool">true</Property>
|
||||
<Item Name="我的电脑" Type="My Computer">
|
||||
<Property Name="server.app.propertiesEnabled" Type="Bool">true</Property>
|
||||
<Property Name="server.control.propertiesEnabled" Type="Bool">true</Property>
|
||||
<Property Name="server.tcp.enabled" Type="Bool">false</Property>
|
||||
<Property Name="server.tcp.port" Type="Int">0</Property>
|
||||
<Property Name="server.tcp.serviceName" Type="Str">我的电脑/VI服务器</Property>
|
||||
<Property Name="server.tcp.serviceName.default" Type="Str">我的电脑/VI服务器</Property>
|
||||
<Property Name="server.vi.callsEnabled" Type="Bool">true</Property>
|
||||
<Property Name="server.vi.propertiesEnabled" Type="Bool">true</Property>
|
||||
<Property Name="specify.custom.address" Type="Bool">false</Property>
|
||||
<Item Name="add.vi" Type="VI" URL="../add.vi"/>
|
||||
<Item Name="依赖关系" Type="Dependencies"/>
|
||||
<Item Name="程序生成规范" Type="Build"/>
|
||||
</Item>
|
||||
</Project>
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#ifdef _WIN32
|
||||
#define LV_CALL __cdecl
|
||||
#ifdef LV_CPP_DEMO_BUILD
|
||||
#define LV_API __declspec(dllexport)
|
||||
#else
|
||||
#define LV_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define LV_CALL
|
||||
#define LV_API
|
||||
#endif
|
||||
typedef int32_t MgErr;
|
||||
typedef void *InstanceDataPtr;
|
||||
@@ -0,0 +1,4 @@
|
||||
#include "lv_cpp_demo.h"
|
||||
extern "C" LV_API int32_t LV_CALL lv_add_i32(int32_t a,int32_t b) {
|
||||
return a + b;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
#include "lv_api.h"
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
LV_API int32_t LV_CALL lv_add_i32(int32_t a,int32_t b);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,32 @@
|
||||
#include "lv_lifecycle.h"
|
||||
#include <new>
|
||||
struct LvLifecycleState {
|
||||
int32_t active;
|
||||
};
|
||||
extern "C" LV_API void LV_CALL lv_lifecycle_anchor(void) {
|
||||
}
|
||||
extern "C" LV_API MgErr LV_CALL lv_lifecycle_reserve(InstanceDataPtr *instanceState) {
|
||||
if (!instanceState) {
|
||||
return -1;
|
||||
}
|
||||
if (*instanceState) {
|
||||
return 0;
|
||||
}
|
||||
LvLifecycleState *state = new(std::nothrow) LvLifecycleState();
|
||||
if (!state) {
|
||||
return -2;
|
||||
}
|
||||
state->active = 1;
|
||||
*instanceState = state;
|
||||
return 0;
|
||||
}
|
||||
extern "C" LV_API MgErr LV_CALL lv_lifecycle_unreserve(InstanceDataPtr *instanceState) {
|
||||
if (instanceState && *instanceState) {
|
||||
delete static_cast<LvLifecycleState*>(*instanceState);
|
||||
*instanceState = nullptr;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
extern "C" LV_API MgErr LV_CALL lv_lifecycle_abort(InstanceDataPtr *instanceState) {
|
||||
return lv_lifecycle_unreserve(instanceState);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#include "lv_api.h"
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/* LabVIEW 生命周期锚点函数。函数本身不做业务逻辑,只用于挂载生命周期回调。 */
|
||||
LV_API void LV_CALL lv_lifecycle_anchor(void);
|
||||
/* LabVIEW 在调用库函数节点被保留执行时调用。适合做 DLL 级初始化。 */
|
||||
LV_API MgErr LV_CALL lv_lifecycle_reserve(InstanceDataPtr *instanceState);
|
||||
/* LabVIEW 在调用库函数节点解除保留时调用。适合释放保留阶段初始化的资源。 */
|
||||
LV_API MgErr LV_CALL lv_lifecycle_unreserve(InstanceDataPtr *instanceState);
|
||||
/* LabVIEW 在 VI 被强制中止时调用。只适合做紧急清理或通知后台任务退出。 */
|
||||
LV_API MgErr LV_CALL lv_lifecycle_abort(InstanceDataPtr *instanceState);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,22 @@
|
||||
#include "../src/lv_cpp_demo.h"
|
||||
#include <iostream>
|
||||
int main() {
|
||||
double in_data[3] = {1.0,2.0,3.0};
|
||||
double out_data[3] = {0.0,0.0,0.0};
|
||||
double sum = 0.0;
|
||||
char text[128];
|
||||
std::cout << "add=" << lv_add_i32(10,20) << std::endl;
|
||||
std::cout << "mul=" << lv_mul_f64(2.5,4.0) << std::endl;
|
||||
lv_sum_f64(in_data,3,&sum);
|
||||
std::cout << "sum=" << sum << std::endl;
|
||||
lv_scale_f64(in_data,3,10.0,out_data);
|
||||
std::cout << "scale=" << out_data[0] << "," << out_data[1] << "," << out_data[2] << std::endl;
|
||||
lv_make_message(123,text,sizeof(text));
|
||||
std::cout << "message=" << text << std::endl;
|
||||
void *engine = lv_engine_create();
|
||||
lv_engine_configure(engine,2.0,5.0);
|
||||
lv_engine_process(engine,in_data,3,out_data);
|
||||
std::cout << "engine=" << out_data[0] << "," << out_data[1] << "," << out_data[2] << std::endl;
|
||||
lv_engine_destroy(engine);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user