04-28-2023 05:50 AM
Hello All,
i have created tcp client program and i have created two dll
1st dll will have socket creation and connect function
2nd dll will have recv function inside while loop
i'am passing socket_id(Connectsocket) from 1st dll to 2nd dll
as i execute it gets connected but the 2nd dll will not display the data value as it is inside while(1) and it will never end
how can i display value for every iteration of loop.
Regards
Tushar
Regards
Tushar
04-28-2023 06:59 AM
@tushar.V wrote:
Hello All,
i have created tcp client program and i have created two dll
1st dll will have socket creation and connect function
2nd dll will have recv function inside while loop
i'am passing socket_id(Connectsocket) from 1st dll to 2nd dll
as i execute it gets connected but the 2nd dll will not display the data value as it is inside while(1) and it will never end
how can i display value for every iteration of loop.
Regards
Tushar
Regards
Tushar
Have you checked at-least for iteration working without loop as a part of debugging.
Also you cannot have a While loop with No stop button, Else you may need to abort which is not the recommended method.
If in case it works for single iteration and its not reading the data in the second time in the loop wire the connection socket output of DLL1 in both the ends of shift register.
If you are able to read the data and you need to append all the received data use Shift register to store the previous results.
04-28-2023 07:12 AM
the code for 2nd dll is like this
Client1(SOCKET &ConnectSocket, int data)
{
while(1)
{
recv(ConnectSocket,data,sizeof(data),0);
}
}
as it is inside while loop it will never end, so i'am not getting data value
04-28-2023 07:26 AM - edited 04-28-2023 07:27 AM
@tushar.V wrote:
the code for 2nd dll is like this
Client1(SOCKET &ConnectSocket, int data)
{
while(1)
{
recv(ConnectSocket,data,sizeof(data),0);
}
}
as it is inside while loop it will never end, so i'am not getting data value
Of course not! Remove that while(1) completely if you want to actually call this function from anywhere. Otherwise it just makes no sense!
And SOCKET is a pointer sized datatype. So it would not be correct to represent that as UIN32 if you ever intend to use LabVIEW 64-bit and an accordingly compiled 64-bit DLL.
And you could avoid these problems altogether by using the LabVIEW TCP nodes instead. No need for an external DLL to implement network communication!
04-28-2023 07:32 AM
if i remove while(1) the code will run every time from the beginiging , so the recv will lose connection, is there any other way where i can get data continuosly through dll
04-28-2023 07:48 AM
i'am trying to implement it like below image , it works correctly , so i want to do it with dll
am i missing something or have i written wrong code for 2nd dll
04-28-2023 07:48 AM
@tushar.V wrote:
if i remove while(1) the code will run every time from the beginiging , so the recv will lose connection, is there any other way where i can get data continuosly through dll
Huuuuh???? I have no idea what you are talking about.
What is in that function other than the while (1) and the recv()?
Why would it loose connection?
Why can't you do the loop around the call to recv() in the LabVIEW diagram?
Why even bother with DLLs if you have the exactly some functions as native LabVIEW functions too?
04-28-2023 08:02 AM
sorry this is my complete code
Client1(SOCKET &ConnectSocket, int data1)
{
int data1[100];
while(1)
{
recv(ConnectSocket,data,sizeof(data),0);
for(int i=0;i<100;i++)
{
data1[i]=data;
}
count ++;
if (count ==5)
break;
}
}
i'am trying to display data1 for every iteration of loop, but i get data1 only after loop breaks
04-28-2023 12:30 PM
That would never compile! You use a data variable in the call to recv() but have declared twice a data1 variable in your code (once as function parameter and once as local variable.
And even considering that your code simply makes no sense!
And yes the C function only returns after it has iterated through the 5 loops of course, and LabVIEW CAN'T see any data until the function returns. If you want to see the data in each iteration of the outer loop you have to move that loop to the LabVIEW diagram! There is NO other way. The DLL function is for LabVIEW a black box that it can not peek into! Nada, niente, nothing!
So if you want to display intermediate data you have to return to the caller everytime you want LabVIEW to display that data and then let LabVIEW call that function again!