digital_newbie has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I am trying to control an OMAP with Linux, from a Windows laptop running Perl via serial port. I could open serial port (COM1) and send commands, but not able to execute them by sending the enter key. I tried \n but it only moving the cursor to the next line, and not imitating enter key. Code is below. Any suggestions? Please help!!

open( PORT, "+>COM1") or die "Cant open COM1 - $!"; $msg="ls\n"; print PORT $msg;

The output comes as

.#ls |

but doesn't execute..

Thanks
Joseph
https://nurosoft.id/
https://flits.id/

Code tags and various other formatting corrected by Grandfather

Replies are listed 'Best First'.
Re: transferring \n to linux from perl via serial port
by stevieb (Canon) on Nov 28, 2020 at 16:30 UTC

    Just a guess, and I have no configuration to test with currently, but try sending \r\n and see if that helps. A lot of software requires a carriage return (\r) and a newline (\n) to be sent in.

      Just a guess, and I have no configuration to test with currently, but try sending \r\n and see if that helps.

      Sorry, I think that's unlikely to help, as on Windows, that will cause \r\r\n to be transmitted - see my post.

Re: transferring \n to linux from perl via serial port
by haukex (Bishop) on Nov 29, 2020 at 11:36 UTC
    from a Windows laptop running Perl via serial port

    Because this is Windows, the default :crlf PerlIO layer is converting your "ls\n" into "ls\x0D\x0A" (i.e., CRLF), which might be the source of your issues. Try binmode PORT; after your open to see if that helps. If it doesn't help, you'll have to check the specifications of the serial protocol for what is expected.

    By the way, Use strict and warnings, and see also "open" Best Practices in regards to using three-agrument open and lexical filehandles.

Re: transferring \n to linux from perl via serial port
by LanX (Cardinal) on Nov 28, 2020 at 20:18 UTC
    on a side note, you can set $\ to whatever newline-code is needed.

    it'll be appended to every print then.

    Please edit your post and change <.code> to </code> (considered)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery