FEZ Domino Inquiry

You are saying no progress but also have a demo on reading files!

Did you start reading files before doing more basic things? I know you are excited to do it all the first 30 minutes but you should start simple… blink LED…print some debug messages…then you can copy/paste some of the example code in the free ebook.

Also, using ToString() on an array will return the array type and not the array contents so what you are seeing is correct. You can use VisualStudio debugging capabilities to see what is inside your byte array.

Actually, that code is from the Beginners guide on page 113. :stuck_out_tongue:

I’m reading the guide first then trying the Sample Codes and make little by little modifications after understanding them.

Maybe some more googling will solve this. :smiley:

EDIT: solved!! :slight_smile: This is why I love programming, there is always more than 1 way to solve a problem, lots of alternative.

I always get a System.OutOfMemoryException when trying to Filestream read a large file.

Anybody here who successfully read large files from the USB? Or atleast know how to divide the file into segments then clear the memory after reading that segment, then reading the next segment and so on.

You can read any large files of any size you like but you do not read the whole file in memory, instead read chunks of it. I would say you should never have more than 100 byte arrays if you do not know what you are doing.

For example, when we make an MP3 player, the songs are about 5MB in size. You do not read 5MB!!! Even if you are using a PC you shouldn’t read all 5MB. Instead, you read 100 bytes and send to the MP3 decoder then read the next 100 bytes and so no…

I’ve been trying to convert the received byte[] from the serial port to string. Using the code below, from the Guide(pg 76), only displays the decimal numbers of the character.

using System.Threading;
using System.IO.Ports;
using System.Text;
namespace MFConsoleApplication1
{
public class Program
{
public static void Main()
{
SerialPort UART = new SerialPort("COM1", 115200);
int read_count = 0;
byte[] rx_byte = new byte[1];
UART.Open();
while (true)
{
// read one byte
read_count = UART.Read(rx_byte, 0, 1);
if (read_count > 0)// do we have data?
{
// create a string
string counter_string = "You typted: " + rx_byte[0].ToString() + "\r\n";
// convert the string to bytes
byte[] buffer = Encoding.UTF8.GetBytes(counter_string);
// send the bytes on the serial port
UART.Write(buffer, 0, buffer.Length);
//wait...
Thread.Sleep(10);
}
}
}
}
}

Is there a way to convert byte to actual letters?

So I am not sure what your “error” is, if any. Didn’t try your code.

BUT: the byte actually IS the character.

You’ll get an ASCII letter in the byte. If you just want to add that to the string, can’t you just go:

counter_string = "You typted: " + rx_byte[0] + “\r\n”;

char c = (char)rx_byte[0];

hello

System.Text.Encoding enc = System.Text.Encoding.UTF8;
  string myString = new string(enc.GetChars(rx_byte));

mike’ answer is correct but if you want put that into a string you can’t implicitly convert from char to string.

cheers

[quote]hello

System.Text.Encoding enc = System.Text.Encoding.UTF8;
string myString = new string(enc.GetChars(rx_byte));

mike’ answer is correct but if you want put that into a string you can’t implicitly convert from char to string.

cheers [/quote]

It worked!! I only checked today cause of internet connection problems.

Thank you very much Corbal. :slight_smile:

Sorry mods if I used this forum for non-domino help. I just can’t find any better ACTIVE community forum that specialize in .NETMF.

Are you cheating and using our forum? B)

Just kidding…you are always welcome here