Why am I unable to use functions from kernel32.dll such as GetSystemTimeAjustment() and SetSystemT​imeAdjustm​ent() in xPC target 4.3 (R2010a)?

6 views (last 30 days)
Our xPC target machine's system clock drifts at a rate of 2ms/second. Due to the level of system clock accuracy required by our application, we would likely need to set the system clock every time the model executes. I would like to be able to correct this drift through the SetSystemTimeAdjustment() function, so that we would not have to set the system
clock as often. This function is provided in the kernel32.dll.
However when I use the SetSystemTimeAdjustment() or GetSystemTimeAdjustment() function, the model errors when loaded to the target machine with the following message:
"Unable to load DLL dependeny Kernel32.dll: GetSystemTimeAdjustment
Could not load model: corrupted file"
I do not understand why this function does not get detected in the target machine because I am successfully able to use other functions from kernel32.dll such as GetSystemTime() and SetSystemTime().

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Apr 2010
The reason for this issue is that GetSystemTimeAdjustment function is not supported by the xPC kernel. Actually, the kernel32.dll provided by the compiler is not linked into our xPC kernel. When the application calls function GetModuleHandleA("kernel32.dll"), it returns a pointer pointing to certain address in the xPC kernel image instead of the head of kernel32.dll provided by the compiler. When the application calls some functions (e.g. GetSystemTime), it actually calls the GetSystemTime provided by xPC code, instead of the one provided by kernel32.dll. And this image does not emulate the function calls GetSystemTimeAdjustment, GetSystemTimeAdjustment etc.
Actually, all the system modules, including KERNEL32.dll, NTDLL.DLL, USER32.DLL, ADVAPI32.DLL, OLEAUT32.DLL, and RTT32DLL.DLL, are not linked into our kernel. xPC target only provides a set of functions to emulate the functions in these regular system dlls.
xPC target does not have any other tool to adjust target's system clock drift. One workaround to this would be to use an external source into the parallel port interrupt to run the model instead of relying on the system clock.

More Answers (0)

Tags

No tags entered yet.

Products


Release

R2010a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!