![]()  | 
	
| 
		 
			 
			#1  
			
			
			
			
			
		 
		
	 | 
|||
		
		
  | 
|||
| 
		
	
		
		
			
			 
				
				Real-time export data to simulink
			 
			
			
			Hello, 
		
		
		
		
		
		
		
		
	
	I'm seeking a solution to output position and orientation data to another computer running Simulink in real time. Does anybody have any experience? Thanks!  | 
| 
		 
			 
			#2  
			
			
			
			
			
		 
		
	 | 
|||
		
		
  | 
|||
| 
		
	
		
		
		
		 
			
			Can Simulink read data coming over a network socket? If so, you can use the Python socket module to send data over the network.
		 
		
		
		
		
		
		
		
		
	
	 | 
| 
		 
			 
			#3  
			
			
			
			
			
		 
		
	 | 
|||
		
		
  | 
|||
| 
		
	
		
		
		
		 
			
			I found a UDP Receive block in Simulink. It requires the other end of the communication, which is vizard, to specify the port that receives data. I'm not sure how to do it. I think my code only specifies the port that sends data. Am I missing something?   
		
		
		
		
		
		
		
		
	
	Code: 
	import viz
viz.go()
import socket
COMPUTER_IP_ADDRESS = socket.gethostbyname('192.59.88.91')
PORT = 25000 #The port to send data on
OutSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
OutSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
def SendData(data):
	OutSocket.sendto(data,(COMPUTER_IP_ADDRESS,PORT))
vizact.onkeydown(' ',SendData,'hello there')
 | 
| 
		 
			 
			#5  
			
			
			
			
			
		 
		
	 | 
|||
		
		
  | 
|||
| 
		
	
		
		
		
		 
			
			I'm confused, in the sample code, there is only one port 4999, which is "#The port to send/receive data on". Why does it show using different ports? Thanks.
		 
		
		
		
		
		
		
		
		
	
	 | 
| 
		 
			 
			#6  
			
			
			
			
			
		 
		
	 | 
|||
		
		
  | 
|||
| 
		
	
		
		
		
		 
			
			So far I'm sure simulink on computer B can receive data from specified IP address and port over UDP. Then my question is, how do I specify the port that the remote computer B accepts data from in vizard on this computer A? Thanks.
		 
		
		
		
		
		
		
		
		
	
	 | 
| 
		 
			 
			#7  
			
			
			
			
			
		 
		
	 | 
|||
		
		
  | 
|||
| 
		
	
		
		
		
		 
			
			I just got them communicated successfully. PORT = xxxx seems to be used to specify the remote port to receive from. Please forget my previous question. 
		
		
		
		
		
		
		
		
	
	My next problem is I would like to send two values from vizard to simulink every 0.05 second. My code would be like this: Code: 
	import viz viz.go() import socket import random COMPUTER_IP_ADDRESS = '129.59.82.229' PORT = 25000 OutSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) OutSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) def SendData(data): OutSocket.sendto(data,(COMPUTER_IP_ADDRESS,PORT)) def mytimer(num): value1 = random.randint(0, 70) value2 = random.randint(1, 100) SendData(value1, value2) viz.callback(viz.TIMER_EVENT, mytimer) viz.starttimer(0,0.05,viz.FOREVER) Thanks a lot.  | 
| 
		 
			 
			#8  
			
			
			
			
			
		 
		
	 | 
|||
		
		
  | 
|||
| 
		
	
		
		
		
		 
			
			When sending data using the socket module, the data needs to be a string containing the raw byte data. Have a look at the Python struct module for packing Python integer/float values into raw byte data. The following example shows how to generate raw byte data from 2 integer values: 
		
		
		
		
		
		
		
		
	
	Code: 
	import struct
data = struct.pack('ii',value1,value2)
 | 
| 
		 
			 
			#9  
			
			
			
			
			
		 
		
	 | 
|||
		
		
  | 
|||
| 
		
	
		
		
		
		 
			
			Thanks a lot. That really helps.
		 
		
		
		
		
		
		
		
		
	
	 | 
![]()  | 
	
	
| Thread Tools | |
| Display Modes | Rate This Thread | 
		
  | 
	
		
  | 
			 
			Similar Threads
		 | 
	||||
| Thread | Thread Starter | Forum | Replies | Last Post | 
| real time collision on animation path | whj | Vizard | 10 | 10-06-2008 05:38 PM | 
| Real Time Audio Data | lomendil | Vizard | 2 | 06-02-2008 09:18 PM | 
| Can I get real time Intersense tracking data from another computer on the network? | GoldenSun | Vizard | 4 | 04-30-2008 08:42 PM | 
| Flagging the Data | Elittdogg | Vizard | 5 | 04-11-2008 12:40 PM | 
| timer question | Elittdogg | Vizard | 5 | 10-10-2007 03:49 PM |