I would like to write some python code to download data from a pressure sensor we have, a Vaisala PTU300. This sensor connects to our router and can be contacted via a telnet session where simple commands spit out data on request, or it can spit out a continuous stream of data. Page 94 of the manual lists the commands you can send to the instrument. I'm quite new to python but do have some programming experience in Fortran so understand some structuring of programming languages.
I was hoping someone could help me with some ideas of what modules i should implement to do this. I've done a little research on the topic and found these past questions which have some relevance (How can I use python's telnetlib to fetch data from a device for a fixed period of time?, How to save the output of a telnet command by using python for an infinite time [closed]).
I have started to play with trying to use telnetlib to connect to the instrument with the following commands
import sys
import telnetlib
host = 'xxx.xxx.xxx.xxx'
tn=telnetlib.Telnet(host)
tn.open
tn.write('r')
tn.read_very_eager()
This results in one line of data being read
e.g.
2000-01-06 23:43:04 P= 980.0 T= -4.3 'C \r\n>r
however subsequent tn.read_very_eager() does not return anything.
I have tried different [variations][4] on this read command, e.g.
tn.read_until('C')
but any subsequent reads would not return anything. I believe some "blocking" might be occurring? not that i really know what that is.
I have also tried requesting just one reading using
tn.write('send')
tn.read_until('C')
but this would only return one reading and subsequent reads would return nothing.
[One][5] of the past stackoverflow questions suggested using the [asynchat][6] or [socket][7] modules to perform this kind of action. I have not tried using them yet. Do people think this is a better line of attack? The instrument requires no username or password to connect to it.
So my question would be, how can i best connect to this instrument (which package, telnetlib, asynchat, socket)?
How can I avoid the telnet connection being blocked? (i.e. only being able to retrieve one line of data)?
Any advice would be greatly appreciated, i appologise if this question has already been answered.
Regards
Oman
ps, sorry it wouldn't allow me to attach all my links