Querying a modem
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Querying a modem
I am trying to query a com port to see if a modem is present but I just cant get my head round the read from file command. it always returns empty and the result is always "eof"
i am using somthing along thlines of:
open file "COM1:" for update
send "AT" to file "COM1:"
read from file "COM1:" until crlf --I have tried until empty, "OK" , for 1 line , in 5seconds etc.. to no avail
if it contains "OK" then answer information "Modem found!" else answer error "Modem not found!"
close file "COM1:"
I always end up with "Modem not found!"
any help would be appreciated
i am using somthing along thlines of:
open file "COM1:" for update
send "AT" to file "COM1:"
read from file "COM1:" until crlf --I have tried until empty, "OK" , for 1 line , in 5seconds etc.. to no avail
if it contains "OK" then answer information "Modem found!" else answer error "Modem not found!"
close file "COM1:"
I always end up with "Modem not found!"
any help would be appreciated
n.allan,
Has the modem been installed properly? Does it work with other software? Can you actually make a connection with it to an internet provider or ehm... what do people use modems for these days? Are you sure that the modem is supposed to understand AT commands?
Mark
Has the modem been installed properly? Does it work with other software? Can you actually make a connection with it to an internet provider or ehm... what do people use modems for these days? Are you sure that the modem is supposed to understand AT commands?
Mark
Last edited by Mark on Fri Nov 30, 2007 4:49 pm, edited 1 time in total.
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
To explain a little further It is a siemens gsm modem connected to com1. I can communicate with it no probs at all using hyperterminal. It fully supports AT commands.
so typing AT then hitting return using hyperterminal returns "OK" like thus:
AT
OK
I think it has something to do with timing. I am obviously reading com1: at the wrong time. Reading the documentation it states that read from file will continue to read until eof, but even if I don't have the modem connected to com 1, it still returns empty and the result is still "eof"
I can't understand why rev takes it upon itself to timeout even when no data is present on the com port.
so typing AT then hitting return using hyperterminal returns "OK" like thus:
AT
OK
I think it has something to do with timing. I am obviously reading com1: at the wrong time. Reading the documentation it states that read from file will continue to read until eof, but even if I don't have the modem connected to com 1, it still returns empty and the result is still "eof"
I can't understand why rev takes it upon itself to timeout even when no data is present on the com port.
Hi n.allan,
Does this work?
Best,
Mark
Does this work?
Code: Select all
on checkModem
open file "COM1:" for update
write "AT" to file "COM1:"
read from file "COM1:" until cr -- or lf but not crlf
close file "COM1:"
answer it
end checkModem
Mark
Last edited by Mark on Fri Nov 30, 2007 4:49 pm, edited 1 time in total.
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
n.allan,
Have you already tried adding a line to wait for the modem to process the data?
write...
wait 250 millisecs with messages
read....
Best,
Mark
Have you already tried adding a line to wait for the modem to process the data?
write...
wait 250 millisecs with messages
read....
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Yes, I have tried that with different times in milliseconds and ticks, still nothing.
I am having some success using a seperate handler doing the reading and putting it after a field "Output". But I am finding that the seperate handler is putting the SENT Commands after the field as well as the RECIEVED commands? so when I send "AT" and recieve "OK" the field "Output" contains:
-------------------------------
AT
OK
AT
OK
-------------------------------
The recieving handler is as follows:
on CheckModem
open file "COM1:" for update
repeat
read from file "COM1:" until lf
put it after field "Output"
wait 1 tick with messages
next repeat
if tCancel is true then exit repeat --escape from the repeat loop
end repeat
close file "COM1:"
end CheckModem
(In the above example I sent "AT" to com1: twice)
I am having some success using a seperate handler doing the reading and putting it after a field "Output". But I am finding that the seperate handler is putting the SENT Commands after the field as well as the RECIEVED commands? so when I send "AT" and recieve "OK" the field "Output" contains:
-------------------------------
AT
OK
AT
OK
-------------------------------
The recieving handler is as follows:
on CheckModem
open file "COM1:" for update
repeat
read from file "COM1:" until lf
put it after field "Output"
wait 1 tick with messages
next repeat
if tCancel is true then exit repeat --escape from the repeat loop
end repeat
close file "COM1:"
end CheckModem
(In the above example I sent "AT" to com1: twice)
I am positive there is a bug in the read from file/driver "COMx:" command.
No matter what type of line ending I read "to" rev takes it upon itself to stop reading the string and return it. This is particularly unhandy if you you are tryig to interface GPS etc..
I have layed the modem handler above aside to work a "simpler" bit.
I am reading a simple 13 char string from "com1:" it begins with "#" and is terminated with <cr><lf> (ascii 13,10.)
so we have #S1O000000300150<cr><lf> tx every second
I have tried read from file/driver "comx:" until lf --cr --return etc...
I have even tried
put CharToNum(13) & CharToNum(10) into tLineTerminator
read from file "comx:" until tLineTerminator
sometimes it will return the whole string, then it will return partial strings.
I realy need it to read the whole string in order for me to split into chunks and make decisions based on those chunks. If I only get a partial read of the string, The chunks will be useless.
No matter what type of line ending I read "to" rev takes it upon itself to stop reading the string and return it. This is particularly unhandy if you you are tryig to interface GPS etc..
I have layed the modem handler above aside to work a "simpler" bit.
I am reading a simple 13 char string from "com1:" it begins with "#" and is terminated with <cr><lf> (ascii 13,10.)
so we have #S1O000000300150<cr><lf> tx every second
I have tried read from file/driver "comx:" until lf --cr --return etc...
I have even tried
put CharToNum(13) & CharToNum(10) into tLineTerminator
read from file "comx:" until tLineTerminator
sometimes it will return the whole string, then it will return partial strings.
I realy need it to read the whole string in order for me to split into chunks and make decisions based on those chunks. If I only get a partial read of the string, The chunks will be useless.