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);
}