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


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

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

Started byJean-Michel Pichavant <jeanmichel@sequans.com>
First post2013-12-16 17:44 +0100
Last post2013-12-16 13:42 -0500
Articles 4 — 4 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 17:44 +0100
    Re: [newbie] trying socket as a replacement for nc Jean Dubois <jeandubois314@gmail.com> - 2013-12-16 10:26 -0800
      Re: [newbie] trying socket as a replacement for nc Chris Angelico <rosuav@gmail.com> - 2013-12-17 05:35 +1100
      Re: [newbie] trying socket as a replacement for nc Dave Angel <davea@davea.name> - 2013-12-16 13:42 -0500

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

FromJean-Michel Pichavant <jeanmichel@sequans.com>
Date2013-12-16 17:44 +0100
SubjectRe: [newbie] trying socket as a replacement for nc
Message-ID<mailman.4222.1387212273.18130.python-list@python.org>
> This is what I got using telnet:
> [jean:~] $ telnet 10.128.59.63 7000
> Trying 10.128.59.63...
> Connected to 10.128.59.63.
> Escape character is '^]'.
> *IDN?
> KEITHLEY INSTRUMENTS INC.,MODEL 2425,1078209,C32   Oct  4 2010
> 14:20:11/A02  /E/
>                                                                  H
> 
> after pressing CTRL-ALT-ALTGR-] I get this:
> ^[^]
> after which I get the telnet-prompt
> >telnet
> and I can quit telnet by entering quit
> 
> 
> kind regards,
> jean
> --
> https://mail.python.org/mailman/listinfo/python-list


Looks like you don't have any prompt.
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?')


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]


#62088

FromJean Dubois <jeandubois314@gmail.com>
Date2013-12-16 10:26 -0800
Message-ID<a71c4874-2fbc-439d-bc2a-483feb4f3080@googlegroups.com>
In reply to#62076
Op maandag 16 december 2013 17:44:31 UTC+1 schreef Jean-Michel Pichavant:
> > This is what I got using telnet:
> > [jean:~] $ telnet 10.128.59.63 7000
> > Trying 10.128.59.63...
> > Connected to 10.128.59.63.
> > Escape character is '^]'.
> > *IDN?
> > KEITHLEY INSTRUMENTS INC.,MODEL 2425,1078209,C32   Oct  4 2010
> > 14:20:11/A02  /E/
> >                                                                  H
> > 
> > after pressing CTRL-ALT-ALTGR-] I get this:
> > ^[^]
> > after which I get the telnet-prompt
> > >telnet
> > and I can quit telnet by entering quit
> > 
> > 
> > kind regards,
> > jean
> > --
> > https://mail.python.org/mailman/listinfo/python-list
>
> Looks like you don't have any prompt.
> 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...

kind regards,
jean

[toc] | [prev] | [next] | [standalone]


#62089

FromChris Angelico <rosuav@gmail.com>
Date2013-12-17 05:35 +1100
Message-ID<mailman.4228.1387218961.18130.python-list@python.org>
In reply to#62088
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

[toc] | [prev] | [next] | [standalone]


#62091

FromDave Angel <davea@davea.name>
Date2013-12-16 13:42 -0500
Message-ID<mailman.4230.1387219303.18130.python-list@python.org>
In reply to#62088
On Mon, 16 Dec 2013 10:26:14 -0800 (PST), Jean Dubois 
<jeandubois314@gmail.com> wrote:


>   File "./test.py", line 7
>     def flush()
>               ^
> SyntaxError: invalid syntax

A definition line needs to end with a colon (fix the other as well)

-- 
DaveA

[toc] | [prev] | [standalone]


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


csiph-web