WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 03-12-2015, 09:27 AM
shall6 shall6 is offline
Member
 
Join Date: Dec 2014
Posts: 9
Thanks for the assist - can't believe I missed that. Now I'm on to the hard part (been hunting through old threads but no answer).

When I run with the if statement, I can't get it to work. It has to do with the data coming through as e.raw_data. I tried converting it to a string but I still can't compare it. This is what I have after trying to convert BOTH my data and my if object (already a string) to strings. It still doesn't work. Of course it will recognize them as NOT equal... but that doesn't help me much. Why can't I actually turn this raw data into an object?

Code:
dataNetwork = viz.addNetwork('OEM-PC')
def onNetwork(e):
    if isinstance(e,viz.RawNetworkEvent):
        print e.raw_data
        v = str(e.raw_data)
        if v == str('hi'):
            print v

viz.callback(viz.NETWORK_EVENT,onNetwork)
Thanks!
Reply With Quote
  #2  
Old 03-12-2015, 09:46 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Try using the following code to see what the contents of the raw_data attribute is:
Code:
def onNetwork(e):
    if isinstance(e,viz.RawNetworkEvent):
        print repr(e.raw_data)
Keep in mind that the raw data can contain trailing NULL (\x00) byte values, so you might need to account for this if you are expecting to receive a string.
Reply With Quote
  #3  
Old 03-12-2015, 09:52 AM
shall6 shall6 is offline
Member
 
Join Date: Dec 2014
Posts: 9
That's exactly it

I got 'hi\n'

Any chance there's a simple way to remove the trailing parts?
Reply With Quote
  #4  
Old 03-12-2015, 09:55 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
You can use the following to strip trailing newline, space, and null byte characters:

Code:
v = e.raw_data.rstrip('\n\0 ')
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
Interface between Matlab and Vizard Shweta Vizard 8 06-30-2014 09:40 AM
Iinterface between MATLAB and Vizard suraj Vizard 7 07-17-2012 09:02 AM
MATLAB and vizard xingtzu Vizard 1 01-15-2008 10:25 AM
Matlab and Vizard brystewa Vizard 1 09-18-2006 03:11 PM
MATLAB and Vizard eagleman Vizard 4 06-10-2005 11:42 AM


All times are GMT -7. The time now is 09:59 AM.


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