Visual export interface of X-Sim2
X-Sim supports many different solutions to communicate with other programs. But this is only based on one big memory area which carries the visual data exports. This visual data exports are the self defined gauge slots out of the gauge setup section in the profiler 2.x application. Additionally you find six user changeable math setup axis values which represents the actuator outputs. This axis are changeable in the program setup and can be mapped to other generated axis. This output is also used for the 3D plugins which needs axis1 and axis2 for their input.
All the values are placed somewhere in the memory. They are called “memory mapped files”, short MMF. This is a type of a file which is hidden from any normal file system. You can open them with special functions and read write to them like normal files.
First you have to know that if you open a file, you can read out the first byte followed by many others. It is necessary to know each byte by its name to find it again in that amount of following bytes. Memory usage of the x-sim visual export MMF:
#define maxnumberofgaugeslots 40 typedef struct SLOTSTRUCT { int slotstarted[maxnumberofgaugeslots]; int remoteshutdown[maxnumberofgaugeslots]; int slotdata[maxnumberofgaugeslots]; int visualaxis[6]; int positionx; int positiony; int saveposition[maxnumberofgaugeslots]; int moveall; int sync[maxnumberofgaugeslots]; } SharedSlotStruct; CSharedStruct<SharedSlotStruct> g_SharedSlotData("Global\\xsimgaugeslot");
You will find in the above code all information’s you will need. The gauge setup section is able to export 40 of the sender input values to one of the slots in the MMF file. You are able to choose the slot by your own. If you want to export the value you have to select the LCD-Gauge plugin which will fill the slot but not start any desktop gauge. Generally the name of the memory mapped file is:"Global\\xsimgaugeslot" There are many integer stored. A integer has 4bytes in the readable mmf file. You normaly read in bytes, not in integer, so you have to read 4 bytes to get the first integer. You will need all the “slotdata” integer values. The slot data integer array has 40 entries which carries the slot outputs you defined in the gauge slot list. Also the “visualaxis” values are interesting to be used. They are carry the result value of the math setup section. They can be mapped in the program setup if there are more than six axis. All other MMF bytes are used for internal desktop gauge use. All the values are available without a press on the start button. The Profiler 2.0 start button will only be needed to start the real hardware.
How to access the MMF file?
Accessing a MMF is done with WINAPI commands. Here I only show the C++ commands. In any other language you have to import that commands out of the kernel32.dll file. How you can do this you have to find in your language community or manual. C++ is very hardware oriented and uses the WINAPI in the Microsoft source code, because it is written in C++. Hint: The “CSharedStruct” class is a C++ memory mapped file wrapper which will make the MMF use like variables. It will open and close the MMF automatically. It is download able at www.codeproject.com and could help you with its very easy access. In the next sample I will not use it. First you have to open or create the file. Because X-Sim will create the file, you should only open it.
SLOTSTRUCT *inputmmf=(SLOTSTRUCT*) malloc(sizeof(SLOTSTRUCT)); HANDLE mmfhandle = OpenFileMappingA(FILE_MAP_READ,true,"Global\\xsimgaugeslot"); if(mmfhandle != NULL && mmfhandle != INVALID_HANDLE_VALUE ) { inputmmf = (SLOTSTRUCT *)MapViewOfFile(mmfhandle, FILE_MAP_READ, 0, 0, 0); int myfirstvalue=inputmmf->slotdata[0] UnmapViewOfFile(inputmmf); CloseHandle(mmfhandle); }
Step by step: First the data structure was declared as inputmmf. In most languages pointers are not welcomed, so you have to search for other solutions. The main commands are OpenFileMapping and MapViewOfFile. This are API commands and you can search your communities for sample programs with this WINAPI commands. OpenFileMappingA can be exchanged with OpenFileMappingW which reads longs. The W represents wide character (2bytes) in UNICODE, the A is normal ANSI. If the open command fails, the MMF does not exists and the Profiler 2.x was not started. (mmfhandle = NULL) After the file was successfully opened, we have to map the memory out of the x-sim memory to our memory with the MapViewOfFile command. After this we cann access the whole structure like in the myfirstvalue sample.
Do not forget to close the opened MMF file!
|