add write_parameter_frame
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 3 Oct 2020 18:10:37 +0000 (20:10 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 3 Oct 2020 18:10:37 +0000 (20:10 +0200)
Protocol.pm

index 9629347..2db4ddb 100644 (file)
@@ -5,7 +5,7 @@ use strict;
 require Exporter;
 
 our @ISA = qw(Exporter);
-our @EXPORT = qw( modbus_crc16 $protocol read_parameter_frame );
+our @EXPORT = qw( modbus_crc16 $protocol read_parameter_frame write_parameter_frame );
 
 use Data::Dump qw(dump);
 
@@ -109,6 +109,20 @@ sub read_parameter_frame {
        return $frame . modbus_crc16($frame);
 }
 
+sub write_parameter_frame {
+       my $params = join('', @_);
+
+       my $frame
+               = "\x5A" # header
+               . "\x0B" # protocol version
+               . "\x06" # function code
+               . pack("v", length($params)) # data length
+       ;
+
+       $frame .= $params;
+
+       return $frame . modbus_crc16($frame);
+}
 1;
 
 # 6. Protocol Format 
@@ -123,7 +137,7 @@ __DATA__
 0x04   Y axis angle                    f Float(4)      R       -90-90          /       Y axis angle 
 0x09   X axis relative angle           f Float(4)      R       -90-90          0       Return the X angle value according to the set relative zero 
 0x0A   Y axis relative angle           f Float(4)      R       -90-90          0       Return the Y angle value according to the set relative zero 
-0x0C   Sensor temperature              s Word(2)       R       -32768-32767    /       signed,sensor temperature =Data/100, unit \83 
+0x0C   Sensor temperature              s Word(2)       R       -32768-32767    /       signed,sensor temperature =Data/100, unit celsius
 0x0D   Power source voltage            S Word(2)       R       0~65535         /       Voltage= Data/100, unit V 
 0x0E   Heartbeat interval              l DWord(4)      R/W     60~2160000      86400   ZCT330E Interval at which the device periodically uploads data to the server 
 0x0F   Failure interval                l DWord(4)      R/W     60~2160000      3600    ZCT330E Interval at which the device failure is retransmitted