diff --git a/drv/b15f.cpp b/drv/b15f.cpp index 20333ff..ff95d66 100644 --- a/drv/b15f.cpp +++ b/drv/b15f.cpp @@ -23,10 +23,10 @@ void B15F::init() options.c_iflag = IGNPAR; options.c_oflag = 0; options.c_lflag = 0; - options.c_cc[VTIME]=1; // timeout in Dezisekunden + options.c_cc[VTIME]=100; // timeout in Dezisekunden cfsetspeed(&options, BAUDRATE); tcsetattr(usart, TCSANOW, &options); - tcflush(usart, TCIFLUSH); + tcflush(usart, TCIOFLUSH); // leere Puffer in beiden Richtungen std::cout << "OK" << std::endl; @@ -81,14 +81,13 @@ void B15F::reconnect() void B15F::discard(void) { - tcflush(usart, TCIFLUSH); // leere Puffer + tcflush(usart, TCOFLUSH); // leere Ausgangspuffer for(uint8_t i = 0; i < 8; i++) { writeByte(RQ_DISC); // sende discard Befehl (verwerfe input) - delay(10); + delay((16000 / BAUDRATE) + 1); // warte mindestens eine Millisekunde, gegebenenfalls mehr } - delay(100); - tcflush(usart, TCIFLUSH); // leere Puffer + tcflush(usart, TCIFLUSH); // leere Eingangspuffer } bool B15F::testConnection() @@ -272,23 +271,33 @@ bool B15F::analogEingabeSequenz(uint8_t channel_a, uint16_t* buffer_a, uint32_t writeByte(channel_b); writeInt(start); writeInt(static_cast(delta)); - writeInt(count); + writeInt(count); uint8_t aw = readByte(); if(aw != MSG_OK) + { + std::cout << PRE << "Mikrocontroller nicht synchronisiert" << std::endl; throw DriverException("Mikrocontroller nicht synchronisiert"); + } for(uint16_t i = 0; i < count; i++) { buffer_a[offset_a + i] = readInt(); buffer_b[offset_b + i] = readInt(); if(buffer_a[offset_a + i] > 1023 || buffer_b[offset_b + i] > 1023) - std::cout << "schlechte Werte gefunden" << std::endl; - //std::cout << "(" << i << ") " << buffer_a[offset_a + i] << " \t| " << buffer_b[offset_b + i] << std::endl; + { + std::cout << PRE << "Schlechte Werte gefunden" << std::endl; + throw DriverException("Schlechte Werte gefunden"); + } } aw = readByte(); - return aw == MSG_OK; + if(aw == MSG_OK) + return aw; + + std::cout << PRE << "Da ging etwas verloren" << std::endl; + discard(); + return analogEingabeSequenz(channel_a, buffer_a, offset_a, channel_b, buffer_b, offset_b, start, delta, count); } catch(DriverException& de) { @@ -318,10 +327,22 @@ uint8_t B15F::readByte() uint16_t elapsed = 0; while(elapsed < timeout) { - int n = read(usart, &b, 1); - if (n > 0) - return static_cast(b); + int n_ready; + int code = ioctl(usart, FIONREAD, &n_ready); + if(code != 0) + std::cout << PRE << "n_ready code: " << code << std::endl; + + if(n_ready > 0) + { + //std::cout << code << " \tready: " << n_ready << std::endl; + code = read(usart, &b, 1); + if (code > 0) + return static_cast(b); + if (code < 0) + std::cout << PRE << "usart code: " << code << std::endl; + } + end = std::chrono::steady_clock::now(); elapsed = std::chrono::duration_cast(end - start).count(); } diff --git a/drv/b15f.h b/drv/b15f.h index 1d9d3ad..c8cf7ca 100644 --- a/drv/b15f.h +++ b/drv/b15f.h @@ -12,6 +12,7 @@ #include #include +#include #include #include "driverexception.h" @@ -51,7 +52,7 @@ public: private: int usart = -1; - uint16_t timeout = 1000; + uint16_t timeout = 100; // ms static B15F* instance; diff --git a/drv/b15f.o b/drv/b15f.o index ea73b41..1a9b773 100644 Binary files a/drv/b15f.o and b/drv/b15f.o differ diff --git a/gnuplotscript.gp b/gnuplotscript.gp index 9b98559..9a5aaa5 100644 --- a/gnuplotscript.gp +++ b/gnuplotscript.gp @@ -8,27 +8,28 @@ set xrange [5:0] set x2range [5:0] set y2range [0:50] set yrange [0:50] -set label at 2,33 'U_{DS} [V] = 300' right -set label at 2,30 'U_{DS} [V] = 325' right -set label at 2,33 'U_{DS} [V] = 350' right -set label at 2,35 'U_{DS} [V] = 375' right -set label at 2,21 'U_{DS} [V] = 400' right -set label at 2,21 'U_{DS} [V] = 425' right -set label at 2,22 'U_{DS} [V] = 450' right -set label at 2,22 'U_{DS} [V] = 475' right -set label at 2,22 'U_{DS} [V] = 500' right -set label at 2,5 'U_{DS} [V] = 525' right +set label at 2,38 'U_{DS} [V] = 300' right +set label at 2,29 'U_{DS} [V] = 325' right +set label at 2,31 'U_{DS} [V] = 350' right +set label at 2,32 'U_{DS} [V] = 375' right +set label at 2,33 'U_{DS} [V] = 400' right +set label at 2,20 'U_{DS} [V] = 425' right +set label at 2,20 'U_{DS} [V] = 450' right +set label at 2,11 'U_{DS} [V] = 475' right +set label at 2,21 'U_{DS} [V] = 500' right +set label at 2,21 'U_{DS} [V] = 525' right set label at 2,11 'U_{DS} [V] = 550' right set label at 2,11 'U_{DS} [V] = 575' right set label at 2,11 'U_{DS} [V] = 600' right -set label at 2,11 'U_{DS} [V] = 625' right -set label at 2,4 'U_{DS} [V] = 650' right -set label at 2,4 'U_{DS} [V] = 650' right -set label at 2,4 'U_{DS} [V] = 700' right +set label at 2,11 'U_{DS} [V] = 600' right +set label at 2,11 'U_{DS} [V] = 600' right +set label at 2,11 'U_{DS} [V] = 600' right +set label at 2,11 'U_{DS} [V] = 600' right +set label at 2,11 'U_{DS} [V] = 600' right set y2tics unset ytics set ytics format '' unset output set terminal qt unset output -plot "/tmp/tempfile1" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 300' w l,"/tmp/tempfile2" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 325' w l,"/tmp/tempfile3" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 350' w l,"/tmp/tempfile4" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 375' w l,"/tmp/tempfile5" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 400' w l,"/tmp/tempfile6" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 425' w l,"/tmp/tempfile7" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 450' w l,"/tmp/tempfile8" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 475' w l,"/tmp/tempfile9" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 500' w l,"/tmp/tempfile10" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 525' w l,"/tmp/tempfile11" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 550' w l,"/tmp/tempfile12" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 575' w l,"/tmp/tempfile13" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 600' w l,"/tmp/tempfile14" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 625' w l,"/tmp/tempfile15" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 650' w l,"/tmp/tempfile16" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 675' w l,"/tmp/tempfile17" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 700' w l +plot "/tmp/tempfile1" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 300' w l,"/tmp/tempfile2" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 325' w l,"/tmp/tempfile3" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 350' w l,"/tmp/tempfile4" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 375' w l,"/tmp/tempfile5" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 400' w l,"/tmp/tempfile6" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 425' w l,"/tmp/tempfile7" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 450' w l,"/tmp/tempfile8" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 475' w l,"/tmp/tempfile9" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 500' w l,"/tmp/tempfile10" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 525' w l,"/tmp/tempfile11" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 550' w l,"/tmp/tempfile12" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 575' w l,"/tmp/tempfile13" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 600' w l,"/tmp/tempfile14" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 625' w l,"/tmp/tempfile15" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 650' w l,"/tmp/tempfile16" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 675' w l,"/tmp/tempfile17" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 700' w l,"/tmp/tempfile18" using ($1*0.004888):($2*0.048876) binary format="%int16%int16" endian=big title 'U_{DS} [V] = 725' w l diff --git a/main b/main index 17a4de3..6522fb2 100755 Binary files a/main and b/main differ diff --git a/main.cpp b/main.cpp index 74471d6..8eec356 100644 --- a/main.cpp +++ b/main.cpp @@ -82,9 +82,6 @@ void kennlinieZweiterQuadrant() drv.analogeAusgabe1(u_gs); drv.analogEingabeSequenz(0, &ba[0], 0, 1, &bb[0], 0, 0, delta, sample_count); - drv.delay(10); - drv.discard(); - drv.delay(10); curve = 0; for(uint16_t k = 0; k < sample_count + 1; k++) diff --git a/main.o b/main.o index 7ba2d8f..b589bad 100644 Binary files a/main.o and b/main.o differ diff --git a/test_plot b/test_plot index abc733e..afde276 100644 Binary files a/test_plot and b/test_plot differ