LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   End of file in C programming for readings (https://www.linuxquestions.org/questions/linux-newbie-8/end-of-file-in-c-programming-for-readings-4175468746/)

Sanpreet Singh 07-07-2013 12:46 AM

End of file in C programming for readings
 
Code:

Hi! This is my code. Working fine

void setup()
 {
 
  Serial.begin(9600);
 }

void loop() 
{
  int s1[2];
  int s2[2];
  s1[1] = analogRead(A1);
  s2[1] = analogRead(A2);
  Serial.println(s1[1]);
  Serial.println(s2[1]);
  delay(1000);
  s1[2] = analogRead(A1);
  s2[2] = analogRead(A2);
  if((s1[1]<s1[2])&&(s2[1]>s2[2]))
          {
                  exit(1);
          }
  else
          { 
          Serial.println(s1[2]);
          Serial.println(s2[2]);
          delay(1000); 
          }
}

//the above is my code.

Now the problem is I want to Apply EOF in my code. The above code works fine. Definately a question come to your mind why I have to use End of file in my code. I want to run the above code using shell script in terminal in ubuntu.I have done this by using the command sudo /dev/ttyUSB0 > sensor.txt. This command puts the data of ttyUSB0 to the file called sensor.txt. But when My code end means no more reading is coming from my sensor to the arduino serial monitor or to the text file or to ttyUSB0 my script doesnot end. I think that script doesnot have end of file. This is the reason It is not ending. I am giving you the link of my github from where you can view my code of shell scipt. https://github.com/sanpreet/Automati...esting-Machine. There are five files and I have to add content to read me files. Otherfiles are ready. Even if I have tried EOF in file ttyUSB0.sh but no result. So Now I am feeling Should I insert EOF in Sensor_logic.uno. These files are contained in github. You can view them

I am trying my best to explain the problem. Help is needed.

TB0ne 07-07-2013 09:25 AM

Quote:

Originally Posted by Sanpreet Singh (Post 4985515)
Hi! This is my code. Working fine

Now the problem is I want to Apply EOF in my code. The above code works fine. Definately a question come to your mind why I have to use End of file in my code. I want to run the above code using shell script in terminal in ubuntu.I have done this by using the command sudo /dev/ttyUSB0 > sensor.txt. This command puts the data of ttyUSB0 to the file called sensor.txt. But when My code end means no more reading is coming from my sensor to the arduino serial monitor or to the text file or to ttyUSB0 my script doesnot end. I think that script doesnot have end of file. This is the reason It is not ending. I am giving you the link of my github from where you can view my code of shell scipt. https://github.com/sanpreet/Automati...esting-Machine. There are five files and I have to add content to read me files. Otherfiles are ready. Even if I have tried EOF in file ttyUSB0.sh but no result. So Now I am feeling Should I insert EOF in Sensor_logic.uno. These files are contained in github. You can view them

I am trying my best to explain the problem. Help is needed.

Not sure what you need help WITH. You've got working code, and have one problem which you have identified and have a solution for. So, implement the solution. What are you having problems with?


All times are GMT -5. The time now is 04:45 PM.