Perl for cummunicating with modem over serial

Home Forums MultiConnect OCG Perl for cummunicating with modem over serial

Tagged: , , , ,

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #4777

    Hello
    I have written a simple perl script to read/write AT commands through the modems device file (/dev/ttyACM0) on my OCG-E H5.

    If i write a simle command like “ATZ\r” to the modem and wait for a response I receive very odd data like “\n\n\nATZ\n\n0\n\nOK\n\n\n\n\nATZ\n\n\n\n…” and the data keeps coming in. It almost seems like the response is garbled up with other data.

    I would expect something like “ATZ\nOK\n” (if echo is enabled).

    If i send the “ATZ” command manually with e.g. minicom everything works as expected.

    This leads me to think it might be some kind of perl buffering issue, but that’s only guessing.

    I open the device in perl like this:

    
    open(FH, "+>", "/dev/ttyACM0") or die "Failed to open $comport";
    

    And read the response one byte at a time with:

    
    while(1) {
        my $response;
        read(FH, $response, 1);
        printf("hex response '0x%02X'\n", ord $response);
    }
    

    Am I missing some initialization or something else to get this right?

    Regards
    Klaus

    #4791

    Found the answer.

    It was not with perl.
    It was simply my low level tty settings that were way off.

    It seems that tty’s support a range of \r and \n translation settings.
    Set the tty in “raw” mode to receive exactly what your tty device sent fixed the behaviour.

    Simply issue: “stty -F /dev/my_tty raw”

    //Klaus

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.