Автор Тема: error compling: expected primary-expression before ‘)’ token  (Прочетена 1954 пъти)

0 Потребители и 1 Гост преглежда(т) тази тема.

jazzman

  • Hero Member
  • *****
  • Благодарности
  • -Казани: 25
  • -Получени: 190
  • Публикации: 3624
error compling: expected primary-expression before ‘)’ token
« -: 18 Октомври 2016, 14:22:34 »
Опитвам се да вкарам Date/Time functions в arduino IDE, но получавам грешка при компилацията на кода. Нямам и грам идея кво е тва чудо :)

Код: C
  1. #include <DateTime.h>
  2. #include <DateTimeStrings.h>
  3.  
  4. #define TIME_MSG_LEN  11   // time sync to PC is HEADER and unix time_t as ten ascii digits
  5.  
  6. #define TIME_HEADER  255   // Header tag for serial time sync message
  7.  
  8. void setup(){
  9.   Serial.begin(9600);
  10. }
  11.  
  12. void  loop(){  
  13.   getPCtime();   // try to get time sync from pc        
  14.   if(DateTime.available()) { // update clocks if time has been synced
  15.     unsigned long prevtime = DateTime.now();
  16.     while( prevtime == DateTime.now())  // wait for the second to rollover
  17.       ;
  18.     DateTime.available(); //refresh the Date and time properties
  19.     digitalClockDisplay();   // update digital clock
  20.  
  21.     // send our time to an app listening on the serial port
  22.     Serial.print( TIME_HEADER,byte); // this is the header for the current time
  23.     Serial.println(DateTime.now());      
  24.   }
  25. }
  26.  
  27. void getPCtime() {
  28.   // if time available from serial port, sync the DateTime library
  29.   while(Serial.available() >=  TIME_MSG_LEN ){  // time message
  30.     if( Serial.read() == TIME_HEADER ) {        
  31.       time_t pctime = 0;
  32.       for(int i=0; i < TIME_MSG_LEN -1; i++){  
  33.         char c= Serial.read();          
  34.         if( c >= '0' && c <= '9')  
  35.           pctime = (10 * pctime) + (c - '0') ; // convert digits to a number            
  36.       }  
  37.       DateTime.sync(pctime);   // Sync DateTime clock to the time received on the serial port
  38.     }  
  39.   }
  40. }
  41.  
  42. void digitalClockDisplay(){
  43.   // digital clock display of current time
  44.   Serial.print(DateTime.Hour,DEC);  
  45.   printDigits(DateTime.Minute);  
  46.   printDigits(DateTime.Second);
  47.   Serial.print(" ");
  48.   Serial.print(DateTimeStrings.dayStr(DateTime.DayofWeek));
  49.   Serial.print(" ");  
  50.   Serial.print(DateTimeStrings.monthStr(DateTime.Month));  
  51.   Serial.print(" ");
  52.   Serial.println(DateTime.Day, DEC);  
  53. }
  54.  
  55. void printDigits(byte digits){
  56.   // utility function for digital clock display: prints colon and leading 0
  57.   Serial.print(":");
  58.   if(digits < 10)
  59.     Serial.print('0');
  60.   Serial.print(digits,DEC);  
  61. }
  62.  

Цитат
sketch_oct18b.ino: In function ‘void loop()’:
sketch_oct18b.ino:22:35: error: expected primary-expression before ‘)’ token
Java is to Javascript as fun is to funeral.

http://nau4i.me/forum/index.php/topic,15129.0.html

kjufte

  • Sr. Member
  • ****
  • Благодарности
  • -Казани: 1
  • -Получени: 51
  • Публикации: 308
Re: error compling: expected primary-expression before ‘)’ token
« Отговор #1 -: 18 Октомври 2016, 16:24:03 »
Според документацията на сайта на ардуино:

Цитат
An optional second parameter specifies the base (format) to use; permitted values are BIN (binary, or base 2), OCT (octal, or base 8 ), DEC (decimal, or base 10), HEX (hexadecimal, or base 16). For floating point numbers, this parameter specifies the number of decimal places to use. For example:   
- Serial.print(78, BIN) gives "1001110"
- Serial.print(78, OCT) gives "116"
- Serial.print(78, DEC) gives "78"
- Serial.print(78, HEX) gives "4E"
- Serial.println(1.23456, 0) gives "1"
- Serial.println(1.23456, 2) gives "1.23"
- Serial.println(1.23456, 4) gives "1.2346"

Та не съм сигурен тоз byte кви ги чини на ред 22.

jazzman

  • Hero Member
  • *****
  • Благодарности
  • -Казани: 25
  • -Получени: 190
  • Публикации: 3624
Re: error compling: expected primary-expression before ‘)’ token
« Отговор #2 -: 18 Октомври 2016, 18:06:00 »
Мислиш, че от byte ли е? Ако коментирам 22 и 23 ред хвърчат други грешки.
Java is to Javascript as fun is to funeral.

http://nau4i.me/forum/index.php/topic,15129.0.html

kjufte

  • Sr. Member
  • ****
  • Благодарности
  • -Казани: 1
  • -Получени: 51
  • Публикации: 308
Re: error compling: expected primary-expression before ‘)’ token
« Отговор #3 -: 18 Октомври 2016, 21:11:00 »
Е дай да ги видим

Виждам, че тази библиотека дето ползваш са я заменили отдавна с друга. Та дори и тази другата вече е заменена с трета по-нова.

Даже пише че ако ползваш ардуино версия > 1.6.1, то трябва да ползваш последния вариант.
« Последна редакция: 18 Октомври 2016, 21:31:15 от kjufte »

jazzman

  • Hero Member
  • *****
  • Благодарности
  • -Казани: 25
  • -Получени: 190
  • Публикации: 3624
Re: error compling: expected primary-expression before ‘)’ token
« Отговор #4 -: 18 Октомври 2016, 23:34:38 »
Виж кво пише в дискрипшъна:
Цитат
Linux: Teensyduino only works with Arduino from www.arduino.cc. The modified version provided by Ubuntu is not (yet) supported.


Aз съм с компилирана версия за Mint. Tва  ползвам на лаптопа иначе, десктоп машините са под Centos 5, но с тях не съм пробвал.

В момента съм с  - 1.0.5

Ето тва излиза като грешки ако коментирам кода от 22 и 23 ред:


Цитат
In file included from /home/dimt/sketchbook/libraries/DateTimeStrings/DateTimeStrings.cpp:20:0:
/home/dimt/sketchbook/libraries/DateTimeStrings/DateTimeStrings.cpp:32:18: error: variable ‘monthStr0’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
 char monthStr0[] PROGMEM = "January";
                  ^
/home/dimt/sketchbook/libraries/DateTimeStrings/DateTimeStrings.cpp:33:18: error: variable ‘monthStr1’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
 char monthStr1[] PROGMEM = "February";
                  ^
/home/dimt/sketchbook/libraries/DateTimeStrings/DateTimeStrings.cpp:34:18: error: variable ‘monthStr2’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
 char monthStr2[] PROGMEM = "March";
                  ^
/home/dimt/sketchbook/libraries/DateTimeStrings/DateTimeStrings.cpp:35:18: error: variable ‘monthStr3’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
 char monthStr3[] PROGMEM = "April";
                  ^
/home/dimt/sketchbook/libraries/DateTimeStrings/DateTimeStrings.cpp:36:18: error: variable ‘monthStr4’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
 char monthStr4[] PROGMEM = "May";
                  ^
/home/dimt/sketchbook/libraries/DateTimeStrings/DateTimeStrings.cpp:37:18: error: variable ‘monthStr5’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
 char monthStr5[] PROGMEM = "June";
                  ^
/home/dimt/sketchbook/libraries/DateTimeStrings/DateTimeStrings.cpp:38:18: error: variable ‘monthStr6’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
 char monthStr6[] PROGMEM = "July";
                  ^
/home/dimt/sketchbook/libraries/DateTimeStrings/DateTimeStrings.cpp:39:18: error: variable ‘monthStr7’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
 char monthStr7[] PROGMEM = "August";
                  ^
/home/dimt/sketchbook/libraries/DateTimeStrings/DateTimeStrings.cpp:40:18: error: variable ‘monthStr8’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
 char monthStr8[] PROGMEM = "September";
                  ^
/home/dimt/sketchbook/libraries/DateTimeStrings/DateTimeStrings.cpp:41:18: error: variable ‘monthStr9’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
 char monthStr9[] PROGMEM = "October";
                  ^
/home/dimt/sketchbook/libraries/DateTimeStrings/DateTimeStrings.cpp:42:19: error: variable ‘monthStr10’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
 char monthStr10[] PROGMEM = "November";
                   ^
/home/dimt/sketchbook/libraries/DateTimeStrings/DateTimeStrings.cpp:43:19: error: variable ‘monthStr11’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
 char monthStr11[] PROGMEM = "December";
                   ^
/home/dimt/sketchbook/libraries/DateTimeStrings/DateTimeStrings.cpp:45:22: error: variable ‘monthNames_P’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
 PGM_P monthNames_P[] PROGMEM =
                      ^
/home/dimt/sketchbook/libraries/DateTimeStrings/DateTimeStrings.cpp:56:16: error: variable ‘dayStr0’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
 char dayStr0[] PROGMEM = "Sunday";
                ^
/home/dimt/sketchbook/libraries/DateTimeStrings/DateTimeStrings.cpp:57:16: error: variable ‘dayStr1’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
 char dayStr1[] PROGMEM = "Monday";
                ^
/home/dimt/sketchbook/libraries/DateTimeStrings/DateTimeStrings.cpp:58:16: error: variable ‘dayStr2’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
 char dayStr2[] PROGMEM = "Tuesday";
                ^
/home/dimt/sketchbook/libraries/DateTimeStrings/DateTimeStrings.cpp:59:16: error: variable ‘dayStr3’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
 char dayStr3[] PROGMEM = "Wednesday";
                ^
/home/dimt/sketchbook/libraries/DateTimeStrings/DateTimeStrings.cpp:60:16: error: variable ‘dayStr4’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
 char dayStr4[] PROGMEM = "Thursday";
                ^
/home/dimt/sketchbook/libraries/DateTimeStrings/DateTimeStrings.cpp:61:16: error: variable ‘dayStr5’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
 char dayStr5[] PROGMEM = "Friday";
                ^
/home/dimt/sketchbook/libraries/DateTimeStrings/DateTimeStrings.cpp:62:16: error: variable ‘dayStr6’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
 char dayStr6[] PROGMEM = "Saturday";
                ^
/home/dimt/sketchbook/libraries/DateTimeStrings/DateTimeStrings.cpp:64:20: error: variable ‘dayNames_P’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
 PGM_P dayNames_P[] PROGMEM =
                    ^
« Последна редакция: 18 Октомври 2016, 23:38:47 от jazzman »
Java is to Javascript as fun is to funeral.

http://nau4i.me/forum/index.php/topic,15129.0.html

kjufte

  • Sr. Member
  • ****
  • Благодарности
  • -Казани: 1
  • -Получени: 51
  • Публикации: 308
Re: error compling: expected primary-expression before ‘)’ token
« Отговор #5 -: 19 Октомври 2016, 20:15:14 »
1. хващаш последната версия на Time от github
2. разархивираш в arduino_1.0.5_install_dir\libraries\
3. махаш -master от името на папката, за да остане само Time като име
4. Рестартираш arduino studio
5. под File->Еxamples ще видиш папка Time. Отваряш примерно TimeSerial.
6. компилираш и ъплоудваш
7. свързваш се през serial порта и вкарваш Т<unix_timestamp>. Примерно: T1476897208
8. гледаш, тцъкаш с език и са вайкаш до къде е стигнала технологията  ;D

jazzman

  • Hero Member
  • *****
  • Благодарности
  • -Казани: 25
  • -Получени: 190
  • Публикации: 3624
Re: error compling: expected primary-expression before ‘)’ token
« Отговор #6 -: 19 Октомври 2016, 23:07:01 »
Да ти кажа честно отказах се да се занимавам с IDE-то им и предпочитам да си пиша кода сам и да разбирам всеки шибан ред от него. Почнах със C и стигнах до положение, че вече съм способен да чета и преобразувам аналоговият сигнал в дигитален, както и да манипулирам както си искам дигиталните портове на Arduino.Това за сега ме устройва напълно. За Date/Time ще ползвам някоя библиотека писна на  C. Ако се препъна някъде ще питам.
Java is to Javascript as fun is to funeral.

http://nau4i.me/forum/index.php/topic,15129.0.html