07-13-2021 07:52 AM
Good day, does anyone have experience with sending logs via UDP to a CVI application?
I send one log via UDP 100 times per second and the buttons in the application are stuck (cannot be clicked), if I change the period to 0.05 (20 times per second), they already work normally.
Don't know where the problem might be?
I use UDPCALLBACK according to the UDP example in CVI.
Even if I delete everything in this function, the buttons also jam.
thank you for help
07-15-2021 01:08 AM
Although I have a problem with another program, here it also makes me "at a speed of sending the log 0.01, the" Send "button does not work and as soon as I stop the program it works for a while.
If I have a value of 0.05 then it works normally.
Don't know how to treat it?
07-15-2021 02:37 AM - edited 07-15-2021 02:39 AM
With little or no experience on UDP I can only try guessing what's happening, but normally in case of unresponsiveness of the UI there are too much events to be handled in the UI thread. Considering that UPD callback is synchronous, this is very likely what you are facing at present: as a verification, with less events to handle you gain back UI sensitivity.
This problem is usually addressed by splitting the application in independent threads, in your case moving all the UDP stuff to a new thread.
Another, less efficient alternative is to optimize events handling; based on how you describe your application:
I know these tips are very generic and others may better suit your needs, but with very little details on the application I cannot give you more than this. Consider them as a conceptual framework to start with.
07-15-2021 03:10 AM
Hello Roberto,
thank you for the answer, i thought UDPCallback is synchronous and can it somehow be converted to asynchronous?
However, it also occurred to me to insert functions into a separate thread, but I still do not know how to implement.
Do you know what is special?
If I add the Synchronous timer and set the value to 0.01, the application runs normally with 100 times / sec logs without stuttering.
it's probably because it also runs synchronously with UDPcallback.
You don't know of an example where functions are used to create a separate thread.
Otherwise, I send logs with GPS from the company Novatel, which is able to send logs up to 200 times per second.
I apologize for my English.
Thank you
07-15-2021 04:51 AM
When coming to multithreading you have a set of resources to address. On one hand, the online help comes with a full chapter on this argument: you can find it in Creating Applications >> Creating Multithreaded Applications tree section of the help window.
On the other hand, there are a number of examples that you can study: search for them in the Example Finder (Help >> Find Examples... menu function, Search tab and "Thread" keyword). There are examples both for a TCP server and a TCP client that are probably the closest you can find for your actual application. Take your time to look at the other examples too, which can be useful as well.
07-15-2021 05:13 AM
Great, thank you Roberto, I'll look into it and write here how I proceeded if I came up with a result.
07-16-2021 03:41 AM
I tried to throw this program, which is above, into a separate thread, unfortunately I somehow fail. 😞
I can't separate UDPcallback, it probably has to stay there.
The example from CVI "MultiThreading.cws" is similar to UDP, but also retains the TCPCallback callback function.
07-16-2021 07:05 AM - edited 07-16-2021 07:07 AM
Well, as I told you I have no experience on UDP but in TCP it is important that the TCP callback is installed in the same thread that connects to the server, and the thread must be processing events for this to work: you can indeed see in MultiThreadingClient example that the thread callback is done this way:
/*---------------------------------------------------------------------------*/
/* TCP thread entry-point function. */
/*---------------------------------------------------------------------------*/
static int CVICALLBACK TCPThreadFunction (void *functionData)
{
// Connect to the server and install the TCP callback tohandle events
Connect ();
//Process events to permit communications
while (gRunning)
{
ProcessSystemEvents ();
}
// Disconnect fom the server
Disconnect ();
return 0;
}
In UDP environment things are very likely to work the same way, and this may be one problem for you (at least it was for me when I approached this scenario).
07-18-2021 11:48 PM
Thanks for the reply.
I also found this feature, but I don't know how to put UDPcallback into it.
So that I should insert the entire UDPcallback function into the body of the "TCPThreadFunction" function?
Unfortunately, I don't have much experience with threads.
Thank you
07-19-2021 04:10 AM
Well, as I told you I have no experience on UDP, but in my opinion if you can replicate the same structure as TCP using UDP functions it should work.
Can you post your code so that we can revise it? At least a minimum version that shows how you have set the system and threading up.