Tektronix Technical Forums are maintained by community involvement. Feel free to post questions or respond to questions by other members. Should you require a time-sensitive answer, please contact your local Tektronix support center here.

Python Socket Control 1

Questions in this forum area are community supported. Tektronix does not regularly monitor or guarantee responses in this area.
Post Reply
Carl M
Tektronix Applications
Tektronix Applications
Posts: 796
Joined: July 30th, 2008, 4:45 pm
Country: United States

Python Socket Control 1

Post by Carl M » November 20th, 2009, 5:03 pm

For the instruments that support it.

Code: Select all

## Python Socket Control 1
# Date: 09-15-2009
# ==================
# Demonstrate how to communicate with Tektronix instruments using an TCP socket
# connection.
#
# COMPATIBILITY
# ==================
# All Windows based instruments with TekVISA v3.2 or later
# AWG400, 500, 600, 700
# ==================
#
# TESTED & DEVELOPED
# ==================
# Microsoft Windows XP SP3
# Python v2.6
# Ethernet (DHCP)
# DPO7254 FW v4.3.5 Build 6
# ==================
#
# Tektronix provides the following example "AS IS" with no support or warranty.
 
import socket
 
input_buffer = 2 * 1024
 
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("134.62.63.56", 4000))
 
cmd = "*idn?" + "\n"
s.send(cmd)
id = s.recv(input_buffer)
print id
 
cmd = "*rst" + "\n"
s.send(cmd)
 
s.close()
Tektronix Application Engineer

springday
Posts: 2
Joined: March 15th, 2010, 10:27 am

Re: Python Socket Control 1

Post by springday » August 23rd, 2010, 4:24 pm

When I tried your example, I got an error message saying:
'No connection could be made because the target machine actively refused it'

How can I get around that?
Thanks.

springday
Posts: 2
Joined: March 15th, 2010, 10:27 am

Re: Python Socket Control 1

Post by springday » August 24th, 2010, 10:32 am

I got around the previous error message.

Now I have another question. I have the following code to try to get hardcopy from the o'scope:

Code: Select all

        self.write("HARDCOPY:PORT ETHErnet")
        self.write("HARDCOPY:FORMAT BMP")
        self.write("HARDCOPY START")

        self.write("*WAI")

        fOut = file('tds.bmp', 'wb')
        wf = self.inst.recv(65536)
        fOut.write(wf)
        fOut.close()
However, what I received from the scope was:
...HTTP/1.1 100 Continue
I had no problem with the code when I communicated with the scopy via GPIB module. Now I am hoping to do the same thing over Ethernet. How can I get a hardcopy of scope screen image via a socket?


Thanks

Carl M
Tektronix Applications
Tektronix Applications
Posts: 796
Joined: July 30th, 2008, 4:45 pm
Country: United States

Re: Python Socket Control 1

Post by Carl M » September 9th, 2010, 4:21 pm

springday wrote:When I tried your example, I got an error message saying:
'No connection could be made because the target machine actively refused it'

How can I get around that?
Thanks.
firewall? socket server not started? wrong ip address? there are countless reasons why network connections are refused.
Tektronix Application Engineer

Carl M
Tektronix Applications
Tektronix Applications
Posts: 796
Joined: July 30th, 2008, 4:45 pm
Country: United States

Re: Python Socket Control 1

Post by Carl M » September 9th, 2010, 4:24 pm

springday wrote:
...HTTP/1.1 100 Continue
you cannot just connect to the first open port you find. your talking to a web server (likely escope). i doubt your instrument has socket support.

Code: Select all

# COMPATIBILITY
# ==================
# All Windows based instruments with TekVISA v3.2 or later
# AWG400, 500, 600, 700
# ==================
Tektronix Application Engineer

Lei_ZTR_Control
Posts: 2
Joined: October 10th, 2018, 10:02 am
Country: Canada

Re: Python Socket Control 1

Post by Lei_ZTR_Control » October 10th, 2018, 1:32 pm

Hi Carl,

I am using your program test my system. When I run the code, I constantly get the following response from TBS2000. Can you please advise what can go wrong here? I am using Python3.7 and just changed the cmd with encode() method and the id with the decode() method.

Many thanks.

Lei

UNKNOWN 400 Bad Request
Server: thttpd/2.25b 29dec2003
Content-Type: text/html; charset=UTF-8
Date: Wed, 10 Oct 2018 16:15:50 GMT
Last-Modified: Wed, 10 Oct 2018 16:15:50 GMT
Accept-Ranges: bytes
Connection: close
Cache-Control: no-cache,no-store

<HTML>
<HEAD><TITLE>400 Bad Request</TITLE></HEAD>
<BODY BGCOLOR="#cc9999" TEXT="#000000" LINK="#2020ff" VLINK="#4040cc">
<H2>400 Bad Request</H2>
Your request has bad syntax or is inherently impossible to satisfy.
<HR>
<ADDRESS><A HREF="http://www.acme.com/software/thttpd/">thttpd/2.25b 29dec2003</A></ADDRESS>
</BODY>
</HTML>

Lei_ZTR_Control
Posts: 2
Joined: October 10th, 2018, 10:02 am
Country: Canada

Re: Python Socket Control 1

Post by Lei_ZTR_Control » October 11th, 2018, 9:54 am

This has been solved. The issue was the firmware in the scope does not support sockets. After upgrading the firmware, it's working now.

Thanks.

Post Reply

Return to “Older and Obsolete Signal Sources”

Who is online

Users browsing this forum: No registered users and 8 guests