ashmanq
February 29th, 2008, 06:04 AM
I have a list of commands in hex format e.g {0x4D, 0x01, 0x01, 0x01}; and i need to send these commands over a tcp connection to a robot when a button is pressed on teh console to control the robot. How can you have a list of byte array commands saved in a header file? Whenever I try to do this it says : global or static variable may not have managed type 'cli::array<Type> ^'. Is it possible to save these commands in an int array of some sort and then translate them into byte arrays before sending them over the network? I dont want to save them as their string equivelant because there are no ASCII characters that represent negative values or are there?
darwen
March 1st, 2008, 02:59 PM
You are probably declaring the array in a .h file outside a class. In .NET all static variables have to be members of classes so you have to do something like :
public ref class Globals sealed abstract
{
public:
property static array<unsigned char> ^Command
{
static array<unsigned char> ^get()
{
return _command;
}
}
private:
static const int ArraySize = 20;
static array<unsigned char> ^_command = gcnew array<unsigned char>(ArraySize);
} ;
int main(array<System::String ^> ^args)
{
// how to use
array<unsigned char> ^command = Globals::Command;
return 0;
}
The property is to maintain encapsulation of the variable : you shouldn't expose variables as public in 99.9999% of cases.
Darwen.