示例#1
0
        public void SerialExceptionOnReadTest()
        {
            var ss = new SerialSettings("COM0");

            using (var sp = new SerialProcess(ss))
            {
                Assert.Throws <SerialException>(() =>
                {
                    sp.Read(-1, -1, 200);
                });
            }
        }
示例#2
0
        public void EofExceptionOnReadTest()
        {
            var ss = new SerialSettings("COM98");

            using (var sp = new SerialProcess(ss))
            {
                Process.GetProcessById(sp.Pid).Kill();
                Assert.Throws <EndOfStreamException>(() =>
                {
                    sp.Read(-1, -1, 200);
                });
            }
        }
        public int Read(byte[] data)
        {
            var response = serialProcess.Read(data.Length, -1, timeout);
            var count    = response.Length;

            for (var i = 0; i < count; i++)
            {
                data[i] = response[i];
            }
            if (monitor != null)
            {
                monitor('<', data, count);
            }
            return(count);
        }