2018年3月31日土曜日

REX-BTWATTCH1

管理者権限で起動したpowershell (v3以上必須)に貼っ付けてEnterすると
RATOCのBluetoothワットチェッカー(REX-BTWATTCH1)のリアルタイム値をグリッド表示できます


function get_crc8($bytes){[byte]$crc=0x00;foreach($currByte in $bytes){
[byte]$crc=$crc -bxor $currByte;for($bit=0; $bit -lt 8; $bit++){if(($crc -band 0x80) -eq 0){
[byte]$crc=$crc -shl 1}else{[byte]$crc=(($crc -shl 1) -bxor 0x85)}}};echo $crc}
function aa([byte[]]$pld,$len){[byte[]]$cmd=0xAA,$pld.length,(($pld.length -shr 8) -band 0xFF),$pld,(get_crc8 $pld) | %{$_}
$wattch1.Write($cmd,0,$cmd.length);$count=$wattch1.Read(($buf=New-Object byte[] 256),0,$len);$buf[0..($count-1)]}
($global:wattch1=New-Object IO.Ports.SerialPort ((gwmi -cl Win32_PnPSignedDriver -f `
"FriendlyName LIKE '%COM%' and DeviceID LIKE '%$((gwmi -cl Win32_PnPSignedDriver -f "FriendlyName LIKE '%WATT%'"`
).HardwareID -replace ".+?Dev_(\w)")%'").FriendlyName -replace ".+?\((COM\d).+?",'$1'),115200`
).ReadTimeout=$wattch1.WriteTimeout=1000;$wattch1.Open()
[int[]]$initPLD=0x01,($now=Get-Date).Second,$now.Minute,$now.Hour,$now.Day,$now.Month,($now.Year%100),$now.DayOfWeek
$null=aa $initPLD 6;$null=aa @(0x02,0x00) 6;
&{while($true){$nowsec=(Get-Date).Second;if($nowsec -eq $pastsec){sleep -m 10}else{
[int[]]$data=aa @(0x08) 21;if(($data[0] -eq 0xAA) -and ($data[4] -eq 0x00) -and ($data[1] -ne 0x02)){
$wattage=(($data[13] -shl 16)+($data[12] -shl 8)+$data[11])*5/1000;$voltage=(($data[10] -shl 16)+($data[9] -shl 8)+$data[8])*1/1000
$current=(($data[7] -shl 16)+($data[6] -shl 8)+$data[5])*(1/128)
$value=$("20{0:00}/{1:#0}/{2:#0} {3:00}:{4:00}:{5:00}" -f $data[19..14])+", "+
$("{0:###0.00}, {1:#00.00}, {2:####0.00}" -f $wattage,$voltage,$current);$pastsec=$nowsec;$value `
| ConvertFrom-Csv -h @("DateTime","Wattage(W)","Voltage(V)","Current(mA)")}}}} `
| ogv -t "REX-BTWATTCH1";$wattch1.Close()

0 件のコメント:

コメントを投稿

CT125・ハンターカブ タイヤ