Go to Post Coaxial swerve modules with a suspension and differential aren't normal. But on Winnovation they are. - Andrew Schreiber [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 27-02-2011, 13:49
KART35 KART35 is offline
Registered User
FRC #1622 (Team Spyder)
Team Role: Electrical
 
Join Date: Jan 2011
Rookie Year: 2009
Location: Poway, CA
Posts: 5
KART35 is an unknown quantity at this point
Custom data gathering class crashes user program

Hi, I'm having a bit of trouble with a class I wrote, it appears to be crashing the user program as soon a VxWorks attempts to launch it. I'm not sure what part of it is crashing it either, but i have tried commenting out everything in its Get(); member so the only thing left was a return 0; statement to see if that was the problem, so I'm assuming its the constructor.

The way the code is meant to work is gather bits from three dip switches, and then translate that binary sequence into a more usable decimal number.

this is how I have been calling the constructor and destructor. I have tried not using an object pointer, but i still had the same problem.
Code:
switchbox *box = new switchbox(10, 9, 8);
int mode2= box->Get(); 
box->~switchbox();
and this is the class:
Code:
class switchbox {
public:
	int Get();
	switchbox(int port1, int port2, int port3);
	virtual ~switchbox();
private:
	bool port1;
	bool port2;
	bool port3;
	int mode;
	int bin2dec(bool bit[3]);
	bool readPorts(int port);
};

 bool switchbox::readPorts(int port)//this gets the input values from the program switchbox
{
	DigitalInput *digital = new DigitalInput(port);
	bool port_ = false;
	port_ = digital->Get();
	digital->~DigitalInput();
	return port_;
}

 int switchbox::bin2dec(bool bit[3])//this is a 3 bit binary to decimal converter. 
{ //to be used for the program switchbox.
	int num=0;

	if (bit[1]) {
		num=num+1;
	}
	if (bit[2]){
		num=num+2;
	}
	if (bit[3]) {
		num=num+4;
	}
  return mode = num; //member functions can access private data, doing this to hopefully not need another int.
}


 int switchbox::Get(){
	 bool bit[3];
	for( int i=0; i<=3; i++){
		bit[i] = switchbox::readPorts(i);
	}
	bin2dec(bit);
	
	return mode;
}
thanks to anyone who can help with this!
__________________

Last edited by KART35 : 27-02-2011 at 13:51.
Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 17:43.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi