Java Simple Serial Connectorを使用して、コンピューターとarduino unoを接続しようとしています。以下にリストされているコードを使用してそれを実行しようとしています。どういうわけか機能していません(arduinoのピン7に接続されたLEDダイオードは、プログラムの実行中にオンになりませんが、artuinoソフトウェアのシリアルモニターを使用している場合はオンになります。)。誰かが理由を知っていますか?
Java プロジェクト コード:
import jssc.SerialPort;
import jssc.SerialPortException;
public class Main {
public static void main(String[] args) {
//In the constructor pass the name of the port with which we work
SerialPort serialPort = new SerialPort("COM3");
try {
//Open port
serialPort.openPort();
//We expose the settings. You can also use this line - serialPort.setParams(9600, 8, 1, 0);
serialPort.setParams(SerialPort.BAUDRATE_9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
//Writes data to port
serialPort.writeBytes("Test".getBytes());
//Closing the port
serialPort.closePort();
}
catch (SerialPortException ex) {
System.out.println(ex);
}
}
}`
Arduino コード:
void setup() {
Serial.begin(9600); //Ustawienie prędkości transmisji
pinMode(7, OUTPUT);
digitalWrite(7, LOW);
}
void loop() {
if( Serial.available() > 0){
digitalWrite(7, HIGH);
}
}