Serial xfer of data

Status
Not open for further replies.

Mosaic

Well-Known Member
I am learning about rs232 xfer to PICs etc. So far i can achieve it via the max232 level shifter.

I'd like a procedure to read a text file in windows and transfer it serially out to the PIC.Hopefully in a manner that will permit 'looping' the file continuously. Kinda like how you can do it with a play list.


The intention is to have long scrolling messages that can be looped.

Need some help with this..
 
Here's a procedure in C# to send a text file continuously out the serial port:
Code:
static bool cancel = false;
        static void sendFile(string fileName, string portName, int baudRate, int lineDelay)
        {
            using (SerialPort serialPort = new SerialPort(portName, baudRate))
            {
                StreamReader stream = new StreamReader(new MemoryStream(File.ReadAllBytes(fileName)));

                serialPort.Open();
                while (!cancel)
                {
                    stream.BaseStream.Seek(0, SeekOrigin.Begin);    // start from the beginning

                    while (!stream.EndOfStream)
                    {
                        string line = stream.ReadLine();
                        if (line != null)
                        {
                            serialPort.Write(line);
                            System.Threading.Thread.Sleep(lineDelay);
                        }
                    }
                }
                serialPort.Close();
            }
        }
 
Ok, would that use RTS/CTS...? i'd need the PIC to handle flow control.

It really depends on exactly what you're doing, flow control is only required if you're sending data faster than it can be handled at the receiving end.
 
Ok, would that use RTS/CTS...? i'd need the PIC to handle flow control.

If you want to use rts/cts (hardware) flow control, specify
Code:
port.Handshake = Handshake.RequestToSend;
before you open it.
 
Any suggestions for a wireless serial solution...say 300 feet range?

Either use modules with built-in encoding/decoding, in which case you just feed them standard serial (RS232 style), or write your own Manchester routines, you can't generally send just plain serial over a radio link.

Check my tutorials for an example.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…