Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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.

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.

Latest threads

New Articles From Microcontroller Tips

Back
Top