Ну как-то кластер создал, теперь его надо подключать к CLFNу. А не подскажете, как задать в CLFNе входную переменную типа "кластер"? там в явном виде такого нет: есть Numeric, String, Array, Adopt to Type...
Выбрал вход Adopt to Type и кластер подключился проводами. Это правильно?
так-то пока у меня не заработало...
Подключение СЛАВНЫ через CLFN
-
Borjomy_1
- doctor

- Сообщения: 2317
- Зарегистрирован: 28 июн 2012, 09:32
- Награды: 3
- Версия LabVIEW: 2009..2020
- Откуда: город семи холмов
- Благодарил (а): 33 раза
- Поблагодарили: 38 раз
Re: Подключение СЛАВНЫ через CLFN
Чтобы не гадать, напишите как выглядит заголовок функции с аргументами и содержимое структуры, т.е покажите .h файл
-
Kds
- interested

- Сообщения: 8
- Зарегистрирован: 06 ноя 2025, 12:39
- Версия LabVIEW: 8.5
- Контактная информация:
Re: Подключение СЛАВНЫ через CLFN
--обьявление функции настройки битрейта
SLCANAPI BOOL STDCALL SlCan_DeviceSetBitRate(
HSLCAN hDevice,
PSLCAN_BITRATE pBitRate
);
--SLCANAPI BOOL- свой тип логический где-то там определенный
pBitRate
[in] Указатель на переменную, в которой находится устанавливаемые параметры состояние
скорости передачи.
--далее определение этой самой структуры настройки скорости передачи
typedef struct _SLCAN_BITRATE {
WORD BRP;
BYTE TSEG1;
BYTE TSEG2;
BYTE SJW;
BYTE SAM;
}SLCAN_BITRATE,*PSLCAN_BITRATE;
--сама программа, которую я переписываю на ЛАБВЬЮ. в конце кусок непосредственно с самим использованием этой функции настройки скорости
#include "stdafx.h"
#include <slcan.h>
int _tmain(int argc, _TCHAR* argv[])
{
BOOL b;
ULONG devicecount;
HSLCAN hDevice;
SLCAN_BITRATE br;
SLCAN_MESSAGE OutMsg;
SLCAN_MESSAGE InMsg[100];
int i;
BYTE WriteStatus;
ULONG ReadCount;
// Загрузим библиотеку. Необходимо это сделать один раз
// до вызова любой другой функции библиотеки.
b=SlCan_Load(NULL,NULL);
if (!b) return 0;
// Выясним, сколько устройств доступно
devicecount = SlCan_GetDeviceCount();
if (!devicecount) return 0;
// Получим ссылку на первое устройство
hDevice = SlCan_GetDevice(0);
if (hDevice==INVALID_HANDLE_VALUE) return 0;
// Откроем устройство.
b = SlCan_DeviceOpen(hDevice);
if (!b) return 0;
// При открытии устройства устанавливается максимально возможная
// скорость передачи. Но мы установим 125kb/s
br.BRP = SLCAN_BR_CIA_125K;
b = SlCan_DeviceSetBitRate(hDevice,&br);
if (!b) return 0;
SLCANAPI BOOL STDCALL SlCan_DeviceSetBitRate(
HSLCAN hDevice,
PSLCAN_BITRATE pBitRate
);
--SLCANAPI BOOL- свой тип логический где-то там определенный
pBitRate
[in] Указатель на переменную, в которой находится устанавливаемые параметры состояние
скорости передачи.
--далее определение этой самой структуры настройки скорости передачи
typedef struct _SLCAN_BITRATE {
WORD BRP;
BYTE TSEG1;
BYTE TSEG2;
BYTE SJW;
BYTE SAM;
}SLCAN_BITRATE,*PSLCAN_BITRATE;
--сама программа, которую я переписываю на ЛАБВЬЮ. в конце кусок непосредственно с самим использованием этой функции настройки скорости
#include "stdafx.h"
#include <slcan.h>
int _tmain(int argc, _TCHAR* argv[])
{
BOOL b;
ULONG devicecount;
HSLCAN hDevice;
SLCAN_BITRATE br;
SLCAN_MESSAGE OutMsg;
SLCAN_MESSAGE InMsg[100];
int i;
BYTE WriteStatus;
ULONG ReadCount;
// Загрузим библиотеку. Необходимо это сделать один раз
// до вызова любой другой функции библиотеки.
b=SlCan_Load(NULL,NULL);
if (!b) return 0;
// Выясним, сколько устройств доступно
devicecount = SlCan_GetDeviceCount();
if (!devicecount) return 0;
// Получим ссылку на первое устройство
hDevice = SlCan_GetDevice(0);
if (hDevice==INVALID_HANDLE_VALUE) return 0;
// Откроем устройство.
b = SlCan_DeviceOpen(hDevice);
if (!b) return 0;
// При открытии устройства устанавливается максимально возможная
// скорость передачи. Но мы установим 125kb/s
br.BRP = SLCAN_BR_CIA_125K;
b = SlCan_DeviceSetBitRate(hDevice,&br);
if (!b) return 0;
-
Borjomy_1
- doctor

- Сообщения: 2317
- Зарегистрирован: 28 июн 2012, 09:32
- Награды: 3
- Версия LabVIEW: 2009..2020
- Откуда: город семи холмов
- Благодарил (а): 33 раза
- Поблагодарили: 38 раз
Re: Подключение СЛАВНЫ через CLFN
Во первых, в CLFN надо настраивать calling convension (stdcall), а не C как по умолчанию. Судя по вашему тексту.
hDevice должно быть Numeric int32, либо int64(в зависимости от версии Labview) Value
pBitRate должно быть Adtapt type, Handles by Value
вот что пишет справка:
Adapt to Type
Use Adapt to Type to pass arbitrary LabVIEW data types to DLLs in the following ways:
Scalars are passed by reference. A pointer to the scalar is passed to the library.
Arrays and strings are passed according to the Data Format setting. You can choose from the following Data Format settings:
Handles by Value passes the handle to the library. The handle is not NULL.
Pointers to Handles passes a pointer to the handle to the library. If the handle is NULL, treat the handle as an empty string or array. To set a value when the handle is NULL, you must allocate a new handle.
Array Data Pointer passes a pointer to the first element of the array, allowing the called library to access the array data as the data type of the array data.
Interface to Data allows you to inspect LabVIEW data and data type information in C++ code. For more information about this setting, refer to the ILVDataInterface.idl and ILVTypeInterface.idl files in the labview\cintools directory.
Clusters are passed by reference.
Scalar elements in arrays or clusters are in line. For example, a cluster containing a numeric is passed as a pointer to a structure containing a numeric.
Clusters within arrays are in line.
Strings and arrays within clusters are referenced by a handle.
Note
When one or more of the parameters of the function you want to call in a DLL are of types that do not exist in LabVIEW, ensure that each parameter is passed to the function in a way that allows the DLL to correctly interpret the data. Create a skeleton .c file from the current configuration of the Call Library Function Node. By viewing the .c file, you can determine whether LabVIEW will pass the data in a manner compatible with the DLL function. You then can make any necessary adjustments.
Кстати, если есть заголовочный файл .h, рекомендую попробовать покопаться в меню Toolt->Import->shared library. При наличии хорошо оформленного заголовочного файла достаточно быстро создается библиотека-обертка dll ки. но готовьтесь к тому, что этот файл придется править, чтобы Labview правильно все расписала
hDevice должно быть Numeric int32, либо int64(в зависимости от версии Labview) Value
pBitRate должно быть Adtapt type, Handles by Value
вот что пишет справка:
Adapt to Type
Use Adapt to Type to pass arbitrary LabVIEW data types to DLLs in the following ways:
Scalars are passed by reference. A pointer to the scalar is passed to the library.
Arrays and strings are passed according to the Data Format setting. You can choose from the following Data Format settings:
Handles by Value passes the handle to the library. The handle is not NULL.
Pointers to Handles passes a pointer to the handle to the library. If the handle is NULL, treat the handle as an empty string or array. To set a value when the handle is NULL, you must allocate a new handle.
Array Data Pointer passes a pointer to the first element of the array, allowing the called library to access the array data as the data type of the array data.
Interface to Data allows you to inspect LabVIEW data and data type information in C++ code. For more information about this setting, refer to the ILVDataInterface.idl and ILVTypeInterface.idl files in the labview\cintools directory.
Clusters are passed by reference.
Scalar elements in arrays or clusters are in line. For example, a cluster containing a numeric is passed as a pointer to a structure containing a numeric.
Clusters within arrays are in line.
Strings and arrays within clusters are referenced by a handle.
Note
When one or more of the parameters of the function you want to call in a DLL are of types that do not exist in LabVIEW, ensure that each parameter is passed to the function in a way that allows the DLL to correctly interpret the data. Create a skeleton .c file from the current configuration of the Call Library Function Node. By viewing the .c file, you can determine whether LabVIEW will pass the data in a manner compatible with the DLL function. You then can make any necessary adjustments.
Кстати, если есть заголовочный файл .h, рекомендую попробовать покопаться в меню Toolt->Import->shared library. При наличии хорошо оформленного заголовочного файла достаточно быстро создается библиотека-обертка dll ки. но готовьтесь к тому, что этот файл придется править, чтобы Labview правильно все расписала
-
Kds
- interested

- Сообщения: 8
- Зарегистрирован: 06 ноя 2025, 12:39
- Версия LabVIEW: 8.5
- Контактная информация:
Re: Подключение СЛАВНЫ через CLFN
заголовочного файла нет, к сожалению, только dll и руководство по ней
спасибо большое! буду пытаться что-то сделать)
спасибо большое! буду пытаться что-то сделать)