Java Arduino在不打开串行监视器的情况下从Python读取串行数据

Java Arduino在不打开串行监视器的情况下从Python读取串行数据,java,python,arduino,minecraft,Java,Python,Arduino,Minecraft,我正在为MineCraft编写一个mod,我有一个Python脚本将健康值传递给Arduino Uno。打印这些值会显示积极的结果。但是,Arduino不能正常工作,以免串行监视器打开,即使它显然接收到数据。我想知道是否有任何工作围绕这个利基 下面是Python: import serial #to open Serial port connected to Arduino import sys #to send arguments to Arduino ser = serial.Ser

我正在为MineCraft编写一个mod,我有一个Python脚本将健康值传递给Arduino Uno。打印这些值会显示积极的结果。但是,Arduino不能正常工作,以免串行监视器打开,即使它显然接收到数据。我想知道是否有任何工作围绕这个利基

下面是Python:

import serial   #to open Serial port connected to Arduino
import sys  #to send arguments to Arduino

ser = serial.Serial('/dev/ttyACM0', 9600)   #declares specific Serial port at 9600 baud rate
ser.write(str(sys.argv[1]))         #sends arguments to Arduino via Serial
发送至Arduino并由Arduino读取:

/*
    reads health from Serial input
    returns health as String
*/
String getHealth()
{
  String readHealth;

  readHealth = "";  //start empty String

  while(Serial.available())
  {
    delay(3);   //wait three milliseconds

    if(Serial.available() > 0)  //if there is Serial to read
    {
      char c = Serial.read();   //read the character
      readHealth += c;  //add the character to the String
    }
  }

  return readHealth;
}

/*
    takes in health read
    powers appropriate number of LEDs
    returns void
*/
void toLight(String readHealth)
{
  int health = readHealth.toInt();  //convert readHealth to integer

  for(int thisRed = 0; thisRed < ELEMENTS; thisRed++)   //for every LED
  {
    if(thisRed < health)    //turn on the LED if health is greater than index
    {
      digitalWrite(red[thisRed], HIGH);
    }
    else    //turn off the LED if health is less than or equal to index
    {
      digitalWrite(red[thisRed], LOW);
    }
  }
  return;
}

我让Java执行Python代码并将其作为参数传递。巨蟒继续将其传递给Arduino。Arduino成功读取值,将其转换为整数,并点亮适当数量的LED,但仅当串行监视器打开时。串行监视器经常打开有什么办法吗?

提供代码,没有可读的东西很难帮助。这有帮助吗@拉迪斯拉斯