08-18-2011 07:15 PM
I've used a PXI-6541 card for a few projects involving digital input and output and have not had any problems. Today I started to implement a new feature that reads the signals to generate in from a file and outputs them to the card. When I try to write the data to the card, I receive the following error:
NI Platform Services: One or more memory pages in the specified logical buffer could not be locked into physical memory. The operation could not be completed as specified.
I am using C and compiling with MS Visual Studio 2005. The issue seems to occur when I try to transfer more than 256kB to the card. Even if I break it up into smaller chunks and append each chunk to the waveform, I get this error after 256kB.
I created a simple test case console application that exhibits the same issue. Can anyone please provide any suggestions?
Example C code:
#include <stdio.h> #include <tchar.h> #include <windows.h> #include "stdafx.h" #include "niHSDIO.h" #define errorCheckNIHSDIO(X) \ status = X; \ if (status < VI_SUCCESS) \ { \ displayNIHSDIOError(status); \ return FALSE; \ } ViSession dOSession; void displayNIHSDIOError(ViStatus errorCode) { char errorMessage[256] = ""; niHSDIO_error_message(dOSession, errorCode, errorMessage); printf("Error: %s\n", errorMessage); } int _tmain(int argc, _TCHAR* argv[]) { HANDLE hvecFile = NULL; LARGE_INTEGER vecFileSize; ViUInt32 extra = 0; ViUInt32 pad = 0; ViStatus status = 0; ViUInt32 *waveform; int i = 0; ViInt32 samples = 0; errorCheckNIHSDIO(niHSDIO_InitGenerationSession("DigitalIO", VI_TRUE, VI_TRUE, "", &dOSession)); errorCheckNIHSDIO(niHSDIO_AssignDynamicChannels(dOSession, "0-5")); errorCheckNIHSDIO(niHSDIO_ConfigureSampleClock(dOSession, NIHSDIO_VAL_ON_BOARD_CLOCK_STR, 50.0e3)); hvecFile = CreateFile(L"C:\\input.bin", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (!hvecFile) { printf("Unable to open vector input file.\n"); return FALSE; } // Determine vector file size if (!GetFileSizeEx(hvecFile, &vecFileSize)) { printf("Unable to determine the size of the vector input file."); CloseHandle(hvecFile); return FALSE; } if (vecFileSize.HighPart > 0) { printf("Vector input file is too large.\n"); CloseHandle(hvecFile); return FALSE; } // If the vector file is not a multiple of 32 samples (not bytes), need to copy the last sample a few times until it reaches a multiple of 32 for the PXI-6541 card extra = (vecFileSize.LowPart / sizeof(waveform)) % 32; if (extra > 0) pad = 32 - extra; else pad = 0; waveform = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, vecFileSize.LowPart + sizeof(waveform)*pad); if (!waveform) { printf("Unable to allocate memory for the vectors\n"); CloseHandle(hvecFile); return FALSE; } if (!ReadFile(hvecFile, waveform, vecFileSize.LowPart, &samples, NULL)) { printf("Unable to read vector input file\n"); CloseHandle(hvecFile); return FALSE; } CloseHandle(hvecFile); errorCheckNIHSDIO(niHSDIO_ConfigureSampleClock(dOSession, NIHSDIO_VAL_ON_BOARD_CLOCK_STR, 2.0e6)); niHSDIO_AllocateNamedWaveform(dOSession, "Output", samples); for (i = 0; i < samples; i += 65536) { printf("i=%d\n", i); errorCheckNIHSDIO(niHSDIO_WriteNamedWaveformU32(dOSession, "Output", 65536, waveform+i)); } return 0; }Output of the code:
i=0 i=65536 i=131072 Error: NI Platform Services: One or more memory pages in the specified logical buffer could not be locked into physical memory. The operation could not be completed as specified.
Solved! Go to Solution.
08-19-2011 01:55 PM
Hi Andrew N,
Thanks for posting. For my own reference, what version of the NI-HSDIO driver are you using?
One possibility is that it does not appear that you have an niHSDIO_close function in your program. Maybe the function was in a portion of your code that you didn't include in your post, but if that is not included at the end of your program, the resources for your 6541 card may not be releasing properly and causing an error like this. If you aren't already using an niHSDIO_close, I recommend that you include it in your program. Additionally, you may want to reset the device in Measurement & Automation Explorer to try to release the device resources that are currently in use. Let me know if that helps, thanks!
Regards,
Joe S.
08-19-2011 03:02 PM
Hi,
I'm using NI-HSDIO version 1.7.3.1. I've also tried on a system running NI-HSDIO version 1.7.3.
I did have niHSDIO_close in my real program...I chopped everything off of this one at the point where the error occurred. I know what you are getting at, but I have tried running the test application immediately after a complete system reboot and the problem still occurred.
I have 2.0GB of physical memory and a swap file with a minimum of 3GB allocated.
Andrew
08-19-2011 03:17 PM
Oops - this was my error. I was thinking that the samples variable I passed to ReadFile() was the number of samples...but that's actually the number of bytes read...so I need to divide that by 4 to get the number of samples since I am doing a 32-bit write. The NI-HSDIO library was then trying to read beyond my allocated memory which generated this error.
Thanks for your help.