Read from serial port

binaryjesus coolman.guron at gmail.com
Thu Aug 14 04:47:16 EDT 2008


On Aug 14, 6:11 am, mmrash... at gmail.com wrote:
> Hi,
> I am newbie in python. I am working on Telit GM862 GPS/GPRS module
> which has python interpreter built in. But it seems this problem is
> pretty much related to general python structure.
>
> I need a promt/terminal when the device is connected to PC. If user
> enters a command by serial port and press "Enter" then the data is
> read by the device and work on the command. This is similar to
> readline() function. Unfortunately there is no readline() function for
> GM862 device. The following functions are available for serial port
> data receive-
>
> SER.read() - reads whole string at a time from buffer
> SER.receive(timeout) - reads  if there is any input in the buffer
> andwait for the input upto timeout
> SER.receivebyte(timeout) - reads  if there is any byte sent in the
> buffer and wait for the input upto timeout
>
> Now, is this possible to build a readline() using the functions above?
> Can I redirect the terminal or serial port data to receive it as a
> whole string when entered "\n"?
>
> Please advise me how can I solve this problem.
>
> Thanks a lot.

Well i dont think its much of a problem.
What i think you should be doing is to read the data into a secondary
buffer. it could be a simple string or a specialized buffer class. You
would need a method to update() this secondary buffer. ie read from
port and append the read data to our buffer.

That done you can easily make a readline function. lol i think even a
15yr old can make a readline() from here.

btw does ur gm862 support multiple thread? if yes u can put the
update() function code and also a method launcher when ever a
particular command is sent to the device using a serial connection!

hope it helps !
BJ



More information about the Python-list mailing list