1

Is there a way to show a byte array on the NXTscreen (using NXC)?

I've tried like this:

unsigned char Data[];
string Result = ByteArrayToStr(Data[0]);
TextOut(0, 0, Result);

But it gives me a File Error! -1.

If this isn't possible, how can I watch the value of Data[0] during the program?

Mateen Ulhaq
  • 24,552
  • 19
  • 101
  • 135

2 Answers2

1

If you want to show the byte array in hexadecimal format, you can do this:

byte buf[];
unsigned int buf_len = ArrayLen(buf);

string szOut = "";
string szTmp = "00";

// Convert to hexadecimal string.
for(unsigned int i = 0; i < buf_len; ++i)
{
    sprintf(szTmp, "%02X", buf[i]);

    szOut += szTmp;
}

// Display on screen.
WordWrapOut(szOut,
            0, 63,
            NULL, WORD_WRAP_WRAP_BY_CHAR,
            DRAW_OPT_CLEAR_WHOLE_SCREEN);

You can find WordWrapOut() here.


If you simply want to convert it to ASCII:

unsigned char Data[];
string Result = ByteArrayToStr(Data);
TextOut(0, 0, Result);

If you only wish to display one character:

unsigned char Data[];
string Result = FlattenVar(Data[0]);
TextOut(0, 0, Result);
Mateen Ulhaq
  • 24,552
  • 19
  • 101
  • 135
0

Try byte. byte is an unsigned char in NXC.

P.S. There is a heavily-under-development debugger in BricxCC (I assume you're on windows). Look here.

EDIT: The code compiles and runs, but does not do anything.

Mateen Ulhaq
  • 24,552
  • 19
  • 101
  • 135
Tim
  • 834
  • 2
  • 12
  • 31