Hi eveybuddy,
This is the 1st time am posting my query. I am in need of help. Any help is appreciated.


As i agree that i have given my prob as long story. But am sorry i am not getting how to make it short and my intention is to give complete information regarding my prob.


Problem :
I have to communicate between two laptops using USB-to-Serial adapter. I have written 2 programs one for sending and another for receiving. Programs were written in C# programming language.

Using C# language :
Below two programs are written in C# using visual studio. I have used SerilaPort class , its properties and methods for communication. Using this, am able to communicate text and xml files on both the sides successfully.Also image files with .jpg extention, can be transferred from USB to serial end withot any loss of data(successful transmission), but if i transfer from serial to usb end, am able receive image with some data loss, even with the data loss am able to see the image.




Sender file on laptop with serial port :

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
using System.IO;
using System.Threading;


namespace Communication
{
    class Program
    {
        static void Main(string[] args)
        {


            string name;
            string message;
            StringComparer stringComparer = StringComparer.OrdinalIgnoreCase;
            //Thread readThread = new Thread(Read);




            FileStream fs = new FileStream("C:/text.xml", FileMode.Open);


            //StreamReader sr = new StreamReader(fs);


            BinaryReader br = new BinaryReader(fs);


            // Create a new SerialPort object with default settings.
            SerialPort _serialPort = new SerialPort();


            // Allow the user to set the appropriate properties.
            _serialPort.PortName = "COM1";
            _serialPort.BaudRate = 115200;
            _serialPort.Parity = Parity.None;
            _serialPort.DataBits = 8;
            _serialPort.StopBits = StopBits.One;
            _serialPort.Handshake = Handshake.None;


            // Set the read/write timeouts
            _serialPort.ReadTimeout = 500;
            _serialPort.WriteTimeout = 500;


            _serialPort.Open(); 
            bool _continue = true;
            //readThread.Start();


            int len = (int)fs.Length;
            char[] data = new char[len+1];


            br.Read(data, 0, len);


            for (int i = 0; i < len+1; i++)
            {
                _serialPort.Write(data, i, 1);
                //Console.Write(data,i,1);
            }


            br.Close();
            fs.Close();
            _serialPort.Close();


        }
    }
}

Receiver file on laptop with USB port :

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
using System.IO;
using System.Threading;
using System.Collections;


namespace Communication
{
    class Program
    {
        static void Main(string[] args)
        {
            SerialComm comm = new SerialComm();
            comm.Init();
            comm.ReadSerial();
            comm.WriteToFile();
            comm.ResClose();
            Console.ReadKey();
        }
    }




    class SerialComm
    {
        FileStream fs = null;
        BinaryWriter file = null;
        ArrayList al = null;


        public Boolean Init()
        {
            if (fs == null)
            {
                fs = new FileStream("C:/text1.txt", FileMode.OpenOrCreate);
            }


            if (file == null)
            {
                file = new BinaryWriter(fs);
            }
            if (al == null)
            {
                al = new ArrayList();
            }


            return true;
        }


        public void ResClose()
        {
            file.Close();
            fs.Close();
        }
        


        public Boolean ReadSerial()
        {
            SerialPort port;
            StreamWriter sw;
            ConsoleKeyInfo ck;


            port = new SerialPort();


            port.PortName = "COM4";
            port.BaudRate = 115200;
            port.DataBits = 8;
            port.Parity = Parity.None;
            port.StopBits = StopBits.One;
            port.Handshake = Handshake.None;


            port.Open();


            port.BaseStream.Flush();
            port.DiscardInBuffer();
            int c = 1;
            while (c != 0)
            {
                c = port.ReadByte();
                al.Add((byte)c);
            }
            return true;
        }


        public void WriteToFile()
        {
            int i = 0;
            byte[] message = al.ToArray(typeof(byte)) as byte[];
            file.Write(message, 0, message.Length - 1);
        }
   }
}

Please help me.


Thanks in advance.