A timing message needs to go out every 20 msec, thats why I wanted to use this interrupt facility on the PCI card. Most other data goes out at 100 msec or 300 msec, which wold be OK for Windows timers. I may be wrong but is not Windows limited to 55 msec accuracy? So do you think that this solution is poor? Andy
Andy202
Posts
-
Call Class Members from Interrupt Routine -
Call Class Members from Interrupt RoutineYes, the card comes with a good API and I just need to install the interrupt handler at the start with a call-back routine and uninstall as the program ends. You do get a 'blue screen of death' from time to time; buts thats down to developing code and debugging - to be expected until the code is mature. Andy
-
Call Class Members from Interrupt RoutineThanks for the information and direction. I got it working now. My application was a MFC C++ Dialog based program using VS2008. The most difficult part was getting the first parameter in the PostMessage() call. This was the HWND hWnd of the main window. I used a global variable g_hMainHWND so that it was available in both the interrupt and main program. Code as follows:-
//In the header file
#define Digital_Event 1
// Message for 1553 interrupts
afx_msg LRESULT OnDigitalInterrupt(UINT wParam, LONG lParam);// In the Main MFC file of the application
const UINT WM_INTERRUPT_DIGITAL = WM_APP + 1;
HWND g_hMainHWND;BEGIN_MESSAGE_MAP(CDigitalPnPDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
// Interrupt for Digital
ON_MESSAGE(WM_INTERRUPT_DIGITAL, OnDigitalInterrupt)// In the Dialog Init routine
g_hMainHWND = this->GetSafeHwnd();LRESULT CDigitalPnPDlg::OnDigitalInterrupt(UINT wParam, LONG lParam)
{
/* This routine is called every 20 msec by the interrupt from the
board. */
if(wParam == Digital_Event)
manage_timers();
return 0;
}// In the interrupt routin
/* Arrange for the processing of the 20 msec interrupt in the main application */
PostMessage(g_hMainHWND, WM_INTERRUPT_DIGITAL, Digital_Event, NULL);Note I was using the interrupt to provide a timer facility as the card was providing this every 20 msec. Andy
-
Call Class Members from Interrupt RoutineOK Jochen, thanks for the info. I remember using EVENTS a few years ago (this is similar?), but if you have a link or example that would be great as very out of date hear. Searching through old code to see what I did in the past regarding events. Andy
-
Call Class Members from Interrupt RoutineI have installed a PCI digital card which provides an interrupt every 20 msec. Now I would like to be able to call procedures within my MFC aplication from this routine. Are they any way I can call - exampe
CTest1::Timer1() // MFC Dialog is CTest1
from
DigitalInt();
I am not an expert on Namespace, but I think thats the problem. Andy.
-
MFC Program and Very Large Text FilesThanks Federico for the information. The requirement has gone away, but I thought that it would be good to do this task (a worked example) should I ever need to revist this problem again. Just one follow up question you suggest 64 KB (the allocation granularity size)? Is this from expericence? And the best value. Andy
-
MFC Program and Very Large Text FilesThanks for your post jschell. Two input files to generate one output file. Input1 sampled at 50 msec and Input2 sampled at 200 msec, so using timing information merge the two sets of data into one output file; interporlate as required. I can do what is required if the files were as follows:- Input1 = 1 Mb; Input2 = 2Mb and Output = 5Mb. Andy
-
MFC Program and Very Large Text FilesThanks Federico for your post. I have used these API's, but for large auto generated data structures ~ 50k bytes. I did look at he link you gave and the following concerns me:- If the file mapping object is backed by the operating system paging file (the hfile parameter is INVALID_HANDLE_VALUE), specifies that when a view of the file is mapped into a process address space, the entire range of pages is committed rather than reserved. The system must have enough committable pages to hold the entire mapping. Otherwise, CreateFileMapping fails. With files sizes of ~ 500GB will these APIs work? Andy.
-
MFC Program and Very Large Text FilesFor merging together some recording data stored in CSV files I have used the class CtextFile (by Johan Rosengren via the Codeproject site) to read in and write out the processed files. I also used class CNewStringArray (which is a modified version of CStringArray by Anders M Eriksson, again via the Codeproject) I use the MFC function AfxExtractSubString() to extract the various fields of the CSV record and CnewStringArray variables to hold and process the data. Now I have a problem where the size of some of the files to be processed may be in the order of 250 to 700Gb. I have never used files larger that about 10Mb, but will I have problems with files these sizes and do I need to consider new methods of processing these very large files. Any comments and advice please.
-
Shared Library o DLL?For an item of hardware I have written a Shared library to make it easy to use the API for this hardware. The library sets up data structures and handles, buffers etc for simple program use. For example to arrange data to be transmitted I call routines like:-
UINT16 TransmitData( UINT unit, UINT addr, TXBUFFER * tx_buffer );
However in VS2008 I used C++ in a MFC dialog application, which all worked well. Having moved to VS2010, I now see that the intellisence does not work with this product for C++. So my thoughts were to use C# for the Windows forms and link in the Shared Library. My question is do I need to general a DLL rather than a Shared Library so that I can use C++, C# and perhaps VB. Is this correct and what are the procedures to follow. The libray is built using C. I include the API.lib and API.h along with the DLL that came with the API s/w environment. Many thanks, Andy
-
How To Use a C Libray in your C# ProgramFor an item of hardware I have written a Shared library to make it easy to use the API for this hardware. The library sets up data structures and handles, buffers etc for simple program use. For example to arrange data to be transmitted I call routings like:- UINT16 TransmitData( UINT unit, UINT addr, TXBUFFER * tx_buffer ); However in VS2008 I used C++ in a MFC dialog application, which all worked well. Having moved to VS2010, I now see that the intellisence does not work with this product. So my thoughts were to use C# for the Windows forms and link in the Shared Library. I have built the Shared Library in VS2010 so I need to understand how to access these function in a C# program. Is this using ‘Wrappers’ and how does the libraries API001.LIB and API001.h files link in? For a C++ MFC program I included the headers and LIB files with the PATH set up for the DLL’s. The libray is built using C. Many thanks, Andy
-
C Casting ProblemThanks Luc, the Longitude (-180 to +180) has the same scaling. I can get the code running OK on Windwos but when ported to Unix (using a Gnu complier) the program bombs out. Debuggin a bit limited hence the use of Windows for the development.
-
C Casting ProblemI have seen the term Fixed_32 for a data item with MSB = 1 and LSB = 1/2**31 ; Max = 1.0 and Min = -1.0 with units of semicircles (used for Latitude and Longitude) I did think this was a float to the IEEE-754 Floating-Point Representation. However the 3rd party that is reading some data via a message structure cannot see the same value. I mistaken the term Fixed_32 as a standard float but it is a 32 bit int in the message. The scalling is:-
#define BEARING_SCALING 4.65661287307739E-10
typedef struct ReceiveMessage
{
unsigned int msgNumber; // Msg number
int msgPosLat; // Msg latitude
int msgPosLong; // Msg longitude
unsigned int msgQuality; // Msg quality
}positionData#define BEARING_SCALING 4.65661287307739E-10
However I get a crash when I try to load the value (the Latitude was declared as a double and I tried to cast to the int and vice versa. Code:
// Note 180 is used to scale up from semicircles to degrees
double lat = 55.55;
positionData.msgPosLat = (int)(lat/(BEARING_SCALING * 180));// and the other way for reading:-
lat = (double)( positionData.msgPosLat) * BEARING_SCALING * 180;
What is going wrong please, is it the oder of casting or do I need to use fix point stuff?
-
Passing a char array to a routineThanks I just tested this and it did not work. The size is always 1. Have I implemented it correct?
#define ARRAY_SIZE(_Array) (sizeof(_Array) / sizeof(_Array[0])) // This is the answer
char *OPTIONS1_ENUMS[4] = {"OPT_1", "OPT_2", "OPT_3", "OPT_4"};
char *OPTIONS2_ENUMS[2] = {"OPT_1", "OPT_4"};
char *OPTIONS3_ENUMS[1] = {"OPT_1234"};char* GetOptions(short enumValue, char** szOptions)
{
int i, nOptions;
short size;
nOptions = 1;
size = ARRAY_SIZE(szOptions);printf("Array Size = %d\\n", size); // do something with OPTIONS\_ENUMS\[j\]
}
// In the Main program call GetOptions() for 3 different sized arrays
GetOptions(1, OPTIONS1_ENUMS);
GetOptions(2, OPTIONS2_ENUMS);
GetOptions(3, OPTIONS3_ENUMS); -
Passing a char array to a routineThanks for your suggestion. But are they anyway I can find out the number of elements in an array like this:-
char *OPTIONS_ENUMS[4] = {"OPT_1","OPT_2","OPT_3","OPT_4"};
// Would this work
for(int j = 0; j < 100; j++)
{
if(OPTIONS_ENUMS[j] == NULL)
return j;
} -
Passing a char array to a routineI need to pass an array into a procedure and return a string. The problem is the array could be 1, 2, 3 or 4 character strings. I am stuck as how to do it, see typical arrays below.
char *OPTIONS_ENUMS[4] = {
"OPT_1",
"OPT_2",
"OPT_3",
"OPT_4"};char *OPTIONS2_ENUMS[4] = {
"OPT_1",
"OPT_4"};char* GetOptions(short nStatus, char* szOptions)
{
int i, nOptions;
// How can I tell how many elements in the array?
nOptions = sizeof(ssmStatusOptions); // This will not work
for(i=0; i < nOptions; i++)
{
if(nStatus == 0)
{
if(strcmp(szOptions[i], "NULL") == 0)
{
return "NULL";
}
else if(strcmp(szOptions[i], "ITEM1") == 0)
{
return "ITEM1";
}
else if(strcmp(szOptions[i], "NO_DATA") == 0)
{
return "NO_DATA";
}
}
else if(nStatus == 1)
{
if(strcmp(szOptions[i], "OK") == 0)
{
return "OK";
}
else if(strcmp(szOptions[i], "ITEM2") == 0)
{
return "ITEM2";
}
else if(strcmp(szOptions[i], "NO_DATA") == 0)
{
return "NO_DATA";
}
}
}
}How to call the procedure e.g.
GetOptions(1, OPTIONS2_ENUMS);
where OPTIONS2_ENUMS is
char \*OPTIONS\_ENUMS\[4\] = { "OPT\_1", "OPT\_2", "OPT\_3", "OPT\_4"};
I need to know how many elements in the array and how to pass over the array. Its a c code project. Many thanks.
-
Data Type ConversionsSorry Luc, as you may have noticed I am getting more confused, but think getting there from your last post. One field in this array was height which ranged from 0 to 10,000, but the LSB was 0.5, and the sign not used; e.g. bit 15 was data. So if you had 0000 0000 0000 1000 which is 8 then that represented 4 meters. I got this working and then turned to see why the heading and lat/long were not! But with heading which did use the sign and had a range of -1 to +1 and a very small LSB. May next question is are they a formula to handle these types of conversions. Just for a Windows platforn with the VS environment. Still need to sort out the two unsigned short Lat and Long.
-
Data Type ConversionsJust to recap and get things right in my mind; if a heading value is represented as an unsigned short (16 bits) with bit 1 = 0.000030517578125; so the range is -1 to + 1 and if we multiple by 180 we get -180 to +180 degrees - more useful Now for a test I set heading to 3.45 then the following occures. 3.45/0.000030517578125 = 1B999 in Hex; but as we can only store 16 bits in the unsigned short the debugger shows B999 as the value. Now when I come to decode that vaue via:- B999 * 0.000030517578125 = 1.44998169 which is wrong and if x 180 to get into degrees then get 260.99. Now for reading another value say, e.g. the value is 1234hex then we get:- 1234Hex * 0.000030517578125 = 0.14221191 and if we convert into degrees then get 0.14221191 * 180 = 25.598144 degrees. Hope this helps to explan what I am trying to do.
-
Data Type ConversionsSorry not made myself very clear. Forget about strings to floats thats OK. I need to cast from a float to a unsigned short using the information about the format about the unsigned short; e.g. top bit is sign, LSB is the scaling. Now if I run my code with a heading set to 3.45 this sets the unsigned short to 0xB999 which is not what I expected. Or looking at it the other way if the value of the unsigned short is 0x0001 then this would represent heading = (float)0x0001 * LSB. The messageData holds the data as unsigned shorts which need to be processed on Get and Set if that makes sense. For Lat and Long two elements are used, for heading just one.
-
Data Type ConversionsI have been trying to interface with a software program which uses a message made up of a 20 word array of unsigned shorts;
unsigned short messageData[20];
I have been trying to use data from a home GPS system which includes Lat and Long and heading.; these have been converted from strings to floats. e.g. float lat, long, heading; My problem is that as I know the scaling factors and least Sig Bit (LSB) for the lat, long and heading in the messageData buffer; e.g. For lat and long LSB = 8.377E-08; Twos complement - 32 bits Max/ Min -180 to +180 For Heading LSB 0.00549306; Twos complement - 16 bits Max/ Min -180 to +180 Setting the heading:- unsigned short heading = (unsigned short)(newHeading/0.00549306); messageData[10] = heading; Getting the heading:-
bool negative;
unsigned short currentField = messageData[10];
if(currentField & 0x8000)
{
// Set the negative flag
negative = true;
}
else
negative = false;
float heading = (currentField & 0x7FFF) * g_nScalings[wordPos];
if(negative)
heading = -(180 - heading);But this does not work as I expected; am I missing something? As for the 32 bit latitude, I was going to this:- Setting the Latitude:-
union
{
int lat_long;
unsigned short buff[2];
}convert;unsigned short highWord, lowWord;
int newData = (int)(fEngValue/8.377E-08);convert.lat_long = newData;
highWord = convert.buff[1];
lowWord = convert.buff[0];I need to get and set data in the message that is of type unsigned short and use in my program as scaled floats. Any suggestions please.