前回、iRemocon Wi-FiをWindowsのコマンドプロンプトから操作する方法を書きました。
このように、iRemoconは、ローカルIPさえ分かってしまえば、telnetで簡単なコマンドを書くことで、結構たやすく操作することができます。
ただ、コマンドを覚えたり書いたりするのが面倒なので、もっと手軽にテストができる簡易サンプルプログラムを作ってみたので紹介です。
目次
iRemocon Wi-Fi簡易操作アプリ
その、簡易サンプルプログラムがこちら。
開発者向け情報のIRM-03WLAコマンド仕様書(PDF)にある操作コマンドを、ボタンで実行できるようにしてあります。
ボタンを押すことで、手軽にWindowsからiRemocon Wi-Fiのコマンド操作テストを行うことができます。
一応ソースも付いています。ただし作成は、Delphiというかなりマイナーな部類に入る言語で行いました。(それしかまともに使えないので)
しかも、Delphiといっても前時代の遺物Delphi7 IDEで作成しているので、今のIDEでは、そのままソース編集できないかもしれません。
一応、iRemoconオブジェクトを作成し、オブジェクトのiRemocon Wi-Fi操作メソッドで操作をしています。
以下に、Delphiで書いたiRemocon操作オブジェクトを載せておきます。(クリックで開く)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 | unit iRemocon; interface uses Windows, Messages, SysUtils, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdTelnet, ExtCtrls, Classes, Forms, DateUtils, dbg; const //リピート時間定数 RS_NONE = 0; //リピートなし RS_ONE_HOUR = 3600; //一時間ごと RS_12_HOUR = RS_ONE_HOUR * 12; RS_ONE_DAY = RS_ONE_HOUR * 24; //一日ごと RS_ONE_WEEK = RS_ONE_DAY * 7; //一週間ごと UTC0900 = 32400; type TSendEvent = procedure (Sender: TObject; Command: String) of object; TSentEvent = procedure (Sender: TObject; Response: String) of object; TCustomErrorEvent = procedure (Sender: TObject; ErrorCode, ErrorTitle, ErrorMessage: string) of object; //タイマーリスト取得用レコード TTimerRec = record No: Word; RemoconNo: Word; DateTime: TDateTime; RepeatSec: Cardinal; end; //タイマーリスト取得用動的配列 TTimerArray = array of TTimerRec; TIRemocon = class(TComponent) private FHost: string; FIdTelnet: TIdTelnet; FInterval: Word; FIsLastCommandError: Boolean; FLastErrorCode: string; FLastErrorMessage: string; FLastErrorTitle: string; FLastReturnCommand: string; FLearningTimeout: Cardinal; FLogList: TStringList; FNecessaryCRLF: Boolean; FOnCustomError: TCustomErrorEvent; FOnSend: TSendEvent; FOnSent: TSentEvent; FPort: Integer; IsLearning: Boolean; IsReturnFinished: Boolean; TmpLastReturnCommand: string; procedure IdTelnetDataAvailable(Sender: TIdTelnet; const Buffer: String); procedure SetLearningTimeout(const Value: Cardinal); function SendCommand(Command: string): Boolean; function IsRemoconNoValid(RemoconNo: Word): Boolean; procedure SetErrors(const ReturnCommand: string); procedure SetInterval(const Value: Word); procedure SetOnSend(const Value: TSendEvent); procedure SetOnSent(const Value: TSentEvent); procedure SetHost(const Value: string); procedure SetOnCustomError(const Value: TCustomErrorEvent); procedure SetNecessaryCRLF(const Value: Boolean); protected public constructor Create(AOwner: TComponent); override; destructor Destroy; override; {IRM-01Lコマンド} function KeepAlive: Boolean; //[au]:接続確認用 function TransmitInfrared(RemoconNo: Word): Boolean; //[is]:赤外線発光 function StartLearning(RemoconNo: Word): Boolean; //[ic]:リモコン学習開始 function StopLearning: Boolean; //[cc]:リモコン学習中止 function SetTimer(RemoconNo: Word; //[tm]:タイマーセット ADateTime: TDateTime; RepeatSec: Cardinal): Boolean; function GetTimers(var Timers: TTimerArray): Boolean; //[tl]:タイマー一覧取得 function CancelTimer(TimerNo: Word): Boolean; //[td]:タイマー解除 function SetDateTime(ADateTime: TDateTime): Boolean; //[ts]:現在時刻設定 function GetDateTime(var ADateTime: TDateTime): Boolean; //[tg]:現在時刻取得 function GetVersion(var Version:string): Boolean; //[vr]:ファームバージョン番号の取得 function GetIlluminance(var Illuminance:Single): Boolean; //[li]:照度センサー値の取得 function GetHumidity(var Humidity:Single): Boolean; //[hu]:湿度センサー値の取得 function GetTemperature(var Temperature:Single): Boolean; //[te]:温度センサー値の取得 function GetSensors(var Illuminance, Humidity, Temperature:Single): Boolean; //[se]:すべてのセンサー値の取得 //iRemocon用接続先ポート番号(51013) property Port: Integer read FPort; //最新の返信コマンド property LastReturnCommand: string read FLastReturnCommand; //最新のエラーコード property LastErroreCode: string read FLastErrorCode; //最新のエラータイトル property LastErrorTitle: string read FLastErrorTitle; //最新のエラーメッセージ property LastErrorMessage: string read FLastErrorMessage; //最新の返信コマンドがエラーだったか property IsLastCommandError: Boolean read FIsLastCommandError; //コマンドログ property Log: TStringList read FLogList; published property Host: string read FHost write SetHost; //連射防止用のインターバル Default 500ms property Interval: Word read FInterval write SetInterval default 500; //学習タイムアウト時間 Default 15秒(15000ms) property LearningTimeout: Cardinal read FLearningTimeout write SetLearningTimeout default 15000; //返信コマンドに#13#10を含めるか property NecessaryCRLF: Boolean read FNecessaryCRLF write SetNecessaryCRLF default False; //コマンド送信前イベント property OnSend: TSendEvent read FOnSend write SetOnSend; //コマンド送信後イベント property OnSent: TSentEvent read FOnSent write SetOnSent; //エラー出力用に作ったイベントの設定 //書式の変更をするにはSetErrors手続きを変更してください property OnCustomError: TCustomErrorEvent read FOnCustomError write SetOnCustomError; end; procedure Register; implementation uses Math; procedure Register; begin RegisterComponents('Samples', [TIRemocon]); end; { TIRemocon } constructor TIRemocon.Create(AOwner: TComponent); begin inherited; FPort := 51013; FInterval := 500; FLearningTimeout := 15000; FNecessaryCRLF := False; //Telnetの初期設定 FIdTelnet := TIdTelnet.Create(AOwner); with FIdTelnet do begin Port := FPort; OnDataAvailable := IdTelnetDataAvailable; end; FLogList := TStringList.Create; end; destructor TIRemocon.Destroy; begin inherited; FIdTelnet.Free; FLogList.Free; end; procedure TIRemocon.IdTelnetDataAvailable(Sender: TIdTelnet; const Buffer: String); function IsCRLF2(s: string): Boolean; var i, n: Integer; begin n := 0; for i := 1 to Length(s)-1 do begin if (s[i] + s[i+1]) = #13#10 then begin Inc(n); end; end; Result := n = 2; end; var crlfPos: Integer; begin TmpLastReturnCommand := TmpLastReturnCommand + Buffer; crlfPos := Pos(#13#10, TmpLastReturnCommand); if crlfPos > 0 then begin //学習を中止した時用の処理 //返信コマンド→cc;ok#13#10ic;err;002#13#10 if Pos('cc;ok', TmpLastReturnCommand) > 0 then begin //2つめの#13#10が出た時点で取得終了するようにする if (Pos(#13#10, Copy(TmpLastReturnCommand, crlfPos+1, Length(TmpLastReturnCommand))) > 0) and IsCRLF2(TmpLastReturnCommand) then begin IsReturnFinished := True; end; end else begin //それ以外は最初の#13#10が出たときに取得終了 IsReturnFinished := True; end; end; end; function TIRemocon.KeepAlive: Boolean; begin Result := SendCommand('au'); end; function TIRemocon.TransmitInfrared(RemoconNo: Word): Boolean; begin Result := False; if IsRemoconNoValid(RemoconNo) then Result := SendCommand('is;' + IntToStr(RemoconNo)); end; function TIRemocon.StartLearning(RemoconNo: Word): Boolean; begin Result := False; if IsRemoconNoValid(RemoconNo) then begin Result := SendCommand('ic;' + IntToStr(RemoconNo)); IsLearning := False; end; end; function TIRemocon.StopLearning: Boolean; begin if IsLearning then begin Result := SendCommand('cc'); end else begin raise Exception.Create('リモコンコード学習モード以外の状態に対して実行しました。'); end; end; function TIRemocon.SetDateTime(ADateTime: TDateTime): Boolean; begin Result := SendCommand('ts;' + IntToStr(DateTimeToUnix(ADateTime) - UTC0900)); end; function TIRemocon.GetDateTime(var ADateTime: TDateTime): Boolean; var s: string; begin Result := SendCommand('tg'); if Result then begin s := Trim(StringReplace(FLastReturnCommand, 'tg;ok;', '', [])); ADateTime := UnixToDateTime(StrToIntDef(s, 0) + UTC0900); end else begin ADateTime := UnixToDateTime(UTC0900); end; end; function TIRemocon.SetTimer(RemoconNo: Word; ADateTime: TDateTime; RepeatSec: Cardinal): Boolean; begin Result := False; if not ((RepeatSec = 0) or ((RepeatSec >= 60) and (RepeatSec <= 31536000))) then begin raise Exception.Create('繰り返し秒数は、0もしくは60~31536000にしてください。'); end; if IsRemoconNoValid(RemoconNo) then Result := SendCommand('tm;' + IntToStr(RemoconNo) + ';' + IntToStr(DateTimeToUnix(ADateTime) - UTC0900) + ';' + IntToStr(RepeatSec)); end; function TIRemocon.GetTimers(var Timers: TTimerArray): Boolean; function NextValue(s: string): string; begin //;までを削除 Result := StringReplace(s, Copy(s, 1, Pos(';', s)), '', []); end; var s: string; n, i: Integer; begin Result := SendCommand('tl'); {} if Result then begin //返信コマンド例 tl;ok;2;1;3;1334692382;0;2;6;1335642637;604800 s := FLastReturnCommand + ';'; s := StringReplace(s, 'tl;ok;', '', []); //tl;ok;1;を削除 n := StrToIntDef(Copy(s, 1, Pos(';', s)-1), 0); //タイマー登録数を取得 if n = 0 then Exit; SetLength(Timers, n); s := NextValue(s); //回数を削除 for i := 0 to n-1 do begin Timers[i].No := StrToIntDef(Copy(s, 1, Pos(';', s)-1), -1); //タイマーNoを取得 if Timers[i].No = -1 then Exit; s := NextValue(s); //タイマーNoを削除 Timers[i].RemoconNo := StrToIntDef(Copy(s, 1, Pos(';', s)-1), -1); //リモコンNoを取得 if Timers[i].RemoconNo = -1 then Exit; s := NextValue(s); //リモコンNoを削除 Timers[i].DateTime := //予約時間を取得 UnixToDateTime(StrToIntDef(Copy(s, 1, Pos(';', s)-1), -1) + UTC0900); s := NextValue(s); //予約時間を削除 Timers[i].RepeatSec := StrToIntDef(Copy(s, 1, Pos(';', s)-1), -1); //繰り返し秒数を取得 s := NextValue(s); //繰り返し秒数を削除 end; end; end; function TIRemocon.CancelTimer(TimerNo: Word): Boolean; begin if (TimerNo >= 1) and (TimerNo <= 1500) then begin Result := SendCommand('td;' + IntToStr(TimerNo)); end else begin raise Exception.Create('タイマー番号が1~500の範囲外です。'); Result := False; end; end; function TIRemocon.GetVersion(var Version: string): Boolean; begin Result := SendCommand('vr'); if Result then Version := FLastReturnCommand else Version := ''; end; function TIRemocon.SendCommand(Command: string): Boolean; var i: Integer; s, cmd, sendcmd, lrc: string; startms: Cardinal; begin //開始時間 startms := GetTickCount; //メンバーの初期化 FLastReturnCommand := ''; TmpLastReturnCommand := ''; FLastErrorCode := ''; FLastErrorMessage := ''; FIsLastCommandError := False; IsReturnFinished := False; cmd := Copy(Command, 1, 2); //コマンド先頭2文字 ex. au, ic, cc //学習中はccコマンド以外受け付けない if IsLearning and (cmd <> 'cc') then begin raise Exception.Create('リモコン学習開始コマンドが終了していません。'); Exit; end; //接続 if not FIdTelnet.Connected then FIdTelnet.Connect; try if FIdTelnet.Connected then begin s := '*' + Command + #13#10; //コマンドの改行が必要か否か sendcmd := s; if not FNecessaryCRLF then sendcmd := Trim(sendcmd); //コマンド送信前イベント if Assigned(FOnSend) then FOnSend(Self, sendcmd); for i := 1 to Length(s) do FIdTelnet.SendCh(s[i]); FLogList.Add('*' + Command); if cmd = 'ic' then IsLearning := True; end; finally //コマンド応答が終わるまで待機 while not IsReturnFinished do begin Application.ProcessMessages; Sleep(10); //学習タイムアウト時間を超えたら学習キャンセル if IsLearning and ((GetTickCount-startms) > FLearningTimeout) then begin StopLearning; end; //学習時以外は5秒でループを抜ける if not IsLearning and ((GetTickCount-startms) > 5000) then begin Break; end; end; lrc := TmpLastReturnCommand; // DOut(lrc); Result := not (Pos(cmd + ';err;', lrc) > 0); //コマンド成功か if Result then begin //文字列先頭から改行まで FLastReturnCommand := Copy(lrc, 1, Pos(#13#10, lrc)+1); // lrc := StringReplace(lrc, 'cc;ok'#13#10, '', []); // DOut(TmpLastReturnCommand); // DOut('1' + FLastReturnCommand); //コマンドの改行が必要か否か if not FNecessaryCRLF then FLastReturnCommand := Trim(FLastReturnCommand); //コマンド送信後イベント if Assigned(FOnSent) then FOnSent(Self, FLastReturnCommand); end else begin // //文字列の送信コマンド先頭から文末まで // if Pos('cc;ok', lrc) > 0 then begin // lrc := StringReplace(lrc, 'cc;ok'#13#10, '', []); // end; FLastReturnCommand := Copy(lrc, Pos(cmd, lrc), Length(lrc)); FIsLastCommandError := True; SetErrors(lrc); // DOut('2' + FLastReturnCommand); //コマンドの改行が必要か否か if not FNecessaryCRLF then FLastReturnCommand := Trim(FLastReturnCommand); //コマンド送信後イベント if Assigned(FOnSent) then FOnSent(Self, FLastReturnCommand); if Assigned(FOnCustomError) then FOnCustomError(Self, FLastErrorCode, FLastErrorTitle, FLastErrorMessage); end; //コマンド送信後イベント // if Assigned(FOnSent) then begin // FOnSent(Self, FLastReturnCommand); // end; //オンタイマー、音声切り替え FLogList.Add(FLastReturnCommand); Sleep(FInterval); //連射防止のインターバル //切断 if FIdTelnet.Connected then FIdTelnet.Disconnect; end; end; procedure TIRemocon.SetErrors(const ReturnCommand: string); var s, errCode: string; begin s := ReturnCommand; errCode := Copy(s, Pos(#13#10, s)-3, 3); if errCode = '010' then begin FLastErrorTitle := 'フォーマットエラー'; FLastErrorMessage := 'コマンドの書式が不正です。'; FLastErrorCode := 'XX' + errCode; end else if errCode = '020' then begin FLastErrorTitle := 'タイムアウトエラー'; FLastErrorMessage := 'コマンド入力が5秒以上途切れました。'; FLastErrorCode := 'XX' + errCode; end else if errCode = '051' then begin FLastErrorTitle := '内部システムタイムアウトエラー'; FLastErrorMessage := '内部のシステムタイムアウトエラー 。'; FLastErrorCode := 'XX' + errCode; end else if errCode = '052' then begin FLastErrorTitle := '内部システム応答データなしエラー'; FLastErrorMessage := '内部システムに応答するデータがありません。'; FLastErrorCode := 'XX' + errCode; end else if errCode = '053' then begin FLastErrorTitle := '内部システム応答データ不正エラー'; FLastErrorMessage := '内部システムの応答データが不正です。'; FLastErrorCode := 'XX' + errCode; end else begin if Pos('is;', s) > 0 then begin FLastErrorTitle := ''; FLastErrorMessage := ''; FLastErrorCode := 'IS' + errCode; if errCode = '001' then begin FLastErrorTitle := 'リモコン番号範囲外'; FLastErrorMessage := 'リモコン番号が1~1500の範囲外です。'; end else if errCode = '002' then begin FLastErrorTitle := 'リモコンデータ未登録エラー'; FLastErrorMessage := 'リモコンデータが記録されていない番号が指定されました。'; end else if errCode = '003' then begin FLastErrorTitle := '送信エラー '; FLastErrorMessage := '不正なデータを送信しようとしました。'; end; end else if Pos('ic;', s) > 0 then begin FLastErrorCode := 'IC' + errCode; if errCode = '001' then begin FLastErrorTitle := 'リモコン番号範囲外'; FLastErrorMessage := 'リモコン番号が1~1500の範囲外です。'; end else if errCode = '002' then begin FLastErrorTitle := '学習キャンセル'; FLastErrorMessage := 'リモコン学習はコマンドによってキャンセルされました。'; end else if errCode = '003' then begin FLastErrorTitle := '受信エラー'; FLastErrorMessage := '不正なリモコンデータを受信しました。'; end else if errCode = '004' then begin FLastErrorTitle := 'リモコンデータ件数エラー'; FLastErrorMessage := '登録可能なリモコンデータの最大件数を超えて登録しようとしています。'; end else if errCode = '005' then begin FLastErrorTitle := '二重操作エラー'; FLastErrorMessage := '既にic/ibで受信待ちの状態です。'; end; end else if Pos('cc;', s) > 0 then begin FLastErrorCode := 'CC' + errCode; if errCode = '001' then begin FLastErrorTitle := '実行エラー'; FLastErrorMessage := 'リモコンコード学習モード以外の状態に対して実行しました。'; end; end else if Pos('tm;', s) > 0 then begin FLastErrorCode := 'TM' + errCode; if errCode = '001' then begin FLastErrorTitle := 'リモコン番号範囲外'; FLastErrorMessage := 'リモコン番号が1~1500の範囲外です。'; end else if errCode = '002' then begin FLastErrorTitle := '実行時間範囲外エラー'; FLastErrorMessage := '現在時刻+1~4102444800の範囲外です。'; end else if errCode = '003' then begin FLastErrorTitle := '繰り返し時間範囲外エラー'; FLastErrorMessage := '0~31536000以外の範囲が指定されました。'; end else if errCode = '004' then begin FLastErrorTitle := '2重登録エラー(同一時間あり)'; FLastErrorMessage := '既に同一の時間にタイマー登録されています。'; end else if errCode = '005' then begin FLastErrorTitle := '登録数オーバーエラー'; FLastErrorMessage := '登録数オーバー(最大500件)です。'; end else if errCode = '006' then begin FLastErrorTitle := 'リモコンデータエラー'; FLastErrorMessage := 'リモコンデータが登録されていない番号が指定されました。'; end else if errCode = '007' then begin FLastErrorTitle := '曜日指定エラー'; FLastErrorMessage := '曜日指定のフォーマットが不正です。'; end; end else if Pos('tl;', s) > 0 then begin FLastErrorCode := 'TL' + errCode; if errCode = '001' then begin FLastErrorTitle := 'タイマー登録なし'; FLastErrorMessage := 'タイマーが1件も登録されていません。'; end; end else if Pos('td;', s) > 0 then begin FLastErrorCode := 'TD' + errCode; if errCode = '001' then begin FLastErrorTitle := 'タイマー番号範囲外エラー'; FLastErrorMessage := '1~500の範囲外です。'; end else if errCode = '002' then begin FLastErrorTitle := 'タイマー登録なし'; FLastErrorMessage := '指定したタイマー番号のタイマーが存在しません。'; end; end else if Pos('ts;', s) > 0 then begin FLastErrorCode := 'TS' + errCode; if errCode = '001' then begin FLastErrorTitle := '設定時間範囲外'; FLastErrorMessage := '1293775200~4102444800の範囲外です。'; end; end else if Pos('li;', s) > 0 then begin FLastErrorCode := 'LI' + errCode; if errCode = '001' then begin FLastErrorTitle := 'センサーの値が不正'; FLastErrorMessage := 'センサーの値が不正です。'; end; end else if Pos('hu;', s) > 0 then begin FLastErrorCode := 'HU' + errCode; if errCode = '001' then begin FLastErrorTitle := 'センサーの値が不正'; FLastErrorMessage := 'センサーの値が不正です。'; end; end else if Pos('te;', s) > 0 then begin FLastErrorCode := 'TE' + errCode; if errCode = '001' then begin FLastErrorTitle := 'センサーの値が不正'; FLastErrorMessage := 'センサーの値が不正です。'; end; end else if Pos('se;', s) > 0 then begin FLastErrorCode := 'SE' + errCode; if errCode = '001' then begin FLastErrorTitle := 'センサーの値が不正'; FLastErrorMessage := 'センサーの値が不正です。'; end; end; end; end; function TIRemocon.IsRemoconNoValid(RemoconNo: Word): Boolean; begin if (RemoconNo >= 1) and (RemoconNo <= 1500) then Result := True else begin raise Exception.Create('リモコン番号が1 - 1500の範囲外です。'); Result := False; end; end; procedure TIRemocon.SetLearningTimeout(const Value: Cardinal); begin FLearningTimeout := Value; if Value < 3000 then begin FLearningTimeout := 3000; raise Exception.Create('3000ms(3秒)以上に設定してください。'); end else if Value > (1000*60) then begin raise Exception.Create('60000ms(1分)以下に設定してください。'); FLearningTimeout := 1000*60; end; end; procedure TIRemocon.SetInterval(const Value: Word); begin FInterval := Value; if Value < 100 then begin FInterval := 100; raise Exception.Create('100ms(0.1秒)以上に設定してください。'); end else if Value > 2000 then begin FInterval := 2000; raise Exception.Create('2000ms(2秒)以下に設定してください。'); end; end; procedure TIRemocon.SetOnSend(const Value: TSendEvent); begin FOnSend := Value; end; procedure TIRemocon.SetOnSent(const Value: TSentEvent); begin FOnSent := Value; end; procedure TIRemocon.SetHost(const Value: string); begin FHost := Value; FIdTelnet.Host := Value; end; procedure TIRemocon.SetOnCustomError(const Value: TCustomErrorEvent); begin FOnCustomError := Value; end; procedure TIRemocon.SetNecessaryCRLF(const Value: Boolean); begin FNecessaryCRLF := Value; end; function TIRemocon.GetIlluminance(var Illuminance:Single): Boolean; begin Result := SendCommand('li'); if Result then Illuminance := StrToFloatDef(StringReplace(FLastReturnCommand, 'li;ok;', '', []), -1) else Illuminance := -1; end; function TIRemocon.GetHumidity(var Humidity: Single): Boolean; begin Result := SendCommand('hu'); if Result then Humidity := StrToFloatDef(StringReplace(FLastReturnCommand, 'hu;ok;', '', []), -1) else Humidity := -1; end; function TIRemocon.GetTemperature(var Temperature: Single): Boolean; begin Result := SendCommand('te'); if Result then Temperature := StrToFloatDef(StringReplace(FLastReturnCommand, 'te;ok;', '', []), -1000) else Temperature := -1000; end; function TIRemocon.GetSensors(var Illuminance, Humidity, Temperature: Single): Boolean; var s:String; sl:TStringList; begin Result := SendCommand('se'); if Result then begin sl := TStringList.Create; try s := StringReplace(FLastReturnCommand, 'se;ok;', '', []); s := StringReplace(s, ';', ',', [rfReplaceAll]); sl.CommaText := s; Illuminance := StrToFloatDef(sl[0], -1); Humidity := StrToFloatDef(sl[1], -1); Temperature := StrToFloatDef(sl[2], -1000); finally sl.Free; end; end else begin Illuminance := -1; Humidity := -1; Temperature := -1000; end; end; end. |
あと、当然ながらこのアプリを利用するには、iRemocon Wi-Fiが必要です。
アプリの使い方
Windowsから、アプリを利用するには、実行ファイルを起動して、以下の部分にiRemocon Wi-FiのローからIPアドレスを入力します。
WindowsでのIP取得方法は、以下を参照してください。
IPを入力したら、あとは、以下のコマンドボタンで操作をします。
個々のコマンドについては、以下に書いてあるコマンドの使い方を参照してください。
すると、こんな感じで、簡易的ではありますが、GUIからiRemocon Wi-Fiを操作出来るようになります。
こんな感じで、コマンドと実行結果が表示されます。
これを応用すれば、iRemocon Wi-Fiを利用して、自分好みのリモコンアプリなどを作ることができます。
とりあえず、こういったものの機能を強化したものが以下の、Windows用、iRemoconリモコンアプリになります。
こちらは、iRemocon Wi-Fiのセンサー機能はまだ取り込んでないですが、ローカルIPさえ取得できれば、iRemocon Wi-Fiを操作することができます。
まとめ
このように、iRemocon Wi-Fiはアプリからでも操作できます。
僕は、Windowsのデスクトップアプリ用の言語は、Delphiしかまともに書けないので、マイナーな言語で申しわけないのですが、何かの参考になれば幸いです。
そして、他人まかせで申し訳ないですけど、誰かがもっと良いアプリを作ってくれて、より快適な生活が送れれば最高です。
最近、PHPや、Rubyのような、軽量プログラミング言語に慣れてしまったら、手間がかかるし面倒くさいデスクトップアプリで、新たに何か作る気が起きない…。