├── kukavarproxy_read_write_msg_format.png ├── python ├── example.py └── kukavarproxy.py ├── c++ ├── kukavarproxy_msg_format.pro └── main.cpp └── README.md /kukavarproxy_read_write_msg_format.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akselov/kukavarproxy-msg-format/HEAD/kukavarproxy_read_write_msg_format.png -------------------------------------------------------------------------------- /python/example.py: -------------------------------------------------------------------------------- 1 | from kukavarproxy import * 2 | robot = KUKA('172.31.1.147') 3 | 4 | robot.write("$OV_PRO",33) 5 | print (robot.read("$OV_PRO")) -------------------------------------------------------------------------------- /c++/kukavarproxy_msg_format.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2014-09-26T15:30:11 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core 8 | QT += network 9 | 10 | QT -= gui 11 | 12 | TARGET = kukavarproxy_msg_format 13 | CONFIG += console 14 | CONFIG -= app_bundle 15 | 16 | TEMPLATE = app 17 | 18 | 19 | SOURCES += main.cpp 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # kukavarproxy Message Format 2 | 3 | ## 1. Description 4 | kukavarproxy is an TCP/IP interface to Kuka robots that allows for reading and writing variables and data structures of the controlled manipulators. 5 | 6 | ## 2. How it works 7 | The kukavarproxy is a TCP/IP server that listens for network messages on the TCP port 7000, the reads and writes data to the KRC system variables. 8 | kukavarproxy message format is 9 | * msg ID in HEX 2 bytes 10 | * msg length in HEX 2 bytes 11 | * read (0) or write (1) 1 byte 12 | * variable name length in HEX 2 bytes 13 | * variable name in ASCII # bytes 14 | * variable value length in HEX 2 bytes 15 | * variable value in ASCII # bytes 16 | 17 | ## 3. Usage 18 | The KRC robot controller runs the Microsoft Windows operating system. The teach pendant shows an “HMI” which is a program that KUKA developed to run on Windows and it is the interface that the robot user has to manipulate the robot through. 19 | In order to establish an Ethernet (TCP/IP) connection, you first need to run kukavarproxy on the controllers operating system, then configure the network connection from KUKA "HMI". 20 | ### 3.1. Copying kukavarproxy to the operating system on the KRC: 21 | * Get the kukavarproxy from https://sourceforge.net/projects/openshowvar/files/openshowvar/REV%200.13.0/kukavarproxy-6_1.rar/download or from https://github.com/aauc-mechlab/JOpenShowVar/tree/master/KUKAVARPROXY%20rev%206.1.0.101 22 | * Unpack and copy the folder to a USB flash drive 23 | * Plug it to the KRC (not the teach pendant) 24 | * Log in as an Expert or Administrator. For KR C4: `KUKA Menu -> Configuration -> User Group`. Defaulf password is `kuka` 25 | * Minimize the "HMI". For KR C4:`KUKA Menu -> Startup -> Service -> Minimize HMI` 26 | * Copy kukavarproxy folder to the Desktop (or anywhere else) 27 | * Start the KUKAVARPROXY.exe 28 | * If you have a problem with the file `cswsk32.ocx`, Use this command in the Administrator Command Prompt `regsvr32.exe c:\asdf\cswsk32.ocx` while changing the `asdf` with the true path to the file. 29 | * You can make this program start automatically on reboot by creating a shortcut of KUKAVARPROXY.exe in `Windows Start -> All Programs -> Right click Startup -> Open` 30 | ### 3.2. HMI Network Configuration: 31 | * Connect the robot to a network. (private one is recommended) 32 | * Configure the KRC IP. For KR C4: `KUKA Menu -> Startup -> Network Configuration` 33 | * Unlock port 7000. For KR C4: `KUKA Menu -> Startup -> Network Configuration -> Advanced` 34 | * `NAT -> Add Port -> Port number 7000` 35 | * Set permitted protocols: `tcp/udp` 36 | 37 | ## 4. Resources 38 | * http://sourceforge.net/projects/openshowvar/ 39 | * https://github.com/aauc-mechlab/jopenshowvar/ 40 | * http://filipposanfilippo.inspitivity.com/publications/jopenshowvar-an-open-source-cross-platform-communication-interface-to-kuka-robots.pdf 41 | * https://www.robodk.com/forum/attachment.php?aid=4 -------------------------------------------------------------------------------- /c++/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | QByteArray formatMsg(QByteArray msg, unsigned short idMsg){ 6 | 7 | const char READVARIABLE=0; 8 | 9 | QByteArray header, block; 10 | int lunghezza,varNameLen; 11 | unsigned char hByte, lByte; 12 | unsigned char hByteMsg,lByteMsg; 13 | 14 | varNameLen=msg.size(); 15 | hByte=(varNameLen & 0xff00) >> 8; 16 | lByte=(varNameLen & 0x00ff); 17 | 18 | block.append(READVARIABLE).append(hByte).append(lByte).append(msg); 19 | lunghezza=block.size(); 20 | 21 | hByte=(lunghezza & 0xff00) >> 8; 22 | lByte=(lunghezza & 0x00ff); 23 | 24 | // Message ID ( MAX: 0xFFFF ) 25 | hByteMsg=(idMsg & 0xff00) >> 8; 26 | lByteMsg=(idMsg & 0x00ff); 27 | 28 | header.append(hByteMsg).append(lByteMsg).append(hByte).append(lByte); 29 | block.prepend(header); 30 | 31 | qDebug()<<"Message send:"<> 8; 47 | lByte=(varNameLen & 0x00ff); 48 | 49 | block.append(WRITEVARIABLE).append(hByte).append(lByte).append(msg); 50 | 51 | varValueLen=value.size(); 52 | hByte=(varValueLen & 0xff00) >> 8; 53 | lByte=(varValueLen & 0x00ff); 54 | 55 | block.append(hByte).append(lByte).append(value); 56 | 57 | lunghezza=block.size(); 58 | 59 | hByte=(lunghezza & 0xff00) >> 8; 60 | lByte=(lunghezza & 0x00ff); 61 | 62 | hByteMsg=(idMsg & 0xff00) >> 8; 63 | lByteMsg=(idMsg & 0x00ff); 64 | 65 | header.append(hByteMsg).append(lByteMsg).append(hByte).append(lByte); 66 | block.prepend(header); 67 | 68 | qDebug()<<"Message send:"< 0){ 79 | //Message ID 80 | idReadMsg=((unsigned char)msg[0])<<8 | ((unsigned char)msg[1]); 81 | qDebug() << "Message ID: " << idReadMsg; 82 | 83 | //Message Length 84 | lenMsg=((unsigned char)msg[2])<<8 | ((unsigned char)msg[3]); 85 | qDebug() << "Message Length:" << lenMsg; 86 | 87 | //Function(read:0/Write:1) 88 | func=((int)msg[4]); 89 | qDebug() << "Function(read:0/Write:1) " << func; 90 | 91 | //Value Length 92 | lenValue=((unsigned char)msg[5])<<8 | ((unsigned char)msg[6]); 93 | qDebug() << "Value Length:" << lenValue; 94 | 95 | qDebug() << "Message return:" << msg.toHex(); 96 | 97 | // the byte7 begin the value 98 | value = msg.mid(7,lenValue); 99 | return idReadMsg; 100 | 101 | } 102 | else{ 103 | value = QByteArray(""); 104 | return 0; 105 | } 106 | } 107 | 108 | int main() 109 | { 110 | const int Timeout = 5 * 1000; 111 | QTime readtime; 112 | 113 | QTcpSocket socketClient; 114 | socketClient.connectToHost("192.168.40.128", 7000); 115 | readtime.start(); 116 | 117 | if (!socketClient.waitForConnected(Timeout)) { 118 | qDebug() << "Timeout connection!"; 119 | return -1; 120 | } 121 | 122 | //read variable 123 | socketClient.write(formatMsg("$OV_PRO",43981)); 124 | 125 | //write varibel 126 | //socketClient.write(formatMsg("$OV_PRO","55",43981)); 127 | 128 | if(!socketClient.waitForBytesWritten(Timeout)) 129 | { 130 | qDebug() << "Timeout message sent!"; 131 | return -1; 132 | } 133 | 134 | if (!socketClient.waitForReadyRead(Timeout)) { 135 | qDebug() << "Timeout message return!"; 136 | return -1; 137 | } 138 | QByteArray returnMsg = socketClient.read(socketClient.bytesAvailable()); 139 | 140 | qDebug()<<"-----------return message-----------"; 141 | unsigned char ok = returnMsg.right(1).at(0); 142 | 143 | QByteArray value; 144 | unsigned short idMsg = clearMsg(returnMsg,value); 145 | qDebug()<<"Value:"<> 8) # MSB of variable value length 30 | msg.append((len(val) & 0x00ff)) # LSB of variable value length 31 | msg.extend(map(ord, val)) # Variable value in ASCII 32 | temp.append(bool(val)) # Read (0) or Write (1) 33 | temp.append(((len(var)) & 0xff00) >> 8) # MSB of variable name length 34 | temp.append((len(var)) & 0x00ff) # LSB of variable name length 35 | temp.extend(map(ord, var)) # Variable name in ASCII 36 | msg = temp + msg 37 | del temp[:] 38 | temp.append((msgID & 0xff00) >> 8) # MSB of message ID 39 | temp.append(msgID & 0x00ff) # LSB of message ID 40 | temp.append((len(msg) & 0xff00) >> 8) # MSB of message length 41 | temp.append((len(msg) & 0x00ff)) # LSB of message length 42 | msg = temp + msg 43 | except : 44 | self.error_list(2) 45 | try: 46 | client.send(msg) 47 | return client.recv(1024) # Return response with buffer size of 1024 bytes 48 | except : 49 | self.error_list(1) 50 | 51 | 52 | def __get_var(self, msg): 53 | """ 54 | kukavarproxy response format is 55 | msg ID in HEX 2 bytes 56 | msg length in HEX 2 bytes 57 | read (0) or write (1) 1 byte 58 | variable value length in HEX 2 bytes 59 | variable value in ASCII # bytes 60 | Not sure if the following bytes contain the client number, or they're just check bytes. I'll check later. 61 | """ 62 | try: 63 | # Python 2.x 64 | lsb = (int (str(msg[5]).encode('hex'),16)) 65 | msb = (int (str(msg[6]).encode('hex'),16)) 66 | lenValue = (lsb <<8 | msb) 67 | return msg [7: 7+lenValue] 68 | 69 | """ 70 | # Python 3.x 71 | lsb = int( msg[5]) 72 | msb = int( msg[6]) 73 | lenValue = (lsb <<8 | msb) 74 | return str(msg [7: 7+lenValue],'utf-8') 75 | """ 76 | 77 | except: 78 | self.error_list(2) 79 | 80 | def read (self, var, msgID=0): 81 | try: 82 | return self.__get_var(self.send(var,"",msgID)) 83 | except : 84 | self.error_list(2) 85 | 86 | 87 | def write (self, var, val, msgID=0): 88 | try: 89 | if val != (""): return self.__get_var(self.send(var,val,msgID)) 90 | else: raise self.error_list(3) 91 | except : 92 | self.error_list(2) 93 | 94 | 95 | def disconnect (self): 96 | client.close() # CLose socket 97 | 98 | 99 | def error_list (self, ID): 100 | if ID == 1: 101 | print ("Network Error (tcp_error)") 102 | print (" Check your KRC's IP address on the network, and make sure kukaproxyvar is running.") 103 | self.disconnect() 104 | raise SystemExit 105 | elif ID == 2: 106 | print ("Python Error.") 107 | print (" Check the code and uncomment the lines related to your python version.") 108 | self.disconnect() 109 | raise SystemExit 110 | elif ID == 3: 111 | print ("Error in write() statement.") 112 | print (" Variable value is not defined.") --------------------------------------------------------------------------------