В полученном событии данных serialport говорится, что операция ввода / вывода была прервана из-за выхода из потока или запроса приложения - PullRequest
1 голос
/ 04 апреля 2020

Я интегрирую VS и Arduino IDE вместе для моего проекта Iot. Я должен прочитать данные и отобразить их в VS IDE .. что я могу. считываются только первые 3 значения, а не остальные 3, внутри события последовательных данных, полученных. Раньше я мог читать данные, но не отображать их. Ошибка, которую я получил, была перекрестная обработка, которую я исправил с помощью делегата. Теперь я не умею читать. Исключение: System.IO.IOException: «Операция ввода-вывода была прервана из-за выхода из потока или запроса приложения.

VS Code

private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            Microsoft.VisualBasic.Interaction.MsgBox("dfghjk");

            moist = serialPort1.ReadLine();  //can read
            temper = serialPort1.ReadLine(); //can read
            humid = serialPort1.ReadLine();  //can read

            SetTextMo(moist);   //can set
            SetTextTe(temper);//can set
            SetTextHu(humid);//can set

            resMois = serialPort1.ReadLine();  //cannot read (exception mentioned above occurs)
            resTemp = serialPort1.ReadLine();  //cannot read (exception mentioned above occurs)
            resHumi = serialPort1.ReadLine();  //cannot read (exception mentioned above occurs)


            SetTextResM(resMois); //can set
            SetTextResT(resTemp);//can set
            SetTextResH(resHumi);   //can set
        }
Arduino Code

void loop() 
{    
    if(a == 0)
    {
      if(Serial.available() > 0) 
        {
            mySt = Serial.readString();
            i = mySt.toInt();
            if (i==1) 
            {
                checkCurrentValue();//works perfect
                suitablePlant();//works perfect
                a++;
            }  
            else if(i==2)
            {
                crop = Serial.readString();
                checkCurrentValue();//values of the data i can read belong too this function
                checkParameters();//values of data belonging to this function i am unable to read 
                a++;
            } 
            else{}
        }
   }                    
}
...