Exemplo n.º 1
0
        /// <summary>
        /// Write accepts data and calls back when a response is received. This is useful for
        /// writing a large block in chuncks. The user can specify an ofset and count and write
        /// ranges of the data.
        /// </summary>
        /// <param name="data">the data to send to the serial port</param>
        /// <param name="offset">the offset within the buffer to start writing from</param>
        /// <param name="count">the number of bytes to write</param>
        /// <param name="terminator">the character which signifies the end of the response.</param>
        /// <param name="responseSize">the expected size of the response in bytes if there's no terminator.</param>
        /// <param name="callback">called when a line of response is recieved</param>
        public void Write(Byte[] data, int offset, int count, char terminator,
                          int responseSize, OnDataRecievedDelegate callback)
        {
            // If the user expects a response, then save all the context parameters.
            if (callback != null)
            {
                _context                = new AsyncContext();
                _context.Data           = data;
                _context.Offset         = offset;
                _context.Count          = count;
                _context.Terminator     = terminator;
                _context.ResponseText   = null;
                _context.ResponseRaw    = new List <byte>();
                _context.ResponseSize   = responseSize;
                _context.CallerCallback = callback;
            }

            _serialPort.Write(data, offset, count);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Write accepts text and callsback when a response is received. It differs from the
 /// above in that there's no terminator to the response. It is fixed length.
 /// </summary>
 /// <param name="text">the data to send to the serial port</param>
 /// <param name="responseSize">the number of bytes in the response</param>
 /// <param name="callback">called when a line of response is recieved</param>
 public void Write(String text, int responseSize, OnDataRecievedDelegate callback)
 {
     byte[] data = Encoding.ASCII.GetBytes(text);
     Write(data, 0, data.Length, '\0', responseSize, callback);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Write accepts text and callsback when a response is received. This is useful
 /// for one shot writing of small blocks of text data.
 /// </summary>
 /// <param name="text">the data to send to the serial port</param>
 /// <param name="terminator">the character which signifies the end of the response</param>
 /// <param name="callback">called when a line of response is recieved</param>
 public void Write(String text, char terminator, OnDataRecievedDelegate callback)
 {
     byte[] data = Encoding.ASCII.GetBytes(text);
     Write(data, 0, data.Length, terminator, 0, callback);
 }