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


Groups > comp.lang.python > #62040

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

Date 2013-12-16 11:42 +0100
From Jean-Michel Pichavant <jeanmichel@sequans.com>
Subject Re: [newbie] trying socket as a replacement for nc
Newsgroups comp.lang.python
Message-ID <mailman.4198.1387190528.18130.python-list@python.org> (permalink)

Show all headers | View raw


> Did you try
> 
> import telnetlib
> 
> ?
> 
> Note that in the code above I forgot the EOF, which is very much
> dependent of the equipment itself.
> 
> You may have to write
> t.write('*IDN?\n')
> or
> t.write('IDN?\n\r')
> 
> JM


Additionally, here's the code we're using for our signal generators, just to give you a broad idea:

	def getError(self):
		error = self._extractRsp(self._sendCmd('SYST:ERR?', 10))
		if '"No error"' in error:
			return None
		else:
			return error

	def _sendCmd(self, aCmd, timeout):
		self.send(str(aCmd) + self.SEND_LFCR)

		waitPattern = [self.PROMPT]
		try:			
			index, _, rsp= self._telnet.expect(waitPattern, timeout)
		except  EOFError:
			self._logger.error('Connection unexpectedly closed while sending/reading/ data.')
			raise MxgError('Connection unexpectedly closed while sending the command "%s"' % aCmd)

		if index == -1:
			raise MxgError('Timeout occurred while sendind the command "%s"' % aCmd)

		return rs


	def _extractRsp(self, rawRsp):
		# the returned string should be something like '\r\n<response>\r\n<prompt>'
		# or '\r\n<prompt>'
		# tries to extract the response only, removing the additional carriage returns and prompt
		rawRsp = rawRsp.replace(self.READ_LFCR+self.PROMPT, '')
		if rawRsp.startswith(self.READ_LFCR):
			rawRsp = rawRsp[2:]
		return rawRs


-- 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.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: [newbie] trying socket as a replacement for nc Jean-Michel Pichavant <jeanmichel@sequans.com> - 2013-12-16 11:42 +0100

csiph-web