我试图将值存储到int
对象中,但是serialPort.ReadLine()
正在挂断(花费很长时间执行)。有没有办法我可以使用try-catch
块或类似于测试的东西?
private void resetPos()
{
serialPort.Write("getCurrXpos");
int currX = Convert.ToInt32(serialPort.ReadLine());
serialPort.Write("getCurrYpos");
int currY = Convert.ToInt32(serialPort.ReadLine());`
if (currX == 0 && currY == 0)
{
}
else if (currX == 0 || currY == 0)
{
serialPort.Write("reset");
serialPort.ReadLine(); serialPort.ReadLine();
currXpos.Text = "0"; currYpos.Text = "0";
}
else
{
serialPort.Write("reset");
serialPort.ReadLine(); serialPort.ReadLine();
serialPort.ReadLine();
currXpos.Text = "0"; currYpos.Text = "0";
}
}