Analog Data Logging over serialport

Hello, this is my first post ever,
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.

Here are the arduino codes :

FIRST CODE (this works)
/*

  • 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 = j;

  • }*
  • i = n-1;*
  • j = analogRead(i);*
  • delay(10);*
  • j = analogRead(i);*
    _ iRead = j;_
    * s = "E";*
    * s = s + String(DataNo) + ",";*
    * for (i=0;i<n-1;i++)*
    * {*
    _ s = s + String(iRead*) + ",";
    }
    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);
    }
    SECOND CODE (does not work)
    /

    * 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 = j;
    * }
    i = n-1;
    j = analogRead(i);
    delay(10);
    j = analogRead(i);
    iRead = j;
    s = "E";
    s = s + String(DataNo) + ",";
    for (i=0;i<n-1;i++)
    {
    s = s + String(iRead) + ",";
    }
    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);
    }*_

Welcome to the forum

Please read the advice in Read this before posting a programming question and edit your post, delete the code, copy it again from the IDE and post it in code tags to avoid the forum software interpreting [­i] as an HTML command to go into italics