lvpstatic MgErr PyArray_ToLVData(PyObject value, int16 tdp, int32 off, UPtr data) {
MgErr err=1;
int32 elms, dims, lvDims = ArrayTDDims(tdp, off);
int32 j=0;
//tdp represents the data type identification array that needs to be converted to labview
//dim represents the dimension of the array
//elms stands for the number of arrays
if (PyArray_Attributes(value, &elms, &dims)==0) {
err=0;
if (lvDims >= dims) {
//List the offset of the data value in the labview memory
int32 elmoff = ArrEltTDOffset(tdp, off);
To
if(!((UHandle)data)){//The handle pointer of the input array data, the handle may be discarded by the runtime of labview, resulting in the phenomenon of no handle, here first check whether the handle exists, if not Exists, create a handle
int32 buffersize=elms(DataSize(tdp))+elmoff;
(UHandle*)data=DSNewAlignedHandle(buffersize,8,elmoff);
}//err = SetArraySize(&tdp, elmoff, lvDims, (UHandle)data, elms))&&
//When inputting an array pointer, use a constant handle pointer, which will not cause the pointer to be released and cause abnormal problems. Check the type constant of the pointer when Labview calls the dll
if (!(err = SetArraySize(&tdp, elmoff, lvDims, (UHandle)data, elms))&&((UHandle)data)) {//&& (UHandle)data
int32 i, sp;
PyObject list = value;
//This place has been obtained multiple times to prevent errors in obtaining the length of the list. It is not clear why the data parsing will cause problems
To
sp = (int32*)data;
/The following for loop writes the length of each dimension of the array data of the labview into the memory. For example, the following example
wangxina=[['1','2','3'],['4','1','5']]; will first write the length of 2 into the first bit of the address of data,
Then write 3 to the second digit of the memory
After writing all, assign a 1 at the end of the dimension length, the address in the memory is like this 2, 3, 1
/
for (i = 0; i <lvDims; i++, sp++) {
if (i <dims) {
sp = (int32)PyList_Size(list);
list = PyList_GetItem(list, 0);
}
else {
sp = 1;
}
}
To
//There is a big problem with the conversion part here. I haven't found it yet. It needs to be confirmed later. I really don’t understand how the data was converted and taken out. I have time in the later stage. You can take a closer look.
//This place may involve multiple data conversion and splitting, mainly because the labview data in the memory and the python data in the memory are stored in different forms
if ((err = PyArray_Convert(value, (UPtr)&sp, tdp, elmoff, DataSize(TDPtr(tdp, elmoff)), (int32)data))) {
//return err;
}
}
else
{
(int32*)data=data;
}
}
else {
err = mgNotSupported;
}
}
return err;//The array is successfully converted to 0
Please do not report bugs from self made modifications. This is not a LabVIEW DLL code writing exercise.