io_eth_cmd.py
Go to the documentation of this file.
00001 """--------------------------------------------------------------------
00002 COPYRIGHT 2013 SEGWAY Inc.
00003 
00004 Software License Agreement:
00005 
00006 The software supplied herewith by Segway Inc. (the "Company") for its 
00007 RMP Robotic Platforms is intended and supplied to you, the Company's 
00008 customer, for use solely and exclusively with Segway products. The 
00009 software is owned by the Company and/or its supplier, and is protected 
00010 under applicable copyright laws.  All rights are reserved. Any use in 
00011 violation of the foregoing restrictions may subject the user to criminal 
00012 sanctions under applicable laws, as well as to civil liability for the 
00013 breach of the terms and conditions of this license. The Company may 
00014 immediately terminate this Agreement upon your use of the software with 
00015 any products that are not Segway products.
00016 
00017 The software was written using Python programming language.  Your use 
00018 of the software is therefore subject to the terms and conditions of the 
00019 OSI- approved open source license viewable at http://www.python.org/.  
00020 You are solely responsible for ensuring your compliance with the Python 
00021 open source license.
00022 
00023 You shall indemnify, defend and hold the Company harmless from any claims, 
00024 demands,liabilities or expenses, including reasonable attorneys fees, incurred 
00025 by the Company as a result of any claim or proceeding against the Company 
00026 arising out of or based upon: 
00027 
00028 (i) The combination, operation or use of the software by you with any hardware, 
00029     products, programs or data not supplied or approved in writing by the Company, 
00030     if such claim or proceeding would have been avoided but for such combination, 
00031     operation or use.
00032  
00033 (ii) The modification of the software by or on behalf of you 
00034 
00035 (iii) Your use of the software.
00036 
00037  THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES,
00038  WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
00039  TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00040  PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
00041  IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
00042  CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
00043  
00044  \file   io_eth_cmd.py
00045 
00046  \brief  This module contains the ethernet UDP communication protocol
00047 
00048  \Platform: Cross platform
00049 --------------------------------------------------------------------"""
00050 from utils import convert_byte_data_to_U32
00051 import socket
00052 
00053 class IO_ETHERNET:
00054     def __init__(self,rmp_address):
00055         
00056         self.success = True
00057         
00058         """
00059         Initialize link parameters
00060         """
00061         my_address = ('',rmp_address[1])
00062 
00063         """
00064         Initialize the UDP connection
00065         """
00066         self.conn = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
00067         self.conn.setblocking(False)
00068         self.conn.bind(my_address)
00069         try:
00070             self.conn.connect(rmp_address)
00071         except:
00072             self.success = False
00073 
00074     def Send(self,data):
00075         try:
00076             self.conn.sendall(data)            
00077         except:
00078             pass
00079     
00080     def Receive(self,num_of_return):
00081         
00082         """
00083         The number of bytes expected is the number of 32-bit messages times
00084         the bytes per 32-bit word
00085         """    
00086         num_of_bytes = num_of_return * 4
00087         
00088         """
00089         Try receiving the data up to a maximum size. If it fails
00090         empty the data
00091         """
00092         try:
00093             data = self.conn.recv(1024)
00094         except:
00095             data = []
00096             
00097         """
00098         If the data is the length expected, convert the byte data to U32 data and return it.
00099         Otherwise return the None type.
00100         """
00101         if (len(data) == num_of_bytes):
00102             return_data = convert_byte_data_to_U32(data);
00103         else:
00104             return_data = None; 
00105             
00106         return return_data;
00107 
00108     def Close(self):
00109         self.conn.shutdown(socket.SHUT_RDWR)
00110         self.conn.close()


python_ethernet_rmp
Author(s): SEGWAY Inc.
autogenerated on Sat Jun 8 2019 19:17:25