关于C#串口接收单片机返回的反馈码

图中的串口测试工具可以接收到一条反馈码,我自己写的winform却接收不到,哪位大神了解串口工具的源码或者知道我的代码怎么改嘛,哪位大神指点一下,万分感谢!
int n = sc._serialPort.BytesToRead;
StringBuilder builder=new StringBuilder();
byte[] rec = new byte[n]; //新建一个接受数组
sc._serialPort.Read(rec, 0, n); //将串口接收到的数据写入接收数组
//sc.DataReceived(object sender, EventArgs e, rec);
builder.Append(Encoding.ASCII.GetString(rec));
这个是我自己写的,获取不到东西,还有一个是别人提供的写好的
public SerialPort _serialPort = null;
//定义委托
public delegate void SerialPortDataReceiveEventArgs(object sender, SerialDataReceivedEventArgs e, byte[] bits);
//定义接收数据事件
public event SerialPortDataReceiveEventArgs DataReceived;

            void _serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
    {
        if (DataReceived != null)
        {
            byte[] _data = new byte[_serialPort.BytesToRead];
            _serialPort.Read(_data, 0, _data.Length);
            DataReceived(sender, e, _data);
            //a += _data.Length;
            //rec += System.Text.Encoding.Default.GetString(_data)+_data.Length;
        }
    }
            可是这两种都接收不到东西,请大神指教一下我应该怎么改写这两个函数或者是怎样写

串口属于独占模式,同一时刻只能被一个程序打开。
你运行程序前关闭了测试工具没?

void _serialPort_DataReceived
这个是个事件,在串口有数据来的时候会触发,而你却在事件中把他当方法递归。代码不报错就已经很不错了。
重写接收事件 DataReceived。这个只管接收,或者接收到的赋值字符串/字符数组,里面不要做任何判断,声明byte数组、调用read接收....
private static void aSerialPor_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
int iByteLen = aSerialPor.BytesToRead;

        byte[] iBytes;
        if (IsGroup)
        {
            int iGroup = iByteLen / OneGroupSum;
            for (int i = 0; i < iGroup; i++)
            {
                iBytes = new byte[OneGroupSum];
                aSerialPor.Read(iBytes, 0, OneGroupSum);
                JsByteSum += OneGroupSum;
                ByteList.Enqueue(iBytes);
            }
        }
        else
        {
            iBytes = new byte[iByteLen];
            aSerialPor.Read(iBytes, 0, iByteLen);
            JsByteSum += iByteLen;
            ByteList.Enqueue(iBytes);
        }
    }
            别处考来的,大概这个样子