从usb raspberry pi读取数据(无头模式)

时间:2016-07-15 13:22:31

标签: c# windows iot datareader serial-communication

我正在尝试使用数据读取器对象从USB设备读取数据。 代码是

public async void Run(IBackgroundTaskInstance taskInstance)
    {

        deferral = taskInstance.GetDeferral();
        await config();
        await WriteAsync();
        while(true)
        await ReadAsync()
        deferral.Complete();

    }
async Task config()
{
  ....
}
 async Task WriteAsync()
{
  ....
}

 async Task ReadAsync()
{
  try
        {

            dataReaderObject = new DataReader(serialPort.InputStream);

            var bytesRead = await dataReaderObject.LoadAsync(1);
            if (bytesRead > 0)
            {

                string a = dataReaderObject.ReadString(bytesRead).Trim();
                byte[] pass_byte = Encoding.ASCII.GetBytes(a);
                Debug.WriteLine(pass_byte[0]);


            }
        }
        catch (Exception e)
        {
            Debug.WriteLine("exception in read async", e);
        }

}

我能够按预期获得数据,但在此之后的一段时间内,它会引发异常。 它显示了arguments out of range exception and SEHE exception

等异常

0 个答案:

没有答案