Screen error: must be connected to a terminal

Discussion in 'Mac Programming' started by cloudydayagain, May 17, 2015.

  1. cloudydayagain, May 17, 2015
    Last edited by a moderator: May 18, 2015

    cloudydayagain macrumors newbie

    Joined:
    May 17, 2015
    #1
    I have Arduino Uno connected via USB to my Mac (Yosemite).

    I try to get sensor data to Mac.

    This works in Terminal app:

    Code:
    screen /dev/cu.usbmodem14131 9600
    I tried to run this in AppleScript Editor and it gives error "must be connected to a terminal":

    Code:
    do shell script "screen /dev/cu.usbmodem14131 9600"
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    Is there just the one line in your AppleScript? Or is it part of a larger script?

    If it's part of a larger script, please post the whole thing, and please use CODE tags.

    If that's the only line in the AppleScript, then it can't possibly work because there's no way you can input or output anything to it. The 'screen' command requires a tty, either a real character device or a pseudo-tty. A Terminal window is normally opened to a pseudo-tty, whose name is like ttyp1. That 'p' in the name means a pseudo-tty.


    You should probably describe your goal or intention, i.e. what you want to achieve or accomplish, rather than posting how you're trying to achieve it.

    If we know what your goal is, we may be able to tell you how to achieve it. Not knowing the goal, all anyone can do is tell you why what you posted didn't work. The brief description you gave is too vague. "I try to get sensor data to Mac." doesn't say anything about the context of the sensor data.

    For example, if your goal is to have a double-clickable AppleScript that opens a Terminal window and runs 'screen' to connect to your Arduino, that's a clear and attainable goal. But it's also a completely different goal than making an AppleScript that automatically tells the Arduino to do something.
     
  3. cloudydayagain thread starter macrumors newbie

    Joined:
    May 17, 2015
    #3
    Code:
    do shell script "screen /dev/cu.usbmodem14131 9600 >> path_to_text_file.txt"
    This is part of script. Everything else works but i have never used screen before and never communicated with serial/terminal/tty things and it fails. Path to text file is okay too.

    I want to get sensor data from Arduino Uno to text file in my Mac. I don't want to use SD-card in Arduino for logging in this case.

    Connection between Arduino and Mac works because i can see sensor data in Arduino serial window and Mac Terminal app.
     
  4. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #4
    If you have no intention of using a terminal, why are you using screen? As mentioned, screen requires a terminal.
     
  5. cloudydayagain thread starter macrumors newbie

    Joined:
    May 17, 2015
    #5
    I didn't know screen is not suitable in this case.

    What i should use and what is correct code which works? Thanks
     
  6. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #6
    Have you tried cat?
     
  7. cloudydayagain thread starter macrumors newbie

    Joined:
    May 17, 2015
    #7
    I checked out cat manual and it talks about reading files.

    Arduino sends stream of data.
     
  8. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #8
    Yeah, and what do you think /dev/cu.usbmodem14131 is? It's a file. So have you tried cat? You should be able to do this in Terminal directly, the only question about launching this from Applescript is if the script waits indefinitely and then kills cat when aborted.
     
  9. mfram macrumors 65816

    Joined:
    Jan 23, 2010
    Location:
    San Diego, CA USA
    #9
    Yep. In Unix, everything is a file. So try:

    Code:
    cat /dev/cu.usbmodem14131 > /path/to/file.txt
     
  10. cloudydayagain thread starter macrumors newbie

    Joined:
    May 17, 2015
    #10
    I get this error:

    cat: /dev/cu.usbmodem14131: No such file or directory
    cat: 9600: No such file or directory

    Maybe this 9600 is baud rate and it is wrong?
     
  11. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #11
    But you said that this file worked with 'screen' in your first post. Perhaps try: ls /dev/cu.* and see what comes up.

    9600 is baud rate, but it's an argument to 'screen' so you don't need that now.
     
  12. cloudydayagain thread starter macrumors newbie

    Joined:
    May 17, 2015
    #12
    Thanks. Works but not.

    Number in name of modem seems to change now and then so after i used this:

    do shell script "cat /dev/cu.usbmodem1413 9600 >> " & path_to_text_file

    Then AppleScript Editor script logged to text file, but then i saw in network preferences 2 usb modems so i deleted both. When i connected Uno i didn't get dialog saying new network interface detected. After i tried different USB-cables without usb-hub i got new usb modem to network preferences (without dialog) but it's "not configured" so i'm not sure is that okay?

    Port menu shows: cu.usbmodem1413 (Arduino Uno)

    Sensor data comes okay to Arduino IDE serial window but now if i try this in AppleScript Editor

    do shell script "cat /dev/cu.usbmodem1413 9600 >> " & path_to_text_file

    i still get same error:

    cat: /dev/cu.usbmodem1413: No such file or directory
    cat: 9600: No such file or directory
     
  13. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #13
    Then there is no file called /dev/cu.usbmodem1413, it's not related to cat, you would get the same error with screen.

    Both 'screen' and 'cat' are programs, each of them takes arguments, like a file name. In the case of 'screen' it accepts a boud rate argument, cat does not. That's why cat is looking for a file called 9600, there is no such file, and it makes no sense to call 'cat' with 9600 since it's a 'screen' argument.
     
  14. cloudydayagain thread starter macrumors newbie

    Joined:
    May 17, 2015
    #14
    Thanks. I have learned lots of new things in past few days about unix.

    After i removed 9600, i still get error: "cat: /dev//dev/cu.usbmodem1413: No such file or directory"
     
  15. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #15
    Well, then the file doesn't exist. But as you noted earlier this file appears under slightly different names. But you can list all files called /dev/cu.usbmodem* with a wildcard added.

    Code:
    ls /dev/cu.usbmodem*
    And it may even work to use that wildcard in your 'cat' line, assuming you have one Arduino connected (haven't tried this, but you can). Cat, short for concatenate will concatenate all files to the log. But look for the correct name of the device file first.
     
  16. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #16
    That command will never work. Look very carefully at the name:
    /dev//dev/cu.usbmodem1413
    The part I hilited in red shouldn't be there.

    If that wasn't exactly what the actual error message was, then you mistyped it in your post. If that was the exact error message, then you should take more care with what command you type or paste in.

    When posting error message, please copy and paste them exactly as they appear. It would also be a good idea to copy and paste the exact command you used, rather than retyping it in a post.

    Accuracy is important.
     
  17. mfram macrumors 65816

    Joined:
    Jan 23, 2010
    Location:
    San Diego, CA USA
    #17
    Without using screen you may have to configure the serial port before using cat. You'd do that with the 'stty' command.

    To print the confiugration:

    Code:
    stty -a -f /dev/cu.usbmodem1413
    You may have to set the configuration:

    Code:
    stty -f /dev/cu.usbmodem1413 9600
     
  18. sero macrumors member

    Joined:
    Aug 28, 2008
    #18
    what is the screen command you guys are talking about. It can't be GNU screen..
     
  19. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #19
  20. sero macrumors member

    Joined:
    Aug 28, 2008
    #20
    I guess I don't see the point of what OP was trying to do then
     
  21. cloudydayagain thread starter macrumors newbie

    Joined:
    May 17, 2015
    #21
    Thanks. This works:

    Code:
    stty -a -f /dev/cu.usbmodem1413
    
    stty -f /dev/cu.usbmodem1413 9600
     

Share This Page