Using Executable or Batch File as serial input

I currently have a program where it will open an executable file upon an event happening, in this case, I want to switch LED animations. I am using the library FastLED for this.
The process is the executable/batch file opens, sends a int value to the arduino, then arduino will select the animation based on the int value received. So functionally, the LED strip should hold the last value received and play that animation until another value is received.

This is the code I am currently using, although it works fine using the serial monitor, it has problems when receiving from other sources. (This is only the important bit.) For this test, I am using two variables, 1 and 2. 1 will cause a rainbow to appear on the LED strip, while 2 will cause it to go black.

  if (Serial.available() > 0) {
 inByte = Serial.read();
  }

  switch (inByte){
     case '1':
     fill_rainbow( leds, NUM_LEDS, gHue, 7);
     break;
  case '2':
      leds[0] = CRGB::Black;
      break;
  }

}

The best, and most simple way (or so it appears) is currently by using a batch file on command prompt that does the following, sending to COM3, the port the adrunio is on.

echo 1 > COM3

However, this does not work. It will successfully send, but the LED strip turns off completely and only plays the first frame of the animation. Other methods I tried were using macro terminals, such as teraterm, which worked when using the terminal, but the macro didn’t.

So, a few questions:

Is there an easy way to get an executable/batch to do a key then send it to the adruino, and hold the value? Is it a problem with my code? Reminder, it works with the serial monitor, but does not with other sources.

Secondly, it is also possible for me to use IPC protocol (CLP, named or pipe), but I have not found any programs that would accept the IPC protocol and then send the correct byte to serial.

Thirdly, although I seriously doubt it, could anybody provide a teraterm macro that would connect to a COM3 then send a simple byte?

That’s all, thanks. I am open to any other suggestions. As long as it is an EXE, BATCH or allows IPC protocol, it will work.

skeeveo:
I currently have a program where it will open an executable file upon an event happening, in this case, I want to switch LED animations. I am using the library FastLED for this.
The process is the executable/batch file opens, sends a int value to the arduino, then arduino will select the animation based on the int value received.

I presume you mean you "currently have a PC program where it will ..."

There is no problem having a PC program send data to an Arduino. However in the normal way when a PC program opens the serial port it causes the Arduino to reset so it is better for the PC program to keep the serial port open until it is completely finished with the Arduino.

This Python - Arduino demo may give you some ideas. The same principles apply for any programming language. And I think the Python demo will work on Windows if you edit it to use the appropriate serial port name.

...R

Is it a problem with my code? Reminder, it works with the serial monitor, but does not with other sources.

If it works with the Serial monitor then there is no reason why it should not work with other sources of serial data as long as they behave the same way. When a serial device connects to an Arduino, or at least most board types, the board reboots. Are you sure that is not what is happening ?

What line ending do you have set in the Serial monitor ? Are the other sources of serial data sending the same line ending ? What do you see if you print inByte ? A tip - print something visible, such as < and > either side of it so that you can see “invisible” characters

For this test, I am using two variables, 1 and 2.

Pssst. 1 and 2 are constants. The values are stored in the variable named inByte (which better be a byte).

Using CMD is not an option, I have realized now that it is resetting the arduino the connection whenever it runs. SO the only solution is to have a program that connects to the serial port, then receives input via IPC. The IPC will send the data 1... 2... and so on, based on the event it receives, and the program should send that value to the arduino board.

Unfortunately for me, I cannot wrap my head around python or named pipe inputs. Does anybody know the most simple way to receive from IPC and then send to a comport?

skeeveo:
I cannot wrap my head around python or named pipe inputs. Does anybody know the most simple way to receive from IPC and then send to a comport?

Python is straightforward and I posted a link to a working program. What is IPC ?

...R

skeeveo:
I have realized now that it is resetting the arduino the connection whenever it runs.

You need to disable auto-reset.