How to send position data to industrial robot?

Hi I need to send data from a CSV file, one line at a time via RS232 when requested from robot controller. I was thinking the easiest way would be to use SD card with the CSV file and use RS232 shield. Not sure how to write the sketch to just send one line at a time each time a message is recieved from robot. Can anyone help please? :)

Not sure how to write the sketch to just send one line at a time each time a message is recieved from robot.

First, you need to determine when the robot is requesting information, versus requesting a coffee or smoke break.

Then, you need to define what constitutes “one line”. Data on an SD card is stored sequentially. You stop reading when you have encountered an end-of-record marker. When that occurs depends on what you have defined for an end-of-record marker.

Once you have a line to send, and know that the robot has asked for data, sending it is trivial.

Serial.print(theLine);

Thanks for your help. when it's ready, the robot sends out a request in the form SHIFT 1 CR LF on the serial port. it then waits for a response that should be SHIFT X, Y, Z, ?X, ?Y, ?Z CR where the values are taken from my data file. the next request should get the next line from the data file and so on. It was easy with Basic, I used the readline function but I'm not sure how do it with the Arduino.

It was easy with Basic, I used the readline function but I'm not sure how do it with the Arduino.

Which SD library are you using? What code have you written? Do you know how to read anything from the SD card?

I think I worked out how to get the data and send it as a string, using the code below. I’m waiting to receive a RS232 shield before I can try for real.
Not sure if I’ve gone about it the right way but the code does read one line at a time when it gets a message from the serial port.
It seems to work with a single byte to read from serial (I used 48 which is “0”) but can not get to work with a string for the request from robot.
Any suggestions?

byte inByte = 0;
String dataString = “SHIFT”;
String dString = “”;
#include <SD.h>
const int chipSelect = 4;
void setup()
{
Serial.begin(9600);
// Serial.print(“Initializing SD card…”);
pinMode(10, OUTPUT);
if (!SD.begin(chipSelect)) {
Serial.println(“Card failed, or not present”);
return;
}
// Serial.println(“card initialized.”);
File dataFile = SD.open(“datalog.txt”);
if (dataFile) {
while (dataFile.available()) {
dString = (dataFile.read());
dataString = dataString + dString;
if (dString == 10) dataString = “SHIFT”;
if (dString ==13) {
Serial.println(dataString);
do inByte = Serial.read(),
delay(10);
while (inByte != 48);
}
}
dataFile.close();
}
else {
Serial.println(“error opening datalog.txt”);
}
}

void loop()
{
}

        do inByte = Serial.read(),
        delay(10);
        while (inByte != 48);

Would you mind explaining what you think this code is doing? Especially the comma there.

Why do you want to wait any time before checking again?

It seems to work with a single byte to read from serial (I used 48 which is "0") but can not get to work with a string for the request from robot.

You are only reading (and discarding) individual characters. If you want to deal with strings, you need to collect the data in an array, keeping the array NULL terminated. Or, you could collect the data in a String.