Analog Data Logging over serialport

Hello, this is my edited post as instructed,
I'm using Borland C++ Builder6 to communicate with Arduino UNO/MEGA
The program is used to control/collect data for various interactive lab experiments.

I applied 2 different codes.
The first code works. However data streaming is controlled by arduino.
I measured the time intervals on the PC and it takes approximately 600 miliseconds/16 channels.
Therefore setting the PC program timer to 1 second works. However I may record either the first or second input.

The second code which I prefer does not work.
Here I send a message "RA" which makes the Arduino go to the multi-channel read function.
However, after the first successful send the repeated sends do not go through.

I remember my serial port communications in the 90's using modems.
At the beginning it was "half duplex" and then I acquired a "full duplex" modem and could <send/receive> voice simultaneously. Is my problem similar ?

Here are the arduino codes (I hope I understood the moderator's instructions) :

This is the one I am currently using. It works. However, it is not synchronized.

/*
 * Author: Demir Bayka
 * Analog data logging over SerialPort
 */
#define BAUD 9600
#define DELAY_TIME 100
#define led3 13

String         receivedString;
String         AnyString,sintRead;
bool           OK = false;
int            ChanNo = 16;
int            DataNo = 0;
int            iRead[16];

void setup() 
{
  Serial.begin(BAUD);
  pinMode(led3, OUTPUT);
}

void ReadAnalogChannels(int &n)
{
  int            i,j;
  String         s;
  DataNo++;
  for (i=0;i<n-1;i++)
  {
    j = analogRead(i);
    delay(10);
    j = analogRead(i);
    delay(10);
    iRead[i] = j;
  }
  i = n-1;
  j = analogRead(i);
  delay(10);
  j = analogRead(i);
  iRead[i] = j;
  s = "E";
  s = s + String(DataNo) + ",";
  for (i=0;i<n-1;i++)
  { 
    s = s + String(iRead[i]) + ",";
  }
  s += String(iRead[n-1]);
  Serial.println(s);
  Serial.flush();
  digitalWrite(led3, LOW);
}

void loop() 
{
  if (Serial.available() > 0)
  { 
    receivedString = Serial.readStringUntil('\n');
  }
  if (receivedString.length()>2)
  {
    AnyString = receivedString.substring(0,2);
    if (AnyString.equals("XX"))
    {
      sintRead = receivedString.substring(2);
      ChanNo = sintRead.toInt();
      Serial.println(ChanNo);
      Serial.flush();
      delay(50);
    }
  }  
  if (receivedString.equals("OFF"))
  {
    OK = false;
    digitalWrite(led3, LOW);
    Serial.println("TEST HAS ENDED");
  }  
  if (OK)
  {
    ReadAnalogChannels(ChanNo);
  }
  if (receivedString.equals("RA"))
  {
    digitalWrite(led3, HIGH);
    receivedString = "";
    DataNo = 0;
    OK = true;
  }
  delay(200);
}

This is the one I wish to use. I should be able to set the timing of the signals.

/*
 * Author: Demir Bayka
 * Analog data logging over SerialPort
 */
#define BAUD 9600
#define DELAY_TIME 100
#define led3 13

String         receivedString;
String         AnyString,sintRead;
int            ChanNo = 16;
int            DataNo = 0;
int            iRead[16];

void setup() 
{
  Serial.begin(BAUD);
  pinMode(led3, OUTPUT);
}

void ReadAnalogChannels(int &n)
{
  int            i,j;
  String         s;
  DataNo++;
  for (i=0;i<n-1;i++)
  {
    j = analogRead(i);
    delay(10);
    j = analogRead(i);
    delay(10);
    iRead[i] = j;
  }
  i = n-1;
  j = analogRead(i);
  delay(10);
  j = analogRead(i);
  iRead[i] = j;
  s = "E";
  s = s + String(DataNo) + ",";
  for (i=0;i<n-1;i++)
  { 
    s = s + String(iRead[i]) + ",";
  }
  s += String(iRead[n-1]);
  Serial.println(s);
  Serial.flush();
  digitalWrite(led3, LOW);
}

void loop() 
{
  if (Serial.available() > 0)
  { 
    receivedString = Serial.readStringUntil('\n');
  }
  if (receivedString.length()>2)
  {
    AnyString = receivedString.substring(0,2);
    if (AnyString.equals("XX"))
    {
      sintRead = receivedString.substring(2);
      ChanNo = sintRead.toInt();
      Serial.println(ChanNo);
      Serial.flush();
      delay(50);
    }
  }  
  if (receivedString.equals("OFF"))
  {
    digitalWrite(led3, LOW);
    Serial.println("TEST HAS ENDED");
  }  
  if (receivedString.equals("RA"))
  {
    digitalWrite(led3, HIGH);
    receivedString = "";
    ReadAnalogChannels(ChanNo);
  }
  delay(200);
}

trying to second guess timing in an asynchronous protocol will lead to disappointment

I would suggest to study Serial Input Basics to understand common principles

I'd start by increasing the baud rate to 115200 or more and removing all of the 'delay()' calls in your sketch.

Also, if you are using an UNO I would recommend not using String. Takes up a lot of memory.

DemirBayka:
Hello, this is my edited post as instructed,

No. This is a cross-post. You were asked to EDIT your post, not create a new one. I guess you didn't notice that you can click "More..." and then "Modify" on your post to edit it.

I've deleted your other cross-post.

Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting will result in a suspension from the forum.

In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.