How to properly simulate a terminal program

I have used Arduino Nano, Mega, Teensy 3.1, and with no luck so far. I am trying to simulate a terminal program like on a windows computer. Ex Putty/TeraTerm.

I am using softwareSerial, AltSerial, and I cannot get it to work. Using the code they provide to simulate a COM port, it looks like it is passing the serial data 1 char at a time. Is there a way to add a whole string at a time? So in putty, you type in your command to serial, then hit Enter. I am trying to simulate that from PC to Arduino then to a softwareSerial.

Thanks for the help!

I am trying to simulate that from PC to Arduino then to a softwareSerial.

What software do you have running on the PC ?

brolly759:
I have used Arduino Nano, Mega, Teensy 3.1, and with no luck so far. I am trying to simulate a terminal program like on a windows computer. Ex Putty/TeraTerm.

Program running on what? What do you mean, simulates a COM port?

brolly759:
I am using softwareSerial, AltSerial, and I cannot get it to work. Using the code they provide to simulate a COM port

code that who provides?

brolly759:
, it looks like it is passing the serial data 1 char at a time. Is there a way to add a whole string at a time? So in putty, you type in your command to serial, then hit Enter. I am trying to simulate that from PC to Arduino then to a softwareSerial.

If the Arduino is just a pass-through, why would it matter if lines were buffered or just passed on, as they are received?

brolly759:
Thanks for the help!

Not much info there, sorry!

Here is the code:

#include <AltSoftSerial.h>
AltSoftSerial altSerial;

void setup() {
  Serial.begin(9600);
  while (!Serial) ; // wait for Arduino Serial Monitor to open
  Serial.println("AltSoftSerial Test Begin");
  altSerial.begin(9600);
  altSerial.println("Hello World");
}

void loop() {
  char c;

  if (Serial.available()) {
    c = Serial.read();
    altSerial.print(c);
  }
  if (altSerial.available()) {
    c = altSerial.read();
    Serial.print(c);
  }
}

I am trying to pass through Serial data not 1 byte at a time but as a buffer with the return carriage added.

Here is my setup: PC-> Arduino/Teensy->softwareSerial->COM Port (115200) on a product that I purchased that takes serial commands through a serial program on the PC.

I'm still puzzled. Surely the serial program sends a newline character at the end of the line? Why not just use something like "SoftwareSerialExample" from the example folder in the IDE, which just passes characters both ways?
Edit - Oh, I see you already are...

What is so important about buffering the line and sending at all at once?

Is it possible you have just failed to configure your terminal program to send a newline?

Finally, how do you know that the product you bought is working? What is it? :slight_smile:

I am trying to pass through Serial data not 1 byte at a time but as a buffer with the return carriage added.

Serial data is sent one character at a time, regardless of what is sending the data.

If you want to collect the data that you receive, and send it out again under a different schedule, you are free to do just that, one character at a time.

If you are going to do that, what defines the boundary of the data to collect? What defines when to send it out again?

PaulS:
If you are going to do that, what defines the boundary of the data to collect? What defines when to send it out again?

Sorry to speak for the OP, but I think it's the newline character.

Sounds to me like he just wants to do line-buffering on the Tx data from the Arduino....

Regards,
Ray L.

RayLivingston:
Sounds to me like he just wants to do line-buffering on the Tx data from the Arduino....

Regards,
Ray L.

Yes, but I'm wondering if it's an XY problem.

Was in a meeting, sorry! So when I plug a real USB to Serial cable into the COM Port on the "device". (115200 Baud) I can send a command for example, "ldd" hit enter, and the action is performed. All the lights turn on.

When I connect using Arduino I get no response when I type "ldd".

The COM port only has RX/TX pinout, and I am connecting GND as well. I have tested the passthrough using an external USB to serial adapter on the softwareSerial coming out of Arduino and verified that what I type is being passed through.

I suspect that the "device" is RS232. That means it is using voltages up to +/-12V for serial comms. The Arduino is only capable of 0-5V. You need an RS232 converter. There are cheap ones and there are good ones which use a MAX232 chip. Get a good one.

I just took it apart. It seems there is a MAX232 already on it, going to the COM port.

Here is a photo of it:

Imgur

Using a store bought USB to serial adapter works. Using an Adafruit USB to serial adapter does NOT work... I have a few of these adapters, I set them up at 3v and 5v and still no luck. RX-TX TX-RX and GND to GND.

Well, the "store bought" one has the appropriate RS232 voltage level outputs and the "Adafruit" one is probably an FTDI which has only TTL level outputs. You may notice that Adafruit uses the word "serial" and not "RS232" to describe that catalog item. They have other items which do the appropriate voltage conversion.

You need a MAX232 to talk to the MAX232 in the photo.