Haskell:串行接收数据未正确打印

时间:2015-07-28 14:12:05

标签: haskell arduino serial-port

我试图从我的Arduino Serial.println("No Format");接收数据。当我打开arduino-serial-monitor时,我可以看到输出的结果。

No Format
No Format
...

我使用 serialport package.但是ghci上打印的输出是:

*Main> main
"\r\nNo Forma"
"t\r\nNo Form"
"at\r\nNo For"
"mat\r\nNo Fo"
"rmat\r\nNo F"
"ormat\r\nNo "
"Format\r\nNo"
" Format\r\nN"
"o Format\r\n"
...
...
"\nNo"
" For"
"mat\r"
"\nNo "
"Form"
"at\r\n"
....

Haskell中:

import qualified Data.ByteString.Char8 as B
import System.Hardware.Serialport
import System.IO
import Control.Monad

main :: IO ()
main = forever $ do
  let port = "/dev/ttyACM0"
  s <- openSerial port SerialPortSettings { commSpeed = CS9600,
                                            bitsPerWord = 8,
                                            stopb = One,
                                            parity = NoParity,
                                            flowControl = NoFlowControl,
                                            timeout = 10 }
  recv s 10 >>= print
  closeSerial s

Arduino的:

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println("No Format");
}

任何帮助都会很棒。感谢。

2 个答案:

答案 0 :(得分:2)

你收到一个&#34; \ n&#34;字符。也许是这样的:

DECLARE @Search NVARCHAR(50) = 'Michael Jordan'

SELECT
FirstName, 
SecondName, 
LastName, 
Company
FROM tableName
WHERE
FirstName LIKE '%' + @Search + '%' OR
SecondName LIKE '%' + @Search + '%' OR
LastName LIKE '%' + @Search + '%' OR
Company LIKE '%' + @Search + '%'

还有改进的余地,但它确实有效!

答案 1 :(得分:0)

Using B.putStr instead of print fixed the problem. Thanks to @pat.