Re: Help converting short Python prog.

new topic     » goto parent     » topic index » view thread      » older message » newer message
irv said...

This does what I need. Can someone convert this into Euphoria 4.1?

Untested.

-------------- 
-- Script listens to serial port and writes contents into a file 
-------------- 
 
sequence serial_port = "/dev/ttyUSB0" 
constant baud_rate = 115200 --In arduino, Serial.begin(baud_rate) 
constant write_to_file_path = "output.txt" 
 
constant output_file = open(write_to_file_path, "a") 
-- from http://stackoverflow.com/questions/12646324/how-to-set-a-custom-baud-rate-on-linux 
system(sprintf("stty -F %s %d", {serial_port, baud_rate}) 
constant ser = open(serial_port, "r") 
while 1 do 
    sequence line = gets(ser) 
    puts(1, line) 
    puts(output_file, line) 
end while 

Though this might be a little better:

object line = "" 
while sequence(line) with entry do 
    puts(1, line) 
    puts(output_file, line) 
  entry 
    line = gets(ser) 
end while 
close(ser) 
close(output_file) 

If you want to avoid the call to stty, you can instead try wrapping termios2:

http://stackoverflow.com/questions/4968529/how-to-set-baud-rate-to-307200-on-linux

http://www.comptechdoc.org/os/linux/programming/c/linux_pgcserial.html

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu