#05 RS485トランシーバ
Tibbitの配置
Tibbit #05を挿入します。
使用できるスロットは、1,3,5,7,9です。
シリアルの設定
シリアル設定の登録方法は、#01 RS232トランシーバのチュートリアルの「シリアルの設定」を参考にしてください。
ノードの配置
送受信切り替え
このTibbitブロックでは、まず送受信の切り替えを行う必要があります。
以下のようにフローを配置します。
functionノードの編集を開き、コードに以下を記述します。
1 2 |
msg.payload = {act: 'io', v: 1}; return msg; |
1 2 |
msg.payload = {act: 'io', v: 0}; return msg; |
ノードの設定を開き、スロットとシリアル設定を選択します。
Node-REDデプロイ後、各injectノードをクリックするとOutput/Inputを切り替えることができます。
サンプルフロー
1 |
[{"id":"d67e0e2d.9e98b","type":"inject","z":"d0a8e665.0b3038","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":880,"y":1260,"wires":[["b91d5021.aed1b8"]]},{"id":"b9581e42.023918","type":"inject","z":"d0a8e665.0b3038","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":880,"y":1300,"wires":[["de7852ae.9dea28"]]},{"id":"b91d5021.aed1b8","type":"function","z":"d0a8e665.0b3038","name":"Output","func":"msg.payload = {act: 'io', v: 1};\nreturn msg;","outputs":1,"noerr":0,"x":1020,"y":1260,"wires":[["6d86edfb.66855c"]]},{"id":"de7852ae.9dea28","type":"function","z":"d0a8e665.0b3038","name":"Input","func":"msg.payload = {act: 'io', v: 0};\nreturn msg;","outputs":1,"noerr":0,"x":1010,"y":1300,"wires":[["6d86edfb.66855c"]]},{"id":"6d86edfb.66855c","type":"Tibbit-#05 out","z":"d0a8e665.0b3038","name":"","tpSlot":"S01","communication":"Serial","serialConf":"21e4a251.3b34a6","connectedStatus":"start","host":"","moreDefaults":[{"outputOnly":{"value":false},"communication":{"value":"GPIO"},"pinA":{"value":"other"},"pinB":{"value":"other"},"pinC":{"value":"OUT_OD"},"pinD":{"value":"other"}}],"x":1200,"y":1280,"wires":[]},{"id":"21e4a251.3b34a6","type":"tp-config-serial","z":"","serialName":"シリアル1","hardwareFlow":"off","seriBaudRate":"9600","seriDataBits":"8","seriParity":"none","seriStartBits":"1","seriStopBits":"1","seriSplitInput":"1","seriOnTheCharactor":"\\n","seriAfterATimeoutOf":"0","seriIntoFixedLengthOf":"0"}] |
シリアルのIN
以下のようにフローを配置します。
ノードの設定を開き、スロットとシリアル設定を選択します。
Node-REDデプロイ後、機器からのデータを受信します。
シリアル設定でのハードウェアフローは使用できません。
サンプルフロー
1 |
[{"id":"1c4e9083.e8468f","type":"Tibbit-#05 in","z":"d0a8e665.0b3038","name":"","tpSlot":"S01","communication":"Serial","outputOnly":true,"serialConf":"21e4a251.3b34a6","connectedStatus":"start","host":"","moreDefaults":[{"outputOnly":{"value":false},"communication":{"value":"GPIO"},"pinA":{"value":"other"},"pinB":{"value":"other"},"pinC":{"value":"OUT_OD"},"pinD":{"value":"other"}}],"x":940,"y":1280,"wires":[["9fad1fa0.76b7e8"]]},{"id":"9fad1fa0.76b7e8","type":"debug","z":"d0a8e665.0b3038","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1110,"y":1340,"wires":[]},{"id":"21e4a251.3b34a6","type":"tp-config-serial","z":"","serialName":"シリアル1","hardwareFlow":"off","seriBaudRate":"9600","seriDataBits":"8","seriParity":"none","seriStartBits":"1","seriStopBits":"1","seriSplitInput":"1","seriOnTheCharactor":"\\n","seriAfterATimeoutOf":"0","seriIntoFixedLengthOf":"0"}] |
シリアルのOUT
送信するデータをセットするため、functionノードを使用します。
以下のようにフローを配置します。
functionノードの編集を開き、コードに以下を記述します。
「test」の部分が送信されるデータになりますので、適宜変更してください。
→文字列以外にもbytesなどでも可能。
1 2 |
msg.payload = Buffer.from("test\n"); return msg; |
ノードの設定を開き、スロットとシリアル設定とモードを選択します。
Node-REDデプロイ後、injectノードをクリックすると機器へデータを送信することができます。
シリアル設定でのハードウェアフローは使用できません。
サンプルフロー
1 |
[{"id":"68038275.de6b3c","type":"function","z":"d0a8e665.0b3038","name":"シリアル送信データ","func":"msg.payload = Buffer.from(\"test\\n\"); \nreturn msg;","outputs":1,"noerr":0,"x":1060,"y":1060,"wires":[["d56b3ede.f183c"]]},{"id":"d5fe7777.76ba28","type":"inject","z":"d0a8e665.0b3038","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":900,"y":1020,"wires":[["68038275.de6b3c"]]},{"id":"d56b3ede.f183c","type":"Tibbit-#05 out","z":"d0a8e665.0b3038","name":"","tpSlot":"S01","communication":"Serial","serialConf":"21e4a251.3b34a6","connectedStatus":"start","host":"","moreDefaults":[{"outputOnly":{"value":false},"communication":{"value":"GPIO"},"pinA":{"value":"other"},"pinB":{"value":"other"},"pinC":{"value":"OUT_OD"},"pinD":{"value":"other"}}],"x":1200,"y":1100,"wires":[]},{"id":"21e4a251.3b34a6","type":"tp-config-serial","z":"","serialName":"シリアル1","hardwareFlow":"off","seriBaudRate":"9600","seriDataBits":"8","seriParity":"none","seriStartBits":"1","seriStopBits":"1","seriSplitInput":"1","seriOnTheCharactor":"\\n","seriAfterATimeoutOf":"0","seriIntoFixedLengthOf":"0"}] |