Here's the source code for the test program if anyone wants to try and reproduce the problem. Thanks again!
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include <process.h>
#include <visa.h>
#define VISA_DLL "visa32.dll"
#define INSTR1_RESOURCE_NAME "GPIB1::5::INSTR"
#define INSTR2_RESOURCE_NAME "GPIB2::5::INSTR"
typedef ViStatus (_VI_FUNC *viOpenDefaultRMPtr)(ViPSession vi);
typedef ViStatus (_VI_FUNC *viOpenPtr)(ViSession sesn, ViRsrc name, ViAccessMode mode, ViUInt32 timeout, ViPSession vi);
typedef ViStatus (_VI_FUNC *viReadPtr)(ViSession vi, ViPBuf buf, ViUInt32 cnt, ViPUInt32 retCnt);
typedef ViStatus (_VI_FUNC *viWritePtr)(ViSession vi, ViBuf buf, ViUInt32 cnt, ViPUInt32 retCnt);
viOpenDefaultRMPtr g_pOpenDefaultRM = NULL;
viOpenPtr g_pOpen = NULL;
viReadPtr g_pRead = NULL;
viWritePtr g_pWrite = NULL;
HANDLE g_mutex = NULL;
unsigned __stdcall InstrThread( void *pArg )
{
DWORD dwEvent = 0;
char szBuffer[1024];
ViSession session = VI_NULL;
ViUInt32 retCount = 0;
ViStatus status = VI_NULL;
double dDC = 0.0;
// get the instrument session
session = *(ViSession*) pArg;
while ( true )
{
// attempt to acquire the mutex
dwEvent = WaitForSingleObject( g_mutex, INFINITE );
if ( dwEvent != WAIT_OBJECT_0 )
{
// force a context switch and then try to re-acquire the mutex
Sleep( 0 );
continue;
}
printf( "session 0x%08X acquired the mutex\n", session );
// format the DC query command
sprintf( szBuffer, "MEAS:DC?" );
// write the query command
retCount = 0;
status = (*g_pWrite)( session, (ViBuf) szBuffer, (ViUInt32) strlen( szBuffer ), &retCount );
printf( "\tcall to viWrite returned\n" );
if ( status < 0 )
printf( "\tviWrite returned an error: %08X\n", status );
else if ( retCount != strlen( szBuffer ) )
printf( "\tviWrite did not write the entire command\n" );
else
{
ZeroMemory( szBuffer, sizeof( szBuffer ) );
// read the query response
retCount = 0;
status = (*g_pRead)( session, (ViPBuf) szBuffer, sizeof( szBuffer ) - 1, &retCount );
printf( "\tcall to viRead returned\n" );
if ( status < 0 )
printf( "\tRead returned an error: %08X\n", status );
else
{
// add null-terminator to response
szBuffer[ retCount ] = '\0';
dDC = 0.0;
if ( sscanf( szBuffer, "%lf", &dDC ) != 1 )
printf( "\tcould not read DC value from return buffer: %s\n", szBuffer );
else
printf( "\tDC = %lf\n", dDC );
}
}
printf( "session 0x%08X is releasing the mutex\n", session );
// release the mutex
ReleaseMutex( g_mutex );
Sleep( 100 );
}
return (0);
}