serialport 0.4.6 → 0.4.7
raw patch · 7 files changed
+207/−6 lines, 7 files
Files
- CHANGELOG.md +6/−0
- README.md +25/−0
- System/Hardware/Serialport/Posix.hsc +2/−1
- System/Hardware/Serialport/Types.hs +2/−2
- serialport.cabal +4/−1
- tests/Tests.hs +2/−2
- tests/haskell_serial_test/haskell_serial_test.ino +166/−0
+ CHANGELOG.md view
@@ -0,0 +1,6 @@+++4.7 (28/08/2014)+================++* Open in non-blocking mode, immediately reverting to blocking to fix OS-X problem
+ README.md view
@@ -0,0 +1,25 @@+Objectives+==========+* Cross platform: at least Linux, Windows and Mac OS.++Tests+=====++Setup+-----+* [Arduino Leonardo](http://arduino.cc/en/Main/arduinoBoardLeonardo) + [Sparkfun FTDI breakout board](https://www.sparkfun.com/products/718).+* Connections: TX, RX and GND++Prepare Arduino+---------------+* Upload arduino code using Arduino IDE or avrdude++Prepare haskell test program+----------------------------+* Configure cabal to build the tests: cabal configure --enable-tests.+* Build: cabal build++Running the tests+-----------------+* Run the tests: cabal test --test-options="/dev/ttyACM0 /dev/ttyUSB0"+
System/Hardware/Serialport/Posix.hsc view
@@ -73,7 +73,8 @@ -> SerialPortSettings -> IO SerialPort openSerial dev settings = do- fd' <- openFd dev ReadWrite Nothing defaultFileFlags { noctty = True }+ fd' <- openFd dev ReadWrite Nothing defaultFileFlags { noctty = True, nonBlock = True }+ setFdOption fd' NonBlockingRead False let serial_port = SerialPort fd' defaultSerialSettings return =<< setSerialSettings serial_port settings
System/Hardware/Serialport/Types.hs view
@@ -21,8 +21,8 @@ data StopBits = One | Two deriving (Show, Eq, Bounded)-data Parity = Even | Odd | NoParity deriving (Show, Eq, Bounded)-data FlowControl = Software | NoFlowControl deriving (Show, Eq, Bounded)+data Parity = Even | Odd | NoParity deriving (Show, Eq)+data FlowControl = Software | NoFlowControl deriving (Show, Eq) data SerialPortSettings = SerialPortSettings { commSpeed :: CommSpeed, -- ^ baudrate
serialport.cabal view
@@ -1,5 +1,5 @@ Name: serialport-Version: 0.4.6+Version: 0.4.7 Cabal-Version: >= 1.8 Build-Type: Simple license: BSD3@@ -12,6 +12,9 @@ synopsis: Cross platform serial port library. description: Cross platform haskell library for using the serial port. category: Hardware+Extra-Source-Files: README.md+ CHANGELOG.md+ tests/haskell_serial_test/haskell_serial_test.ino source-repository head type: git
tests/Tests.hs view
@@ -95,8 +95,8 @@ ("b19200 Serialport", testSerialport CS19200), ("b57600 Serialport", testSerialport CS57600), ("b115200 Serialport",testSerialport CS115200),- ("b9600 Handle", testHandle CS9600),- ("test delay", testDelay)+ ("b9600 Handle", testHandle CS9600)+ --("test delay", testDelay) ]
+ tests/haskell_serial_test/haskell_serial_test.ino view
@@ -0,0 +1,166 @@+static int test_running;+static uint8_t expected_char;++static const uint8_t lowest_expected_char = 0x00;+static const uint8_t highest_expected_char = 0xff;++// the setup routine runs once when you press reset:+void setup()+{+ // initialize the digital pin as an output.+ Serial.begin(9600);+ pinMode(13, OUTPUT);+}++++void ConsumeAllSerial()+{+ while( Serial.available() )+ Serial.read();+}++++// the loop routine runs over and over again forever:+void loop()+{+ if( Serial.available() )+ {+ int i = Serial.read();+ switch(i)+ {+ case 'a':+ Serial.write(i);+ Serial1.end();+ Serial1.begin(1200);+ ConsumeAllSerial();+ test_running = 1;+ expected_char = lowest_expected_char;+ break;+ case 'b':+ Serial.write(i);+ Serial1.end();+ Serial1.begin(2400);+ ConsumeAllSerial();+ test_running = 1;+ expected_char = lowest_expected_char;+ break;+ case 'c':+ Serial.write(i);+ Serial1.end();+ Serial1.begin(4800);+ ConsumeAllSerial();+ test_running = 1;+ expected_char = lowest_expected_char;+ break;+ case 'd':+ Serial.write(i);+ Serial1.end();+ Serial1.begin(9600);+ ConsumeAllSerial();+ test_running = 1;+ expected_char = lowest_expected_char;+ break;+ case 'e':+ Serial.write(i);+ Serial1.end();+ Serial1.begin(19200);+ ConsumeAllSerial();+ test_running = 1;+ expected_char = lowest_expected_char;+ break;+ case 'f':+ Serial.write(i);+ Serial1.end();+ Serial1.begin(57600);+ ConsumeAllSerial();+ test_running = 1;+ expected_char = lowest_expected_char;+ break;+ case 'g':+ Serial.write(i);+ Serial1.end();+ Serial1.begin(115200);+ ConsumeAllSerial();+ test_running = 1;+ expected_char = lowest_expected_char;+ break;+ case 'h':+ Serial.write(i);+ Serial1.end();+ Serial1.begin(9600);+ ConsumeAllSerial();+ test_running = 2;+ break;+ }+ }++ if( test_running == 1 )+ {+ while( Serial1.available() )+ {+ uint8_t i = Serial1.read() & 0xff;+ if( i == expected_char)+ {+ Serial1.write(expected_char);+ if( expected_char == highest_expected_char )+ {+ // test successfull+ Serial.println("ok");+ Serial1.flush();+ Serial1.end();+ test_running = 0;+ }+ else+ expected_char++;+ }+ else+ {+ Serial.print("expected char('");+ Serial.print(expected_char, HEX);+ Serial.print("') got ('");+ Serial.print(i, HEX);+ Serial.println("') test failed");+ }+ }+ }+ else if( test_running == 2 )+ {+ while( Serial1.available() )+ {+ uint8_t i = Serial1.read() & 0xff;+ switch( i )+ {+ case 'a':+ Serial1.write('a');+ Serial1.write('A');+ break;+ case 'b':+ Serial1.write('b');+ delay(50);+ Serial1.write('B');+ break;+ case 'c':+ Serial1.write('c');+ delay(150);+ Serial1.write('C');+ break;+ case 'd':+ Serial1.write('d');+ delay(200);+ Serial1.write('D');+ break;+ case 'e':+ // 50 ms delay+ delay(500);+ Serial1.write('E');+ break;+ default:+ test_running = 0;+ break;+ }+ }+ }+}+