I have a program that communicates to a device through the serial port. I am having difficulties with one section however. I am getting what looks like a right angle symbol when I run through the calculated hexadecimal commands. Here are the two sections of code (main section and function).
Main Section:
private: System::Void poll_Click(System::Object^ sender, System::EventArgs^ e)
{
int i, end;
double a = 1.58730159;
String^ portscan = "port";
String^ translate;
std::string portresponse [65];
std::fill_n(portresponse, 65, "Z");
for (i=0;i<63;i++)
{
if(this->_serialPort->IsOpen)
{
// Command 0 generator
int y = 2;
y += i;
std::string command0[10] = {"0xFF", "0xFF", "0xFF", "0xFF", "0xFF", "0x02", dectohex(i), "0x00", "0x00", dectohex(y)};
// The two "dectohex" values above is where I get the odd symbol
for (end=0;end<10;end++)
{
portscan = marshal_as<String^>( command0[end] );
this->_serialPort->WriteLine(portscan);
}
translate = (this->_serialPort->ReadLine());
MarshalString(translate, portresponse [i]);
if(portresponse [i] != "Z")
{
comboBox7->Items->Add(i);
}
this->progressBar1->Value=a;
a += 1.58730159;
}
}
}
Function:
string dectohex(int i)
{
string hexidecimal = "";
char hex_string[10] = "";
hexidecimal = sprintf (hex_string, "0x%02X", i);
return hexidecimal;
}
I am assuming that there is something fairly simple that I am missing. Any and all help is appreciated.
The solution: Per David Yaw's guidance.
string dectohex(int i)
{
char hex_array[10];
sprintf (hex_array, "0x%02X", i);
string hex_string(hex_array);
return string(hex_string);
}