From: Bruce W. <br...@mi...> - 2002-06-30 20:57:24
|
I agree, I don't think you want to call check_for_socket_data in user code, as that checks all ports. You could get thse socket and get the data directly, maybe something like this: my $name = $cmd_port->{port_name}; my $sock = $Socket_Ports{$name}{socka}; my $data = <$sock>; That will also cause mh to pause if there is not socket data. Seems like you would be better off simply sending th poll (like you did in your example), then structure your code so you can processes the results on a different pass. For example, this is what I do with the weeder sensors, in code/bruce/sensors.pl: set $analog_request_a 'request' if $New_Second and $Second == 20; &analog_read($temp) if $temp = state_now $analog_results; Bruce -----Original Message----- I've been trying to write the module to control my Cbus lighting system. The control is pretty easy, just open a socket to the Cbus server, send a command and wait for a response. But I've hit a little snag with the 'waiting for a response' bit. To get the status of a light I'm using a bit of code like; $cmd_port->set( $cmd_line ); while( ! ($data = $cmd_port->said) ) { } This caused MisterHouse to lock up because I stoped the main loopy bit from executing. Is there anyway of nicely handling this sort of thing? I don't want to return execution to the calling routine before the response with the status arrives on the socket, after all that is what the calling routine wanted made the call for. The only way I can see around this is to call the 'check_for_socket_data' inside my while loop, which doesn't seem a very nice method of solving the problem. |