Use perl to send AT commands to the modem

微信扫一扫,分享到朋友圈

Use perl to send AT commands to the modem

I have a embedded linux box with perl 5.10 and a GSM modem attached. I have written a simple perl script to read/write AT commands through the modems device file (/dev/ttyACM0).

If i write a simle command like “ATZr” to the modem and wait for a response I receive very odd data like “nnnATZnn0nnOKnnnnnATZnnnn…” and the data keeps coming in. It almost seems like the response is garbled up with other data.

I would expect something like “ATZnOKn” (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 (I do not have Device::Serialport on my embedded linux perl installation):

open(FH, "+<", "/dev/ttyACM0") or die "Failed to open com port $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

I don’t think you need the while loop. This code should send the ATZ command, wait for the response, then print the response:

open(FH, "+>", "/dev/ttyACM0") or die "Failed to open com port $comport";
 print FH ("ATZn");
 $R = ;
 print $R;
 close(FH);

微信扫一扫,分享到朋友圈

Use perl to send AT commands to the modem

世界杯时间 天猫超市一小时达将在北京、杭州实现24小时不打烊

上一篇

比特币热度熄灭!韩国「泡菜溢价」几已消失殆尽

下一篇

你也可能喜欢

Use perl to send AT commands to the modem

长按储存图像,分享给朋友