unused plin clients left in memory

The free LIN software API (Application Programming Interface) for Windows® (only for usage with the PCAN-USB Pro CAN/LIN interface)
Post Reply
MOlrich
Posts: 2
Joined: Thu 28. Jun 2018, 17:43

unused plin clients left in memory

Post by MOlrich » Thu 28. Jun 2018, 18:58

Looking for a way to find and kill PLin clients from the API.
Have noticed the app has been leaving clients open if the app closes abnormally.
the clients can be seen with the plinstat.exe tool.
How can I detect these errant clients and then destroy them from the API?

I have tried getting there handle using the getavailablehardware function and then subsequent calls to
LIN_GetHardwareParam with hwpConnectedClients as the parameter
It does not show any clients even though plinstat.exe does.

How can I find the client if the hardware has already been disconnected?
Last edited by K.Wagner on Fri 29. Jun 2018, 07:46, edited 1 time in total.
Reason: Moved from "Third Party Software" to "Development Packages / PLIN-API"

K.Wagner
Software Development
Software Development
Posts: 732
Joined: Wed 22. Sep 2010, 13:36

Re: unused plin clients left in memory

Post by K.Wagner » Fri 29. Jun 2018, 08:35

Hello,

first of all you need a method to detect which clients have been created from your application. You can achieve this by using a name pattern like MyAPP_ClientX, so that you can recognize them (you have up to 48 characters available for the name).

Then, at each start of your program you could have a loop, a for-statement for instance, in which you check if a client with this name pattern exists. This is done using the function 'LIN_GetClientParam'. As "client handle" you use the value of the iteration, from 1 to n, where n is the maximum amount clients you may have.

Note that the API has no restriction on the amount of clients, so how many iterations you have to do is up to you. If a client with handle x has a name (parameter 'clpName ') that match your pattern, then you can delete this client x by using the function LIN_RemoveClient(x).

Code: Select all

This pseudocode shows that explained before. A for-statement iterates client handles from 1 to 64. A function call is used to check if the current client name matches a pattern. If it does, the client is removed:

for(byte hClient=1; hClient<=64; hClient++)
    if(LIN_GetClientParam(hClient, clpName, nameBuffer, 48) == errOK)
        if(ClientBelongsToApp(nameBuffer))
            if (LIN_RemoveClient(hClient) == errOK)
                MessageBox("Client %hClient% (%nameBuffer%) removed");
            else
                MessageBox("An Error occurred while removing a client");
Best regards,
Keneth

MOlrich
Posts: 2
Joined: Thu 28. Jun 2018, 17:43

Re: unused plin clients left in memory

Post by MOlrich » Fri 29. Jun 2018, 15:29

Thanks
Works great.
Did not realize the Handle was just an index, as opposed to a pointer to the object


Matt

Post Reply