[SOLVED] Program compiles just fine but has a Syntax error when I try to run it
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Program compiles just fine but has a Syntax error when I try to run it
Code:
#include "currentLoop.h"
#include "stdio.h"
#define CHANNEL CHANNEL4
//Include FILE Variables
FILE* value_file;
FILE* voltage_file;
FILE* current_file;
void setup()
{
//Inits the Serial for viewing data in the serial monitor.
//Switch ON the 24V DC-DC converter
sensorBoard.ON();
delay(100);
printf("Arduino 4-20 mA board switched ON...");
printf("\n");
//Open 3 Files
value_file = fopen("Value.txt","w");
voltage_file = fopen("Voltage.txt","w");
current_file = fopen("Current.txt","w");
delay(5);
printf("All Files Opened..");
printf("\n");
}
void loop()
{
if (sensorBoard.isConnected(CHANNEL))
{
// Get the sensor value in int format (0-1023).
int value = sensorBoard.readChannel(CHANNEL);
printf("Int value read from channel 1 : %d",value);
printf("\n");
//log data to the Value File
fprintf(value_file, "%d\n", value);
fflush(value_file);
// Get the sensor value as a voltage in Volts.
float voltage = sensorBoard.readVoltage(CHANNEL);
printf("Voltage value rad from channel 1 : %f",voltage);
printf(" V");
printf("\n");
//log data to the Voltage File
fprintf(voltage_file, "%f\n", voltage);
fflush(voltage_file);
// Get the sensor value as a curren in mA.
float current = sensorBoard.readCurrent(CHANNEL);
printf("Current value read from channel 1 : %f",current);
printf(" mA");
printf("\n");
//log data to the Current File
fprintf(current_file, "%f\n", current);
fflush(current_file);
printf("***************************************");
printf("\n");
}
else {
printf("The sensor is not connected...");
printf("\n");
}
//Delay after reading.
delay(2500);
}
int main (){
setup();
while(1){
loop();
}
return (0);
}
This program compiles just fine but will not run. Syntax error: word unexpected (expecting ")") is the error I get when I run it.
The program worked just fine until it was modiefied to write to file. I am running the program in Linux on a Raspberry Pi. It is compiled on the Pi with g++.
Thanks
Last edited by KFarm; 11-21-2014 at 02:00 PM.
Reason: adding information
Distribution: Yellow Dog, Fedora, RedHat, Centos, Ubuntu, Suse Linux
Posts: 106
Rep:
Have you tried to write a dummy file test.txt with "test" as the data?
Trying writing a file without using your inputted data and not going through the loop.
Ok so I tried to run a program that used to work just fine and I got the same error. So I am reinstalling the OS on the raspberry Pi. I will se if that fixes it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.