Я использую последнюю общедоступную версию Windows 10 IoT 17763.253, и у меня возникают проблемы при чтении с датчика i2c Co2.
Кажется, это не проблема для других датчиков.
Время от времени он калечат последние два символа utf8, например, 1126 отображается как 11 \, где последние 1/2 - это один символ UTF8.Во многих случаях там также появляется символ «Замена алмазного вопросительного знака».
Есть идеи как это исправить?Я использую последнюю версию vs2019, Raspberry Pi 3 и Windows 17763.253
Код:
using System;
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Windows.Devices.I2c;
public string GetReading()
{
try
{
byte[] i2CReadBuffer = new byte[20];
_device.Read(i2CReadBuffer);
Task.Delay(300).Wait(); //MXu
string answer_string = "";
bool got_error = false;
int bufsize = i2CReadBuffer.Length;
for(int i =0;i<bufsize;i++)
{
Debug.WriteLine(i2CReadBuffer[i].ToString("X"));
}
Debug.WriteLine("");
switch (i2CReadBuffer[0]) //first character denotes I2C reception status
{
case 1:
i2CReadBuffer[0] = 0;
answer_string = Encoding.UTF8.GetString(i2CReadBuffer).Replace("\0", string.Empty);
// does it match ?L,1 .... if so , makegot_error to true, even though it isn't an error.
Regex regex = new Regex(@"\\?L,[0-9]*,?T?");
Match match = regex.Match(answer_string);
if (match.Success)
{
got_error = true;
}
break;
case 2:
case 254:
case 255:
default:
got_error = true;
break;
}
Наш датчик: https://www.atlas -scientific.com / _files / _datasheets/_probe/EZO_CO2_Datasheet.pdf