LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Unknown Error in CIN dealing with Mutext and Memory mapped files

I have a CIN that uses a Mutext file to pass booleans between LV 6.1 and a C++ executable. I know that the data is going into the Mutext file from the CIN but isn't being recognized by the executable as being there.

I thought it might be do to incorrect value formatting (ie: int, float, bool, etc.) but I tried several variations and none worked.

Following is the code for the CIN:
typedef struct{
LVBoolean CalibrateMe; /* bool in C++ */
LVBoolean UnCalibrateMe; /* bool in C++ */
LVBoolean UseArbitraryPoints; /* bool in C++ */

} HandshakingData;

CIN MgErr CINRun(HandshakindData *HandshakingRecord,
uInt32 *m_hMutex, uInt32 *handshakeptr)
{ DWORD dwWaitResult
;

dwWaitResult = WaitForSingleObject(
(HANDLE)*m_hMutex,INFINITE);
switch(dwWaitResult)
{ case WAIT_OBJECT_0:
__try
{ HandshakingRecord->CalibrateMe = true;
HandshakingRecord->UnCalibrateMe = false;
HandshakingRecord->UseArbitraryPoints =
false;

memcpy((void *)(*handshakeptr),
(void *)HandshakingRecord,
sizeof(HandshakingData));
ReleaseMutex((HANDLE)*m_hMutex);
}
__finally
{ if(!ReleaseMutex((HANDLE)*m_hMutex))
{ /* error code here */
}
}
default:
{ }
}
return noErr;
}

To my knowledge there isn't any error in the code above, yet the executable isn't acknowleding the updated information written via memcpy. The size of the structs match (ie: 3 bytes
each).

Anything would be helpful.
KH @->---
The test of a first-rate intelligence is the ability to hold two opposed ideas in mind at the same time and still retain the ability to function. F. Scott Fitzgerald
0 Kudos
Message 1 of 3
(2,679 Views)
KH,

A LVBoolean is represented as a U8 (char) in memory. I am not sure about a bool in C++, but it might be an int underneath. If this is the case, then you may need to do some casting to get things to be viewable properly. This is my first gut feeling on this issue.

Randy Hoskin
Applications Engineer
National Instruments
http://www.ni.com/ask
0 Kudos
Message 2 of 3
(2,679 Views)
C++ has two formats dependent upon the version of Microsoft C++. In this case its a 1 byte int instead of the usual 4 byte ints. That was what I thought too. But I have altered this code and the C++ executable to floats (float32 in LabView) which I know match since I use them in another CIN, yet the executable wouldn't respond to the data passed it via the Mutex file from this CIN. Therein lies my confusion.

The primary difference between this CIN and the other is this one writes to the memory area and the other reads from a similar area.

The Mutex memory is setup as two structs(clusters) back to back with nothing inbetween. The first is a structure of 6 floats (float32 in LV) and the second is the one used in this CIN - 3 booleans 1 byte each. The CI
N that works reads the 6 floats while this one that doesn't work writes the 3 booleans.
KH @->---
The test of a first-rate intelligence is the ability to hold two opposed ideas in mind at the same time and still retain the ability to function. F. Scott Fitzgerald
0 Kudos
Message 3 of 3
(2,679 Views)