Problem with receiving data from RPi to Arduino via serial

Our team has been trying to send data over from RPi to Arduino but there are some weird things happening:

If we open the serial monitor of arduino on RPi itself, the serial data is sent by RPi and received by Arduino successfully.

However, if we do not open the serial monitor of arduino on RPi, the serial data is sent by RPi but not received by Arduino.

The communication between them is via USB cable.

Below are the codes implemented on RPi (using RS232 Linux library in C):

void *rs232t_connect(void *arg)
{
struct RS232Connection connect = (struct RS232Connection)arg;

// connect to USB port ttyACM0
fprintf(output, "Waiting for connection on Comport ttyACM0 (24)...\n");
while(RS232_OpenComport(connect->cport_nr, connect->bdrate, connect->mode) == 1)
sleep(1);

// set connected flag to signal completion of connection to main()
connect->connected = true;
fprintf(output, "Connection accepted.");

return 0;
}

void *rs232t_send(void *arg)
{
struct RS232Connection connect = (struct RS232Connection)arg;
unsigned char buf[4];
int32_t g;
bool reconnect = false, resend = false;

while(1)
{
// sample
g = 10;

// convert from LSB->MSB to MSB->LSB
memset(buf, 0, sizeof buf); // clear buffer
buf[0] = (g >> 24) & 0xFF;
buf[1] = (g >> 16) & 0xFF;
buf[2] = (g >> 8) & 0xFF;
buf[3] = g & 0xFF;

if(RS232_SendBuf(connect->cport_nr, buf, sizeof(int)) == -1)
{
// Print error msg if sending failed
fprintf(output, "Disconnected\n");
}
else
{
fprintf(output, "Outgoing Message: %d\n", g); // DEBUG
g = 0;
}
}
return 0;
}

Arduino Code:

/-----------------------------------------------------------
Funciton to read in command from rpi
------------------------------------------------------------
/
long readSerialInt() {
long result = 0;
long temp[4];
if (Serial.available() >= 4) {
digitalWrite(13, 1);
for (int i = 0; i < 4; i++) {
temp = Serial.read();
}
//result += temp[0];
//result += temp[1] << 8;
//result += temp[2] << 16;
//result += temp[3] << 24;
result += temp[0] << 24;
result += temp[1] << 16;
result += temp[2] << 8;
result += temp[3];
return result;
}
else {
return 0;
}
}[/quote]
Any idea why this is happening? Its weird that we need to open the serial monitor of Arduino IDE on RPi before the message gets sent out.
Thank you

tam22:
if we do not open the serial monitor of arduino on RPi

I don't understand what this means. Are you running the Arduino IDE on the RPi?

ieee488:
I don't understand what this means. Are you running the Arduino IDE on the RPi?

We are sending data over to Arduino. However Arduino does not detect the messages we are sending to it (it didnt perform any action/light up any LED).

Thus my Arduino team suggested installing Arduino IDE on RPi to see what is sent over the serial com port as they can't see it from their end. When the IDE's serial monitor is turned on, everything flows to Arduino without problem. But without the IDE's serial monitor opened, it simply doesn't do anything...

We are quite puzzled by this and am trying to figure out what is going on.