Op maandag 16 december 2013 20:21:15 UTC+1 schreef Jean-Michel Pichavant: > ----- Original Message ----- > > On Tue, Dec 17, 2013 at 5:26 AM, Jean Dubois > > <jeandubois...@gmail.com> wrote: > > >> Try something simple first: > > >> import telnetlib > > >> host = '10.128.59.63' > > >> port = 7000 > > >> t = Telnet(host, port) > > >> def flush() > > >> t.read_very_eager() > > >> def sendCmd(cmd) > > >> t.write('%s\n' % cmd) > > >> return flush() > > >> flush() > > >> print sendCmd('*IDN?') > > >> print sendCmd('*OPC?') > > > Still no success: > > > jean@mantec:~$ ./test.py > > > File "./test.py", line 7 > > > def flush() > > > ^ > > > SyntaxError: invalid syntax > > > > > > > > > Tried it both with python2 and python3, same error... > > > > Folks, the OP isn't an expert. Please test your scripts before > > posting! > > > > I don't have everything I need to test this fully, but here's a > > variant of the above that's at least syntactically correct: > > > > from telnetlib import * > > host = '10.128.59.63' > > port = 7000 > > t = Telnet(host, port) > > def flush(): > > t.read_very_eager() > > def sendCmd(cmd): > > t.write('%s\n' % cmd) > > return flush() > > flush() > > print sendCmd('*IDN?') > > print sendCmd('*OPC?') > > > > It's written for Python 2, so use that interpreter. > > > > ChrisA > It was done on purpose, for educational purpose... :) > My bad, however I should point that learning the very basic of a language by > implementing a low level equipment remote protocol is rather ambitious. > By experience I know that you are annoyed by a crapload of nasty details > without even caring about the python syntax, including: > * LF/CR sequence > * Inconsistent answer pattern, depending on the equipment vendor > * broken netcode that can block the remote server > * timeouts > * poor equipment feedback > I still wish Jean a great success :) I'm a newbie in Python programming that is very much true, and contrary to what you seem to suggest I did my homework: I succeeded already in writing a Python-script which communicates directly over rs232 with the same device which I now am trying to connect to via a rs232-ethernet adapter. So I thought it would be simply a matter of communicating the same commands as I did before. Here are some parts of my code: serkeith = serial.Serial('/dev/ttyUSB0', 9600, 8, timeout=5, xonxoff=1) serkeith.write("*RST" + "\n") #turn off concurrent functions serkeith.write(":SENS:FUNC:CONC OFF" + "\n") #current source function serkeith.write(":SOUR:FUNC CURR" + "\n") #volt sense function serkeith.write(":SENS:FUNC 'VOLT:DC'" + "\n") #105V compliance #serkeith.write(":SENS:VOLT:PROT 105" + "\n") compliancestring=':SENS:VOLT:PROT '+str(compliancevalue) + '\n' serkeith.write(compliancestring) . . keithleymeasurement=serkeith.readline().split(',')
Also I got it working with nc and telnet, I just don't know how to accomplish this using python. Tomorrow I'll look further at some a the more recent suggestions kind regards, jean -- https://mail.python.org/mailman/listinfo/python-list