Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #62094 > unrolled thread

Re: [newbie] trying socket as a replacement for nc

Started byJean-Michel Pichavant <jeanmichel@sequans.com>
First post2013-12-16 20:21 +0100
Last post2013-12-16 13:01 -0800
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Re: [newbie] trying socket as a replacement for nc Jean-Michel Pichavant <jeanmichel@sequans.com> - 2013-12-16 20:21 +0100
    Re: [newbie] trying socket as a replacement for nc Jean Dubois <jeandubois314@gmail.com> - 2013-12-16 13:01 -0800

#62094 — Re: [newbie] trying socket as a replacement for nc

FromJean-Michel Pichavant <jeanmichel@sequans.com>
Date2013-12-16 20:21 +0100
SubjectRe: [newbie] trying socket as a replacement for nc
Message-ID<mailman.4232.1387221677.18130.python-list@python.org>

----- Original Message -----
> On Tue, Dec 17, 2013 at 5:26 AM, Jean Dubois
> <jeandubois314@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 :)


JM  


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

[toc] | [next] | [standalone]


#62104

FromJean Dubois <jeandubois314@gmail.com>
Date2013-12-16 13:01 -0800
Message-ID<b1f1a46a-78f1-4086-8f5c-2299b4186c30@googlegroups.com>
In reply to#62094
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
> > <jeandubois314@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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web