パソコンからの信号をRS485に変換する中継器のプログラムです。

Dependencies:   arrc_mbed

Fork of USB2RS485 by Hiroki Tanaka

Files at this revision

API Documentation at this revision

Comitter:
TanakaRobo
Date:
Tue Mar 23 09:09:27 2021 +0000
Commit message:
first commit

Changed in this revision

arrc_mbed.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/arrc_mbed.lib	Tue Mar 23 09:09:27 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/TanakaRobo/code/arrc_mbed/#77c13e86ad12
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Mar 23 09:09:27 2021 +0000
@@ -0,0 +1,27 @@
+#include <mbed.h>
+#include <scrp_slave.hpp>
+
+//パソコンのScrpMonitorから送った信号をそのままRS485で送信します。
+//USBで受信したデータをMILLポートから出力します。
+//cmd 0,253,254は使えません。
+
+ScrpSlave slave(PA_9 ,PA_10,PA_12,SERIAL_TX,SERIAL_RX,255);//全受信モード
+
+bool rs485(int rx_data, int &tx_data){
+    if(slave.receivePort() == 1){//USBから受信した時にMILLポートから送信する。
+        slave.send1(slave.receiveId(), slave.receiveCmd(), rx_data);
+    }
+    return false;
+}
+
+void response(uint8_t id,uint8_t cmd, int16_t data){
+    slave.send2(id, cmd, data, false);//返ってきたレスポンスをUSBに送信する。
+}
+
+int main(){
+    for(int i = 0;i < 256;i++){
+        slave.addCMD(i, rs485);
+    }
+    slave.attachResponse(response);
+    while(true);
+}
\ No newline at end of file