Uppdate Property FROM Device??

HouseBot Plugin Development Discussions.
Post Reply
maze42
Member
Posts: 28
Joined: Sat Aug 07, 2004 11:30 am
Location: Sweden

Uppdate Property FROM Device??

Post by maze42 »

I am trying to build a device for UDP/IP communication. So far I have succeded to make it send messages (when I change an alphaNumerical property it send the property value to a preset port and address) BUT how can I make the device notify the HB server when device RECEIVES a message. I have modified the BeepDevice example in the SDK and i know the device have received the message (using TraceMessage() ) but it (seems to) only update the receiving property when i update any other property!?!



I have my receiving code in the loop in DeviceRun method and use CreatePropertyValue(szReceivedUDPData) to update my property. To simplify the problem i tested the code below and it only run when the user change one of the other properties in the device.



Example from the loop in the DeviceRun method:



if((m_dwOldTickCount+1000)<GetTickCount())

{

sprintf(buffer,"Tick count is %d",GetTickCount());

CPropertyValue* pNoValue = m_pData->CreatePropertyValue( buffer );

if (pNoValue)

{

pNoValue->ChangeRequestCompleted();

delete pNoValue;

}

m_dwOldTickCount = GetTickCount();

}



What have i missed??
ScottBot
Site Admin
Posts: 2787
Joined: Thu Feb 13, 2003 6:46 pm
Location: Georgia (USA)
Contact:

Re: Uppdate Property FROM Device??

Post by ScottBot »

maze42 wrote:What have i missed??
I'd have to see the entire ::DeviceRun() method to be sure, but it sounds like you're blocked on the WaitForMultipleObjects() call.



Typically, as in the Beep Device, the ::DeviceRun will loop until the terminate event is signaled. To avoid consuming CPU, the loop will wait using the WaitForMultipleObjects() call. This call will only unblock when the application is terminating, or someone has changed a Property Value.



If you have code below the WaitForMultipleObjects() call it won't get executed until the call unblocks by someone changing a value at the server. This sounds like the symptom that you have.



I'd suggest creating your own thread for your UDP connection and just allowing the ::DeviceRun() to handle calls from the server. If you want to do something that isn't time critical, you could change the wait time on the WaitForMultipleObjects from INFINITE to a real timeout value and do the processing in the main loop.
Scott
maze42
Member
Posts: 28
Joined: Sat Aug 07, 2004 11:30 am
Location: Sweden

Post by maze42 »

Thanks, now it works just fine.



If i decide to remake it and create my own thread solution instead, where is the best place (from HB point of view) to initiate the thread ?
ScottBot
Site Admin
Posts: 2787
Joined: Thu Feb 13, 2003 6:46 pm
Location: Georgia (USA)
Contact:

Post by ScottBot »

You can create the thread either in the DeviceInit() or the DeviceRun() methods.
Scott
Post Reply