From: Jason I. C. <jcomand@MIT.EDU> - 2003-08-15 05:43:55
|
> sub check_for_data { > my ($self) = @_; > &main::check_for_generic_serial_data('W800'); > return unless $main::Serial_Ports{W800}{data}; > # Data comes 2 bytes at a time (no break > character) > my ($data, $remainder) = $main::Serial_Ports{W800}{data} =~ > /(....)(.*)/; > return unless $data; > $main::Serial_Ports{W800}{data} = $remainder; OK, the only problem is that the data strings coming from the thermostat are not fixed length. If I can assume I can capture every byte, I can keep collecting until I see a command end. But ideally, since the thermostat always just answers a command sent by the host, I would like to listen for a fixed period of time after a command is sent and then try to parse whatever comes back in that interval. I tried run_after_delay 2, "print_log 'Ending delay test 1'"; but this did not seem to work from within Omnistat.pm. > > Stupid question - where should I look for docs for this kind of > > thing? > > Sorry, the low level details of internals like this are not documented. > Best we have are the examples of similar code. No problem, I just didn't want to take up your time if I could RTFM. There is another piece of omnistat.pm that is broken. This one should be easy to fix, but my knowledge of packages and locales is lacking. An array @temp is defined in the main body of the package as a hard-coded list of values for different elements of the array. Then, a scalar $temp is passed to a subroutine in that package. To access an element from @temp, it tries to use $Omnistat::temp[$temp] . The first temp is supposed to refer to the @temp defined in the package body and the second temp is supposed to be the $temp variable passed into the subroutine. But $Omnistat::temp[$temp] evaluates to null. Code and output: package Omnistat; ... my @temp; $temp[68]="0x78"; $temp[69]="0x79"; $temp[70]="0x7a"; $temp[71]="0x7b"; $temp[72]="0x7c"; $temp[73]="0x7d"; $temp[74]="0x7f"; $temp[75]="0x80"; $temp[76]="0x81"; ... sub cool_setpoint{ my ($self,$temp)=@_; print "$::Time_Date: Omnistat -> Cool setpoint $temp\n" unless $main::config_parms{no_log} =~/omnistat/ ; my @cool_setpoint=qw(0x01 0x21 0x3b); $cool_setpoint[3]=$Omnistat::temp[$temp]; print "omnicoolsetpoint [$temp] [$Omnistat::temp[$temp]] [$Omnistat::$temp[$temp]] [$cool_setpoint[3]]\n"; my $cool_setpoint_printstr=add_checksum(@cool_setpoint); $main::Serial_Ports{Omnistat}{object}->write($cool_setpoint_printstr); } output: 08/15/03 01:13:06 AM: Omnistat -> Cool setpoint 76 omnicoolsetpoint [76] [] [0x81] [] _______________ Note that $Omnistat::$temp[$temp] seems to work in the print statement but NOT in the assignment statement in the previous line. Weird. Any suggestions? Thanks!! Jason |