Exemplo n.º 1
0
        public override void DoProcess(BpXsvfParameterData p)
        {
            IOutDisplay         ioutdisp  = mIoutdisplay;
            BpXsvfParameterData paramdata = p;
            SerialPort          serialport;
            string filePath = paramdata.XsvfFilePath;

            byte[] byteRead = null;

            if (String.IsNullOrEmpty(filePath) == false)
            {
                filePath = filePath.Trim();
                if (File.Exists(filePath) == true)
                {
                    // File process
                    byteRead = File.ReadAllBytes(filePath);
                    ioutdisp.Display("Number of bytes: " + byteRead.Length);
                }
                else
                {
                    return;
                }
            }
            else
            {
                return;
            }

            ioutdisp.Display("Opening COM");
            serialport = new SerialPort(paramdata.ComName, paramdata.ComBaudRate, Parity.None, 8, StopBits.One);


            try
            {
                serialport.ReadTimeout = 500;

                if (serialport.IsOpen == false)
                {
                    serialport.Open();
                }

                SerialPortDelegateWriteOneByte serPortWriteByteDelegate = delegate(byte data)
                {
                    serialport.Write(new byte[] { data }, 0, 1);
                };


                if (paramdata.ResetJtag)
                {
                    ioutdisp.Display("Reset");
                    serPortWriteByteDelegate(AbstractBpXsvf.JTAG_RESET);
                    Thread.Sleep(10);
                }

                // ChainScan TODO

                // XSVF Process
                ioutdisp.Display("Entering XSVF player mode");
                serPortWriteByteDelegate(AbstractBpXsvf.XSVF_PLAYER);

                const int BUFF_SZ = 4096;

                byte [] readbuffer = new byte[BUFF_SZ + 50];
                int     res;

                int fileSize    = byteRead.Length;
                int readSize    = BUFF_SZ;
                int bytePointer = 0;
                int cnt         = 0;

                while (true)
                {
                    res = serialport.Read(readbuffer, 0, BUFF_SZ);

                    if (res > 0)
                    {
                        if (readbuffer[0] != AbstractBpXsvf.XSVF_READY_FOR_DATA)
                        {
                            ioutdisp.Display("Error! Code: " + (int)readbuffer[0]);
                        }
                        else
                        {
                            if (fileSize == 0)
                            {
                                break;
                            }

                            if (fileSize < BUFF_SZ)
                            {
                                readSize = fileSize;
                            }

                            byte[] tempSend = new byte[2];
                            tempSend[0] = (byte)(readSize >> 8);
                            tempSend[1] = (byte)(readSize);
                            cnt        += readSize;
                            ioutdisp.Display(String.Format("Sending {0:d} Bytes {1:x04}", readSize, cnt));
                            serialport.Write(tempSend, 0, 2);
                            serialport.Write(byteRead, bytePointer, readSize);

                            bytePointer += readSize;
                            fileSize    -= readSize;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                ioutdisp.Display(" Thank you for playing!");
            }
            finally
            {
                if (serialport.IsOpen)
                {
                    serialport.Close();
                }

                serialport.Dispose();
            }
        }
Exemplo n.º 2
0
        //protected BpXsvfParameterData mParamData;

        //public void SetSerialPort(SerialPort s)
        //{
        //    mSerial = s;
        //}

        public void SetOutDisplay(IOutDisplay i)
        {
            mIoutdisplay = i;
        }