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.
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);
}
}
}
}
}