element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Test & Tools
  • Technologies
  • More
Test & Tools
Forum TENMA 72-13210 & Python UDP
  • Blog
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Test & Tools to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 8 replies
  • Subscribers 351 subscribers
  • Views 2957 views
  • Users 0 members are here
Related

TENMA 72-13210 & Python UDP

cfauvel
cfauvel over 2 years ago

Hi everyone,

Does anyone has been able to send UDP commands to a TENMA 72-13210 Power Load using a python 3.0 script ?

When I send an UDP command (*IDN? for example), I am unable to retrieve data from the UDP socket.

Best regards,

import os, sys
import re, string
import socket
import time
import logging


# Register logs from the module to the
# root logs
logs = logging.getLogger(__name__)




"""
    Power load class
"""
class Load():
    """
        Initialize everything
        @param  context     instrument context (ie. ip and port)
        @param  timeout     instrument timeout
        @return             none
    """
    def __init__(self,
                 context,
                 timeout = .5):
        # Open a pyvisa ethernet link to control the
        # power load
        try:
            self.ip = context['ip']
            self.port = context['port']
            logs.info("Open load (ip: %s, port: %d)" % (context['ip'],
                                                        context['port']))
        except:
            logs.error("Unable to open load (ip: %s, port: %d)" % (context['ip'],
                                                                   context['port']))

        # Configure power load by reading it's identifier
        # and resetting the device
        self.timeout = timeout
        print(self.query('*IDN?'))
        try:
            self.query('*REBOOT')
            time.sleep(1)
        except:
            logs.error("Unable to retrieve load identifier")
            logs.error("Ensure that load is VISA capable !")

    """
        Write function
        @param  self        object pointer
        @param  data        data command
        @return             none
    """
    def write(self, data):
        self.dev.sendto(data.encode(), (self.ip, self.port))
        logs.debug("Send data: %s" % data)

    """
        Read function
        @param  self        object pointer
        @return             data command
    """
    def read(self):
        try:
            data = self.dev.recv(64)
            print(data, server)
            logs.debug("Receive data: %s" % data)
            return data
        except:
            pass
           
    """
        Query function
        @param  self        object pointer
        @param  data        data command
        @return             data command        
    """
    def query(self, data):
        self.dev = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.dev.connect((self.ip, self.port))
        self.dev.settimeout(self.timeout)
        self.write(data + '\n')
        return self.read()




if __name__ == "__main__":
    load = Load(context = { 'ip' : "172.16.169.70",
                            'port' : 18190 })
  • Sign in to reply
  • Cancel

Top Replies

  • cfauvel
    cfauvel over 2 years ago in reply to baldengineer +3 verified
    Hi everyone, The TENMA 72-13210 doesn't support TCP/IP protocol, as stated in the datasheet, only UDP or serial connection can be used to control the device. I have already used PyVISA to send an IDN…
  • cstanton
    cstanton over 2 years ago in reply to cfauvel +2
    Fyi UDP is a part of the TCP/IP protocol. Funny the EEVBlog thread also links back to the element14 Community :D Need Windows USB Driver for TENMA 72-13210 (electronic dc-load 30A/120V 300W) But it…
  • cfauvel
    cfauvel over 2 years ago in reply to baldengineer +2
    In fact it's really easy with UDP and raw python sockets. I use the code below : """ Write function @param self object pointer @param data data command @return none """ def write ( self…
Parents
  • baldengineer
    0 baldengineer over 2 years ago

    Why UDP? Since you're opening a socket connection, shouldn't it be TCP?

    I haven't tried to open a direct socket connection via Python. But talking to the Multicomp Pro MP710259 (which I think is the same instrument as the Tenma, just different badge) over TCP/IP with pyVISA and using the pyvisa-py driver worked fine for me in this code:

    https://github.com/baldengineer/bald-efficiency

    Look at efficiency.py for the main script and then insts/instruments.py and insts/mp710259.py for stuff related to the load.

    I did find I had to insert a 100 millisecond wait on query(). For pyVISA that is the delay between sending the command and then reading back the response.

    Edit, I did not need the query delay. The delay in my code was for something else. (I have found it rarely hurts though.)

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • cfauvel
    +1 cfauvel over 2 years ago in reply to baldengineer

    Hi everyone,

    The TENMA 72-13210 doesn't support TCP/IP protocol, as stated in the datasheet, only UDP or serial connection can be used to control the device. I have already used PyVISA to send an IDN command but I always have a permission issue. 

    Ok, got it working using informations from EEVBlog forum : Cheap electronic load with Lan - KORAD KEL-103 - Anyone heard of it? - Page 1 (eevblog.com)

    Best regards,

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • cstanton
    0 cstanton over 2 years ago in reply to cfauvel

    Fyi UDP is a part of the TCP/IP protocol.

    Funny the EEVBlog thread also links back to the element14 Community :D  Need Windows USB Driver for TENMA 72-13210 (electronic dc-load 30A/120V 300W) 

    But it does look like someone provided an example python script https://www.eevblog.com/forum/testgear/cheap-electronic-load-with-lan-korad-kel-103-anyone-heard-of-it/msg2147542/?PHPSESSID=codijt2pie2gknahlcseoqbg4k#msg2147542 for anyone else looking amidst the weeds. 

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • baldengineer
    0 baldengineer over 2 years ago in reply to cfauvel

    To be clear, the Multicomp Pro / Tenma / Korad unit absolutely supports TCP or socket connections. I have used it. Additionally, the TENMA 72-13210 datasheet does not mention the protocol. Only that it supports LAN, Serial, and USB. So, I am not sure where this misconception is coming from.

    I know it uses TCP for two reasons: 1) pyVISA only establishes TCP connections. and 2) you can use a telnet client to connect to it. Telnet is a TCP-based protocol.

    Regarding a "permissions issue," I am not sure what that means. But if you provide details on that error, it might be possible to find an answer. Using pyVISA is significantly easier than trying to re-invent the wheel.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • cfauvel
    0 cfauvel over 2 years ago in reply to baldengineer

    In fact it's really easy with UDP and raw python sockets. I use the code below :

        """
            Write function
            @param  self        object pointer
            @param  data        data command
            @return             none
        """
        def write(self, data):
            dev = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            dev.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            dev.sendto(data.encode(), (self.ip, self.port))
            logs.debug("Send data: %s" % data)

        """
            Read function
            @param  self        object pointer
            @return             data command
        """
        def read(self):
            dev = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            dev.bind(("", self.port))
            dev.settimeout(self.timeout)
            try:
                data, addr = dev.recvfrom(2048)
                logs.debug("Receive data: %s" % data)
                return data.decode()[ : -1]
            except:
                pass

        """
            Query function
            @param  self        object pointer
            @param  data        data command
            @return             data command        
        """
        def query(self, data):
            self.write(data + '\n')
            return self.read()
     
    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • baldengineer
    0 baldengineer over 2 years ago in reply to cfauvel

    Interesting. I am glad you got it working. Thanks for the follow-up.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • baldengineer
    0 baldengineer over 2 years ago in reply to cfauvel

    Interesting. I am glad you got it working. Thanks for the follow-up.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube