matlab-msgpack icon indicating copy to clipboard operation
matlab-msgpack copied to clipboard

Using matlab-msgpack

Open Zahra-on-Github opened this issue 5 years ago • 4 comments

Windows 10 Pro MATLAB R2020b

I'm new to msgpack and I'm trying to use it throughout my script to communicate with my eye tracking device from MATLAB.
I have to use such a function to send my event (annotation) infromation to the device:

function [ ] = send_annotation( socket, annotation )
%NOTIFY Use socket to send annotation
%   Annotations are container.Map objects that contain
%   at least the following keys
%   'topic': String starting with "annotation.", followed by arbitrary string
%   'label': Arbitrary string
%   'timestamp': Pupil time as floating point value
%   'duration': Duration of annoation as floating point value, can be 0.0
payload = dumpmsgpack(annotation);
zmq.core.send(socket, uint8(annotation('topic')), 'ZMQ_SNDMORE');
zmq.core.send(socket, payload);
end

I have tried to put it like this:

    annotation.topic = "annotation.topic";
    annotation.label = "label";
    annotation.timestamp = 1.0;
    annotation.duration = 0.0;
    send_annotation( socket, annotation );

but I get this error:

Error using dumpmsgpack>dump (line 74)
Unknown type "string"

Error in dumpmsgpack>dumpmap (line 223)
        valuestuff = dump(values{n});

Error in dumpmsgpack>dump (line 72)
        msgpack = dumpmap(data);

Error in dumpmsgpack (line 22)
    msgpack = dump(data);

Error in send_annotation (line 9)
payload = dumpmsgpack(annotation);

Error in practice_run (line 361)
    send_annotation( socket, annotation );

Can you tell me how I should enter the annotation arguments?

Zahra-on-Github avatar Jan 28 '21 12:01 Zahra-on-Github

I think I developed matlab-msgpack before the new string type became a thing. It is probably reasonably simple to fix, if you'd like to contribute a pull request. Otherwise, use char arrays (single quotation marks) instead of strings (double quotation marks).

bastibe avatar Jan 30 '21 14:01 bastibe

I think I developed matlab-msgpack before the new string type became a thing. It is probably reasonably simple to fix, if you'd like to contribute a pull request. Otherwise, use char arrays (single quotation marks) instead of strings (double quotation marks).

Thanks for your reply. I changed the double quotes into single quotes and also I implemented the container.Map, like this:

    keySet = {'topic','label','timestamp','duration'};
    topic = 'annotation.topic';    
    label = 'label';
    timestamp = 0.0;
    duration = 0.0001;

    valueSet = {topic,label,timestamp,duration};
    annotation = containers.Map(keySet,valueSet,'UniformValues',false);
    
    send_annotation( socket, annotation );

and the error is gone. But, I receive this new error:

Error using send
Result too large

Error in send_annotation (line 10)
zmq.core.send(socket, uint8(annotation('topic')), 'ZMQ_SNDMORE');

Error in practice_run (line 388)
    send_annotation( socket, annotation );

Do you think this error is related to msgpack?

Zahra-on-Github avatar Feb 01 '21 13:02 Zahra-on-Github

That error does not seem to be related to msgpack. (And msgpack should work with structs, no need for the containers.Map)

bastibe avatar Feb 03 '21 07:02 bastibe

That error does not seem to be related to msgpack. (And msgpack should work with structs, no need for the containers.Map)

I corrected my use of ZMQ functions and the error is resolved. Thanks for your help. I close this issue now.

Zahra-on-Github avatar Feb 04 '21 12:02 Zahra-on-Github