WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 01-05-2017, 04:31 PM
sagar29 sagar29 is offline
Member
 
Join Date: Oct 2016
Posts: 7
Smile Sending data from MATLAB(Simulink) to Vizard

Hello,
I am trying to send data as packets of doubles in little endian format from MATLAB(Simulink) to Vizard. Since MATLAB is non-python interface, I am using code give on the forum and it is:

from __future__ import print_function
import viz
viz.go()
import vizact
import socket

log=open("new.txt","w")
print("Hi there",file=log)

#The maximum amount of data to receive at a time
MAX_DATA_SIZE = 1024

#The port to send/receive data on
PORT = 5600

#Get the name of this computer
COMPUTER_NAME = socket.gethostname()

#Get the IP address of this computer
COMPUTER_IP_ADDRESS = socket.gethostbyname('localhost')

#Create a socket to send data over
#OutSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
#OutSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

#Create a socket to receive data from
InSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
InSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
InSocket.bind(('192.168.1.2', PORT))
InSocket.setblocking(0)

#def SendData(data):
#OutSocket.sendto(data,(COMPUTER_IP_ADDRESS,PORT))

def ReceiveData():
try:
return InSocket.recv(MAX_DATA_SIZE)
except socket.error:
#Insert error handling code here
print("Error has occured",file=log)

#vizact.onkeydown(' ',SendData,'hello there')

def CheckSocket():
#Try to receive data from socket
data = ReceiveData()
if data:
print (data,file=log)
else:
print("Data not received",file=log)
vizact.ontimer(0,CheckSocket)

I have removed data sending part by making it comment and trying to get data in file so that I can analyse(One more reason is that when I write simple print, I am getting nothing in Vizard). I am not understanding second line in socket creation for receiving data and also not getting any output.

I tried to send data from MATLAB to MATLAB and its working but with Vizard it is giving problem.

Please suggest appropriate corrections in code.

Thanks
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Vizard Matlab interface - no data printing shall6 Vizard 7 03-12-2015 10:55 AM
Vizard and Phasespace Time Data teklab Vizard 1 06-13-2013 11:43 AM
Sending data to Vizard via UDP rlh001 Vizard 1 04-05-2011 05:14 PM
Vizard tech tip: Using the Python Imaging Library (PIL) Jeff Vizard 0 03-23-2009 12:13 PM
Vizard & USB 5DT Data Glove rdotsch Vizard 4 07-26-2005 05:35 AM


All times are GMT -7. The time now is 03:33 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC