Чтение данных Processing-ом из txt файла IP адреса.
- Войдите на сайт для отправки комментариев
Ср, 10/07/2013 - 11:51
Добрый день уважаемые форумчане.
Семимильными шагами грызу гранит arduino+Processing.
И вот снова вопрос.
String IP;
BufferedReader load;
void setup()
{
load = createReader("konfigIP.txt");
print(load);
IP=load.readLine();
client = new Client(this, IP, 82);
delay(3000);
}
Пытаюсь прочитать IP адрес из текстового файла. Ругается. Может меня кто ни будь поправить?
Ошибка вида
Unhandled exception type IOException
Ах да, в txt ШЗ записан так
Фаил не может найти
странно. файл в папке с скетчем. М.б файл должен быть создан самим Processing?
На какой строке ошибка?
09IP=load.readLine();Проблема в открытии фаила. Попробуйте создать новый фаил и посмотрите где создался. Туда поместите свои фаил. Иди укажите полный путь.
Спасибо, попробую.
Еще вопрос.
Пытаюсь записывать данные в лог файл.
Если я помещаю строки записи лога в общее тело скетча, лог ведется, но 2-5 значений в секунду. Мне будет достаточно и раз в минуту. Выставил millis. Лог писать перестал, но в консоль данные выводит. Ниже скетч Processing. Может подскажите?
Смотреть строки с 70 по 76
import processing.net.*; PImage IMG; Client client; int interval = 5000; int previousMillis = 0; String h= ""; String t= ""; String t0= ""; String t1= ""; String temperature_up= ""; String temperature_down= ""; String humdity= ""; String filename, row_data; String IP; char flag=10; PrintWriter save; BufferedReader load; void setup() { size(1024, 640); IMG = loadImage ("fon.jpg"); client = new Client(this, "192.168.1.10", 82); delay(3000); int min = minute(); int hr = hour(); int day = day(); int month = month(); int year = year(); client.write ("1"); filename = "DataLogger_"+hr+"_"+min+"_"+day+"_"+month+"_"+year+".txt"; save = createWriter(filename); } void draw() { int sec = second(); // Values from 0 - 59 int min = minute(); // Values from 0 - 59 int hr = hour(); // Values from 0 - 23 int day = day(); int month = month(); int year = year(); background(255); //цвет фона image(IMG,0,0); while (client.available()>0){ char ch = client.readChar(); delay(20); if (ch == 't') {t = client.readStringUntil(flag);} delay(20); if (ch == 'h') {h = client.readStringUntil(flag);} delay(20); if (ch == 1) {t0 = client.readStringUntil(flag);} delay(20); if (ch == 2) {t1 = client.readStringUntil(flag);} delay(20); if (ch == 3) {temperature_up = client.readStringUntil(flag);} delay(20); if (ch == 4) {temperature_down = client.readStringUntil(flag);} delay(20); if (ch == 5) {humdity = client.readStringUntil(flag);} //Запись в лог файл } //Запись в лог файл int currentMillis = millis(); if (currentMillis - previousMillis > interval){ row_data=hr+":"+min+"_"+day+"_"+month+" "+"T1: "+t+" T2: "+t0+" T3: "+t1+" H: "+h; save.println(row_data); previousMillis = currentMillis; println (row_data);} //Заголовки fill (0, 0, 0); textSize(35); text("Заданные нормы", 80, 40); text("температуры и влажности", 10, 80); text("Действительные значения", 562, 40); text("температуры и влажности", 562, 80); textSize(25); text("Датчик1", 580, 120); text("Датчик2", 740, 120); text("Датчик3", 900, 120); text("Верхняя температурная граница:", 10, 120); text("Нижняя температурная граница:", 10, 155); text("Максимум влажности воздуха:", 10, 190); textSize(30); text("С", 675, 160); text("С", 835, 160); text("С", 995, 160); text("%", 675, 200); textSize(25); text("С", 475, 120); text("С", 475, 155); text("%", 475, 190); textSize(20); text("о", 665, 145); text("о", 825, 145); text("о", 985, 145); textSize(15); text("о", 470, 105); text("о", 470, 140); //Вывод заданных значений //Вывод действительных значений fill (0, 0, 0); textSize(30); if (t != null) {text(t, 580, 160);} if (t0 != null) {text(t0, 740, 160);} if (t1 != null) {text(t1, 900, 160);} if (h != null) {text(h, 580, 200);} textSize(25); if (temperature_up != null) {text(temperature_up, 435, 120);} if (temperature_down != null) {text(temperature_down, 435, 155);} if (humdity != null) {text(humdity, 435, 190);} //установка Даты и Времени textSize(30); if (hr<10) { text("0", 10, 240); text(hr, 30, 240);} else { text(hr, 10, 240);} text (":", 50, 240); if (min<10) { text("0", 60, 240); text(min, 80, 240);} else{ text(min, 60, 240);} text(":", 100,240); if(sec<10) { text ("0", 110, 240); text (sec, 130, 240);} else { text(sec, 110, 240);} if(day<10) { text ("0", 180, 240); text (day, 200, 240);} else { text(day, 180, 240);} text (".", 220, 240); if (month<10) { text ("0", 230, 240); text (month, 250, 240);} else { text (month, 230, 240);} text (".", 270, 240); text (year, 280, 240); //Конец установки Даты и Времени // delay(1000); }странно. файл в папке с скетчем. М.б файл должен быть создан самим Processing?
странно. файл в папке с скетчем. М.б файл должен быть создан самим Processing?
понял. Но тогда почему он сам создает файлы в папке со скетчем рядом с папкой data?
Еще вопрос.
Пытаюсь записывать данные в лог файл.
Если я помещаю строки записи лога в общее тело скетча, лог ведется, но 2-5 значений в секунду. Мне будет достаточно и раз в минуту. Выставил millis. Лог писать перестал, но в консоль данные выводит. Ниже скетч Processing. Может подскажите?
Смотреть строки с 70 по 76
import processing.net.*; PImage IMG; Client client; int interval = 5000; int previousMillis = 0; String h= ""; String t= ""; String t0= ""; String t1= ""; String temperature_up= ""; String temperature_down= ""; String humdity= ""; String filename, row_data; String IP; char flag=10; PrintWriter save; BufferedReader load; void setup() { size(1024, 640); IMG = loadImage ("fon.jpg"); client = new Client(this, "192.168.1.10", 82); delay(3000); int min = minute(); int hr = hour(); int day = day(); int month = month(); int year = year(); client.write ("1"); filename = "DataLogger_"+hr+"_"+min+"_"+day+"_"+month+"_"+year+".txt"; save = createWriter(filename); } void draw() { int sec = second(); // Values from 0 - 59 int min = minute(); // Values from 0 - 59 int hr = hour(); // Values from 0 - 23 int day = day(); int month = month(); int year = year(); background(255); //цвет фона image(IMG,0,0); while (client.available()>0){ char ch = client.readChar(); delay(20); if (ch == 't') {t = client.readStringUntil(flag);} delay(20); if (ch == 'h') {h = client.readStringUntil(flag);} delay(20); if (ch == 1) {t0 = client.readStringUntil(flag);} delay(20); if (ch == 2) {t1 = client.readStringUntil(flag);} delay(20); if (ch == 3) {temperature_up = client.readStringUntil(flag);} delay(20); if (ch == 4) {temperature_down = client.readStringUntil(flag);} delay(20); if (ch == 5) {humdity = client.readStringUntil(flag);} //Запись в лог файл } //Запись в лог файл int currentMillis = millis(); if (currentMillis - previousMillis > interval){ row_data=hr+":"+min+"_"+day+"_"+month+" "+"T1: "+t+" T2: "+t0+" T3: "+t1+" H: "+h; save.println(row_data); previousMillis = currentMillis; println (row_data);} //Заголовки fill (0, 0, 0); textSize(35); text("Заданные нормы", 80, 40); text("температуры и влажности", 10, 80); text("Действительные значения", 562, 40); text("температуры и влажности", 562, 80); textSize(25); text("Датчик1", 580, 120); text("Датчик2", 740, 120); text("Датчик3", 900, 120); text("Верхняя температурная граница:", 10, 120); text("Нижняя температурная граница:", 10, 155); text("Максимум влажности воздуха:", 10, 190); textSize(30); text("С", 675, 160); text("С", 835, 160); text("С", 995, 160); text("%", 675, 200); textSize(25); text("С", 475, 120); text("С", 475, 155); text("%", 475, 190); textSize(20); text("о", 665, 145); text("о", 825, 145); text("о", 985, 145); textSize(15); text("о", 470, 105); text("о", 470, 140); //Вывод заданных значений //Вывод действительных значений fill (0, 0, 0); textSize(30); if (t != null) {text(t, 580, 160);} if (t0 != null) {text(t0, 740, 160);} if (t1 != null) {text(t1, 900, 160);} if (h != null) {text(h, 580, 200);} textSize(25); if (temperature_up != null) {text(temperature_up, 435, 120);} if (temperature_down != null) {text(temperature_down, 435, 155);} if (humdity != null) {text(humdity, 435, 190);} //установка Даты и Времени textSize(30); if (hr<10) { text("0", 10, 240); text(hr, 30, 240);} else { text(hr, 10, 240);} text (":", 50, 240); if (min<10) { text("0", 60, 240); text(min, 80, 240);} else{ text(min, 60, 240);} text(":", 100,240); if(sec<10) { text ("0", 110, 240); text (sec, 130, 240);} else { text(sec, 110, 240);} if(day<10) { text ("0", 180, 240); text (day, 200, 240);} else { text(day, 180, 240);} text (".", 220, 240); if (month<10) { text ("0", 230, 240); text (month, 250, 240);} else { text (month, 230, 240);} text (".", 270, 240); text (year, 280, 240); //Конец установки Даты и Времени // delay(1000); }Прошу подсказки по данному посту.
Для отладки на рабочем оборудованиии, готов заинтерисованному лицу, отправить внешний IP адрес для подключения. (Прописать в строку №025).
Лучше поздно, чем никогда)))
//Запись в лог файл int currentMillis = millis(); if (currentMillis - previousMillis > interval){ row_data=hr+":"+min+"_"+day+"_"+month+" "+"T1: "+t+" T2: "+t0+" T3: "+t1+" H: "+h; save.println(row_data); save.flush(); // это она) previousMillis = currentMillis; println (row_data);}