Beispiel #1
0
 protected BaseProvider()
 {
     _writeBuffer  = new ByteList();
     _readBuffer   = new ByteList();
     _timeout      = 2000;
     _abort        = false;
     _pollInterval = 10;
 }
Beispiel #2
0
        /// <summary>
        /// Sends a chunk of firmware data to Blaze
        /// </summary>
        /// <param name="blaze"></param>
        /// <param name="index"></param>
        /// <param name="chunk"></param>
        /// <returns></returns>
        public static bool WriteFirmwareChunk(Blaze blaze, ushort index, List <byte> chunk)
        {
            ByteList data = new ByteList();

            data.AddUInt16(index);
            data.AddRange(chunk);

            return(blaze.Write(BlazeCommand.WriteFirmwareChunk, data.ToArray()));
        }
Beispiel #3
0
 public Blaze()
 {
     _provider = new SerialProvider();
     _provider.DataReceived += new EventHandler(OnDataReceived);
     _replyReceived          = new AutoResetEvent(false);
     _provider.PortName      = "COM1";
     _provider.BaudRate      = 115200;
     _checksum   = new CCITT();
     _dataBuffer = new ByteList();
 }
Beispiel #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="blaze"></param>
        /// <returns></returns>
        public static bool TestCommand(Blaze blaze)
        {
            // Send some dummy bytes to Blaze for testing
            ByteList data = new ByteList();

            data.Add(0x11);
            data.Add(0x22);
            data.Add(0x33);
            data.Add(0x44);

            return(blaze.Write(BlazeCommand.TestCommand, data.ToArray()));
        }
Beispiel #5
0
        internal bool Write(BlazeCommand command, params byte[] data)
        {
            ByteList byteList = new ByteList();
            ushort   length   = 0;

            if (data != null)
            {
                length = (ushort)data.Length;
            }

            // Add a '$' sync character
            byteList.Add(36);
            byteList.Add((byte)command);
            byteList.AddUInt16(length);

            if (length > 0)
            {
                byteList.AddRange(data);
            }

            ushort csum = 0;

            if (_checksum != null)
            {
                // Don't count the
                csum = _checksum.Calculate(byteList, 0, byteList.Count);
            }

            byteList.Add((byte)(csum >> 8));
            byteList.Add((byte)csum);

            byteList.TrimExcess();

            _replyReceived.Reset();

            _startTime = Environment.TickCount;

            if (_dataBuffer != null)
            {
                _dataBuffer.Clear();
            }

            _provider.Write(byteList);

            bool flag = _replyReceived.WaitOne(_provider.Timeout);

            _endTime = Environment.TickCount;

            return(flag);
        }
Beispiel #6
0
 public void Write(ByteList buffer)
 {
     Write(buffer.ToArray());
 }