Hello. I'm a total noob to C++ and MFC, I've been teaching myself from books and it's not going too well. I've been asked to create a test application for a controller. The controller consists of six joysticks connected to a digital I/O board that's connected via USB.
I managed to write C++ code for it that simply outputs whether or not a joystick was pushed to the command line but my supervisor (I'm a student on work term) has asked that it been MFC instead.
This is my C++ code, I realize it's probably breaking every programming practice ever, I'm used to working with Java and I'm having a hard time wrapping my head around classes in C++ and therefore opted not to use them. So this is basically a big ol 'what can I do to make it work' sort of deal. Not exactly elegant coding.
What I would like to do it translate this basic idea into MFC but I'm not really sure how to start. Not sure if it should be a dialog application or SDI or if I should use timers, or threads or what have you. I'm really just overwhelmed by the whole thing and I'm not ever sure I could convey that to my supervisor properly.
Any help would be great. Thanks.
ETA: Perhaps also relevant :D I'm using Visual Studio 2008 on windows XP. It's also my first foray into Visual Studio.
ETA2: Also relevant! What'd I need this program to do. It needs to continuously read the digital board and when the value changes from 0 to 1 it needs to output that value to the display. Or some indication that the value has changed.
#include <iostream>
#include <conio.h>
#include <C:\Program Files\Measurement Computing\DAQ\C\cbw.h>
using namespace std;
int main()
{
int BoardNum = 0;
int PortNum = FIRSTPORTA;
int PortType = FIRSTPORTA;
int Direction = DIGITALIN;
USHORT BitValue;
USHORT bitValue = 0;
int LastCase = 0;
int BitNum = 0;
cout << "Configuring Ports, please wait!\n";
/*CONFIGURES PORTS AS INPUT ON ALL BOARDS*/
for(int i = 0; i < 8; i++)
{
if(BoardNum < 2)
{
cbDConfigPort(BoardNum, PortNum, Direction);
PortNum++;
if(i == 3)
{
BoardNum++;
PortNum = FIRSTPORTA;
}
}
}
/*LED OUTPUTS ON PORT B*/
cbDConfigPort(1,FIRSTPORTB, DIGITALOUT);
/*LINK LED IS ON WHEN USB IS CONNECTED*/
cbDBitOut(1, FIRSTPORTA, 9, 1);
cout << "Link LED!!\n";
cout << "\n";
/*LOOPS THROUGH AND DISPLAYS RESPONSES FROM BOARDS*/
while(!_kbhit())
{
BoardNum = 0;
for (BitNum = 0; BitNum < 24; BitNum++)
{
//THIS IS THE CODE THAT READS THE DIGITAL PORTS ON THE BOARD
cbDBitIn(0, FIRSTPORTA, BitNum, &BitValue);
if(BitValue == 1)
{
cout << "BoardNum: " << BoardNum << "\n";
cout << "Bit Num: " << BitNum << "\n";
cout << "Joystick was pushed\n";
cout << "\n";
}
}//END OF BOARD ZERO FOR LOOP
//THE SECOND DIGITAL BOARD CONTROLS POWER SWITCHES AND LEDS
for(BitNum = 0; BitNum < 8; BitNum++)
{
BoardNum = 1;
cbDBitIn(1, FIRSTPORTA, BitNum, &BitValue);
switch(BitNum)
{
case 0:
if(BitValue == 0)
{
cout << "Board Num: " << BoardNum << "\n";
cout << "Bit Num: " << BitNum << "\n";
cout << "Switch is On!\n";
cout << "\n";
}
break;
case 1:
if(BitValue == 0)
{
cout << "Board Num: " << BoardNum << "\n";
cout << "Bit Num: " << BitNum << "\n";
cout << "Switch is On!\n";
cout << "\n";
}
break;
case 2:
if(BitValue == 0)
{
//if(LastCase == 2)
// break;
// else
cbDBitOut(1, FIRSTPORTA, 8, 0);
//LastCase = 2;
}
break;
case 3:
if(BitValue == 0)
{
// if(LastCase == 3)
// break;
//else
cbDBitOut(1, FIRSTPORTA, 8, 1);
//LastCase = 3;
}
break;
case 4:
if(BitValue == 0)
{
//if(LastCase == 4)
// break;
// else
cbDBitOut(1 , FIRSTPORTA, 8, 0);
// LastCase = 4;
}
break;
case 5:
if(BitValue == 0)
{
//if(LastCase == 5)
// break;
//else
cbDBitOut(1 , FIRSTPORTA, 8, 1);
//LastCase = 5;
}
break;
case 6:
if(BitValue == 0)
{
cout << "Board Num: " << BoardNum << "\n";
cout << "Bit Num: " << BitNum << "\n";
cout << "Switch is On!\n";
cout << "\n";
}
break;
case 7:
if(BitValue == 0)
{
cout << "Board Num: " << BoardNum << "\n";
cout << "Bit Num: " << BitNum << "\n";
cout << "Switch is On!\n";
cout << "\n";
}
break;
default: break;
}
}//END OF BOARD ONE FOR LOOP
}//END OF WHILE LOOP
//TURNS OFF LED's
cbDBitOut(1, FIRSTPORTA, 9, 0);
cbDBitOut(1, FIRSTPORTA, 8, 0);
}