Page 1 of 1

Sending two Events form Crank to External Application

PostPosted: Wed Oct 26, 2016 2:53 pm
by atinir
Hi guys,

How two events can be send from Crank Storyboard to external application in C. When I send only one event it works fine. But when I send two events, the data get mixed. Should I create two channels for receiving the data or one is enough, or what exactly should be different when the event is received?

The code in Lua:
1) First Event
function updateposition(mapargs)
local format = "4s1 int32 2s1 int16"
local data = {}
local positionx
local positiony
data["int32"] = positionx["x"]
data["int16"] = positiony["y"]
gre.send_event_data("Myevent", format, data, "goal_receive")
end

2) Second Event
function sendgoaldata()

local format = "1s1 int8 2s1 int16 2u1 uint16 1u1 uint8 1s1 int8 "
local data = {}
local xG1,xG2,xG3,xG4
data["int8"] = xG1["x"]
data["int16"] = yG1["y"]
data["uint16"] = wG1["width"]
data["uint8"] = hG1["height"]
gre.send_event_data("goalInfo", format, data, "goal_receive")
end

The code in C:

rhandle = gre_io_open("goal_receive", GRE_IO_TYPE_RDONLY);
ret = gre_io_receive(rhandle, &nbuffer);
rnbytes = gre_io_unserialize(nbuffer, &revent_target, &revent_name, &revent_format, (void **) &revent_data); //First Event
my_data = (struct receive_data *) revent_data;

rnbytes = gre_io_unserialize(nbuffer, &revent_target, &revent_name,&revent_format, (void **) &revent_data); //Second Event
myGoal=(struct goalData *) revent_data;

Thank you :)
All the best,
Atinir

Re: Sending two Events form Crank to External Application

PostPosted: Thu Oct 27, 2016 10:50 am
by Evan
Hi Atinir,

Sending event data pushes the data as an atomic item into a queue waiting to be received. Calling receive will return only one such data item from the queue at a time. Here, you are sending two pieces of event data but only calling receive once. After processing the first event, you need to call receive again to get the second event before attempting to process it.

Regards,
Evan

Re: Sending two Events form Crank to External Application

PostPosted: Mon Nov 28, 2016 4:59 am
by atinir
Thank you very much Evan.
Calling receive twice didn't work for me, the data between the two events got mixed. I don't know, maybe it has to do with the way I did format the data.
The way I solved it, was using a separate thread to receive the second event.

Best regards,
Atinir