485-LINK

RS485介面

 
槽位
1 2 3 4
5 6 7 8

網 路 參 考 連 結

各種BOARD的serial port配置介紹
 

B4R = Basic4Arduino

Libraries Manager  rCore  rRandomAccessFile  rSoftwareSerial
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
  Public Serial1 As Serial
  Public rs485 As SoftwareSerial
  Public astream As AsyncStreams
  Public timer1 As Timer
  Public n1 As UInt
End Sub

Private Sub AppStart
  serial1.Initialize(9600)
  rs485.Initialize(9600, 19, 18)
  astream.Initialize(rs485.Stream, "astream_newdata", Null)
  timer1.Initialize("timer1_tick",1000)
  timer1.Enabled=True
  Log("AppStart")
End Sub


Sub astream_NewData (Buffer() As Byte)

End Sub

Sub timer1_tick
  Dim ss As String
  n1=n1+1
  ss=NumberFormat(n1,3,0) 
  Dim b() As Byte=JoinBytes(Array(ss.GetBytes,Array As Byte(13,10)))
  astream.Write(b)
End Sub
 

程 式 說 明

13  rs485.Initialize(9600,19,18)
  初始化物件,速度9600, RX腳位為19, TX腳位為18
14 astream.Initialize(rs485.Stream, "astream_newdata", Null)
  初使化RS485的串流及串流收到資料的事件
15 timer1.Initialize("timer1_tick",1000)
初使化一個1000ms的Timer
26 ~ 30 傳送格式化數字(ss)給RS485(astream.Write(b)