顯示具有 ARDUINO application 標籤的文章。 顯示所有文章
顯示具有 ARDUINO application 標籤的文章。 顯示所有文章

2014年12月21日 星期日

Lab05-ARDUINO UNO R3:Arduino 與 PLC 連線,運用VB模擬



ARDUINO 模擬 PLC 回應 型式一(FORM1 資料格式)

練習測試 :開始試做 FORM1

格式測試 (暫未實際動態模擬)

使用;VB6,ARDUINO UNO board,ARDUINO IDE開發環境,USB line

1.ARDUINO 端程式


void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600);
  while (!Serial)  { //  // Open serial communications and wait for port to open
  }                 //otherwise the data will send and lost before you recieve

  }
void loop() {
  // put your main code here, to run repeatedly:
  //Simulate PLC sned back the data-format as form1 spec.
  // below we can get form1 data-format as STX+01FF10100100+ETX+73
  char val; //define char,use print(char) will send out a char(like STX) not a number.
  val=2;
  Serial.print(val);
  Serial.print("01FF10100100");
  val=3;
  Serial.print(val);
  Serial.print("73");
  while (true) ; // keep loop here, then loop will not send again again
                 // repeatly will casue com-buffer > form1 format
}

2.VB6 端 程式

注意:1. 請先加入MS comm 元件 專案\設定使用元件\Microsoft comm control 6.0(元件)
     2. Comport setting 設定 一致;arduino 預設 9600,n,8,1
     4. 元件 commPort 一致 ,從裝置管理員看.

數據解析 副程式=>並將燈號圖示進行顏色導通顯示(綠色)

Private Sub ParserData()
Dim RcvBuf As String
Dim SumChkStrRcv As String
Dim SumChkStr As String
Dim H02Pos As Integer
Dim H03Pos As Integer
Dim i As Integer
    'PLC 回傳數據處理 之 副程式
        RcvBuf = Text9.Text
        H02Pos = InStr(RcvBuf, Chr(2))
        H03Pos = InStr(RcvBuf, Chr(3))
        If H02Pos >= 1 And (H03Pos - H02Pos) >= (TxtRcvLen.Text - 3) Then
           SumChkStrRcv = Mid(RcvBuf, H03Pos + 1, 2)
           SumChkStr = chksum(Mid(RcvBuf, H02Pos + 1, H03Pos - 1))
           If SumChkStrRcv = SumChkStr Then
               For i = 0 To (Val(Text7.Text) - 1)
                  If Mid(RcvBuf, 6 + i, 1) = 1 Then
                     ShpX(i).FillColor = vbGreen
                  Else
                     ShpX(i).FillColor = &HC0C0C0
                  End If
               Next
               Text10.Text = 6 'ACK
'            Else
'               MsgBox "通信錯誤"
'               Text10.Text = 21 'NAK
            End If
            Call Command3_Click
           MSComm1.InBufferCount = 0
        End If
End Sub




測試結果 可接收


2014年12月11日 星期四

Lab04-ARDUINO UNO R3 :第4個實驗練習=LabView讀取Arduino,LabView與Arduino通訊(LabView communicate with Arduino.

2014年/Dec

這件事我花了不少時間.問了老師,FB社團,查NI 等相關網站,Google 了 一下.

紀錄今天的進度與方案;

使用了幾年前的筆記本電腦 CPU 1.5 GHz,RAM 1G RAM.
Window XP Home Edition,SP3
目前2014/Dec 跑起來真的不快.

下載了NI 的 免費LabView 2014 web-base installer.準備安裝 labView Developement system.
http://www.ni.com/download/web-based-installer-labview-development-system-14.0/5072/en/

1.裝的過程中,要求我先裝 .Net Framwork 4.0,我去找了資源如下安裝
http://www.microsoft.com/en-us/download/confirmation.aspx?id=17718

2.然後回到最初安裝 NI web-installer(預設9GB,myGod)
http://www.ni.com/download/web-based-installer-labview-development-system-14.0/5072/en/

或者
1.35GB

Download the Evaluation Version of NI LabVIEW

http://www.ni.com/gate/gb/GB_EVALLV/US

3.然後安裝
NI VISA Driver
==>按照底下做法
http://ming-shian.blogspot.tw/2013/10/labviewarduino-by-visa.html
(1)硬體接線 (類比也應該可以吧,aduino 類比也是數位)


(2)寫入以下程式 Load到Arduino裡面=>開監看確認com port連上


(4)撰寫labView程式如下---
(說真的如果沒學過LabView,其實會看不懂底下的圖塊作用,還好上課學了,其實沒學labview,也就不會去用這個)


LabView連上ARDUINO的實驗結果




當然也有幾種做法,
1.使用 LIFA 內建 VI 開啟加入專案,去連.
    http://ming-shian.blogspot.tw/2013/09/labviewarduino.html

     韌體部分: 兩種選擇

  • LIFA_BASE.ino 編譯時 會有錯誤
  • 不過,因為函式庫可能有衝突現象,先暫時把出問題的IRremote 等等先移開另存,便可解決

  • 如果只是單純的I/O
  • 使用一般的analog read/write 或 digital read/ write便可



2.使用 LIFA / LINX 內建 VI 開啟加入專案,去連.(2015目前LINX 將取代LIFA)




  • 首先也是必須安裝NI VISA 驅動程式
  • 然後開啓 LINX 支援 LabView 的元件套件 或者開啓LIFA 元件
  • 韌體如同1.之兩種選擇




3.出錯的話
(1)用MAX,裝置管理員或LabVIEW的Max裡看看設備是否都連上線了。
(2)ARDUINO 板是否已上電腦
(3)Serial PORT 的選擇對不對 LabView (看VISA PORT NAME)跟 ARDUINO 都要選擇,且一樣
(4)VISA安裝 SERIAL 功能,必須連帶安裝remote server 項目,還有Framework4.0 =我的是這樣,你的可能還要安裝看你的系統而定
(5) LabView 開發環境中還有VI 在運行
(6) 開關COMPORT 速度過快 未正常關掉=重開吧!
(7) 沒有設定 VISA PORT NAME ,沒有設定好 BAUDRATE ,,檢查碼,停止位元,(GOOGLE 查下)
   ARDUINO預設 9600,8N1

其他資源
ARDUINO.TW
arduino.CC
https://labviewhacker.com/doku.php......

應用思考題:

1.ARDUINO 是否可當作一個簡易 I/O 硬體 ,作為 LabView 控制儀器界面?RS232/485 ,USB ?
2.ARDUINO 可否作為高速計數器, high speed counter ?