| RSLinxを外部アプリケーションからアクセスする方法 |
このテクニカルノートの情報は、以下に該当します:
| 製品: | RSLinx, RSLinx CSDK | タイプ: | テクニカルノート |
| テクニカルノートID: | ERSLNX-001JA | ||
| パッケージ/モジュール: | ---- | 英文版作成日: | 2004/2/20 |
| リビジョン: | ---- | ||
| 修正リビジョン: | ---- | ||
| サブシステム: | ---- |
| テクニカルノート本文: |
- VisualBasicやVisual Cなどの外部アプリケーションを使用してコントローラの値を読み書きするには、RSLinxが持っている以下の3種類のインタフェースを使用して実行可能です。
1. DDE(Dynamic Data Exchange)
- Windowsアプリケーション間でのデータやコマンドのやり取りを行なうための手順の一つ。Windows 2.0から実装されている古いインタフェースで、現在はあまり使用されない。簡単なデータのやり取りには使用できる。
- マイクロソフト社のオブジェクト技術「OLE/ActiveX」を利用した、製造業におけるFA(ファクトリー オートメーション)・ PA(プロセス オートメーション)のアプリケーション相互接続を容易にするインタフェースの統一規格です。
RSLinxが提供する専用のインタフェース関数。アプリケーションの開発にはRSLinx CSDKが必要。
それぞれ以下のような特徴があります。
表1:RSLinxのインタフェース
| DDE | OPC | RSLinx API | |
| 開発に使用可能なプログラミング言語 | VisualBasicまたは Visual C | VisualBasicまたは Visual C | VisualBasicまたは Visual C |
| 処理パフォーマンス (1:遅い-5:速い) | 3 | 5 | 5 |
| 開発の容易さ (1:簡単-5:難しい) | 2-3 | 4 | 3 |
| 開発に必要な知識 | 使用するプログラミング言語 DDEの基本 | 使用するプログラミング言語 OPCインタフェース | 使用するプログラミング言語 一般的なDLLの使用方法 |
| 必要なRSLinx製品 | RSLinx SingleNode, RSLinx OEM、 RSLinx Professional、 RSLinx Gatewayのどれか*1 | RSLinx SingleNode, RSLinx OEM、 RSLinx Professional、 RSLinx Gatewayのどれか*1 (サンプルプログラムが必要な場合はRSLinx C SDK*2) | RSLinx CSDK *2 |
| その他 | EXCELなどDDEに対応するアプリケーションからアクセス可能 | 汎用のインタフェースのため、OPCに対応するさまざまなアプリケーションとも接続可能 | RSLinxのDLL(ダイナミックリンクライブラリ)を使用したAPI関数の呼び出しによるアクセス |
*1 RSLinxの各機能については表2を参照してください。
*2 RSLinx CSDKは以下のサンプルコードおよびマニュアル、ヘルプファイルが付属している製品です。作成したアプリケーションの実行用としてRSLinx OEMが付属しています。(Catalog # : 9355-WABCENE)
- RSLinx APIを使用したCのサンプルプログラム
- OPCを使用したサンプルプログラム(VB用およびC用)
- API関数およびOPCインタフェースを記述したマニュアル(英文)およびヘルプファイル(英文)
VBのサンプルはVisualBasic v6.0を使用します。
作成したアプリケーションは、RSLinx CSDK付属のRSLinx OEMとともに実行できます。2台以上で実行する場合はRSLinx OEM、RSLinx Professional、RSLinx Gatewayのどれかを購入する必要があります。作成したアプリケーションは再配布可能です。
表2:RSLinxの各製品
Single Node | OEM | Professional | Gateway | |
| Catalog Number | 9355- WABSNENE | 9355- WABOEMENE | 9355- WABENE | 9355- WABGWENE |
| Communication Drivers | x | x | x | x |
| Integrated ControlLogix Gateway Configuration Tool | x | x | x | x |
| Driver and Station Diagnostics | x | x | x | x |
| Device Properties | x | x | x | x |
| 1756 Module Statistics | x | x | x | x |
| Data Monitor | x | x | ||
| Ladder Viewer (PLC-5 and SLC-500 only) | x | x | ||
| DDE Support (CF_Text, XL_Table, AdvanceDDE1) | x* | x | x | x |
| DDE Support (FastDDE2) | x | x | ||
| OPC to Local Clients | x* | x | x | x |
| OPC to Remote Clients | x | |||
| Supports applications developed with RSLinx C API | x | x | x | |
| Supports direct drivers in HMI applications | x | x | x | |
| Remote Gateway Client Connection | x |
VisualBasicでDDEを使用した例:
Private Sub Command1_Click()
On Error GoTo Readerror_handler
Text1.LinkTopic = "RSLinx|test" 'アプリケーションおよびトピックの指定
Text1.LinkItem = "Program:MainProgram.T1,L1,C1" 'アイテムの指定
Text1.LinkMode = vbLinkAutomatic 'DDE手動リンクモード
Text1.LinkRequest '読出しの実行
Exit Sub
Readerror_handler:
MsgBox "Read Error"
End Sub
Visual BasicでC-APIを使用した例:
Declare Function DTL_DRIVER_OPEN Lib "DTL32.DLL" (ByVal nDriverID As Integer, ByVal szDriverName As String, ByVal Timeout As Integer) As Integer
Declare Function DTL_DRIVER_CLOSE Lib "DTL32.DLL" (ByVal nDriverID As Integer) As Integer
Declare Function DTL_C_DEFINE Lib "DTL32.DLL" (ByRef NameId As Integer, ByVal Def As String) As Integer
Declare Function DTL_UNDEF Lib "DTL32.DLL" (ByVal nDefineID As Integer) As Integer
Declare Sub DTL_ERROR_S Lib "DTL32.DLL" (ByVal Status As Integer, ByVal ErrStr As String, ByVal StrSize As Short)
Declare Function DTL_INIT Lib "DTL32.DLL" (ByVal Def As Integer) As Integer
Declare Function DTL_READ_W Lib "DTL32.DLL" (ByVal NameId As Integer, ByRef Variable As Any, ByRef iostat As Integer, ByVal Timeout As Integer) As Integer
Declare Sub DTL_UNINIT Lib "DTL32.DLL" (ByVal Param As Integer)
Declare Function DTL_WRITE_W Lib "DTL32.DLL" (ByVal NameId As Integer, ByRef Variable As Any, ByRef iostat As Integer, ByVal Timeout As Integer) As Integer
Sub DTLDriverOpen()
Dim szDriverName As Object
nDriverID = CInt(Form1.DefInstance.DriverID.Text)
szDriverName = Form1.DefInstance.DriverName.Text
nTimeout = CInt(Form1.DefInstance.Timeout.Text)
Status = DTL_DRIVER_OPEN(nDriverID, szDriverName, nTimeout)
Form1.DefInstance.iostatcode.Text = CStr(Status)
End Sub
'DTL Initialize
Sub DTLInit()
nTableSize = CInt(Form1.DefInstance.Table.Text)
Status = DTL_INIT(nTableSize)
Form1.DefInstance.iostatcode.Text = CStr(Status)
End Sub
'DTL Define
Sub DTLDefine()
Dim szDef As Object
Form1.DefInstance.Define.Text = Form1.DefInstance.Sentou.Text & "," & Form1.DefInstance.Datasu.Text & "," & Form1.DefInstance.Dataty.Text & "," & Form1.DefInstance.Acty.Text & "," & Form1.DefInstance.PortID.Text & "," & Form1.DefInstance.Stno.Text & "," & Form1.DefInstance.Proty.Text & "," & Form1.DefInstance.DriverID.Text
szDef = Form1.DefInstance.Define.Text
nDefineID = CInt(Form1.DefInstance.DefineID.Text)
Status = DTL_C_DEFINE(nDefineID, szDef)
Form1.DefInstance.iostatcode.Text = CStr(Status)
End Sub
'DTL Read
Sub DTLRead()
Dim szJunk As Object
nDefineID = CInt(Form1.DefInstance.DefineID.Text)
nTimeout = CInt(Form1.DefInstance.Timeout.Text)
Status = DTL_READ_W(nDefineID, data(1), iostat, nTimeout)
Form1.DefInstance.iostatcode.Text = CStr(Status)
For n = 1 To CInt(Form1.DefInstance.Datasu.Text)
szJunk = Space(6 - Len(Str(data(n)))) & Str(data(n))
Form1.DefInstance.Results.Text = szJunk
Next
End Sub
Visual BasicでOPCインタフェースを使用した例:
Public Sub AsyncRead()
'/*
'/* This function demonstrates how to perform an OPC Group Asynchronous Read operation.
'/* The data is returned in the callback function MyOPCGroup_AsyncReadComplete
'/*
Dim lNumitems As Long
Dim arHandles() As Long
Dim arErrors() As Long
Dim lTransID As Long
Dim lCancelID As Long
Dim i As Long
On Error GoTo ErrorHandler
txtStatus = "OPC Group Async Read in progress ..."
'/* Specify number of elements
lNumitems = MyOPCGroup.OPCItems.Count
ReDim arHandles(1 To lNumitems)
For i = 1 To lNumitems
'/* Pass in server handles
arHandles(i) = MyOPCGroup.OPCItems(i).ServerHandle
Next 'i
'/* Set TransactionID to keep track of where request was made from
lTransID = 5
'/* Perform AsyncRead
MyOPCGroup.AsyncRead lNumitems, arHandles, arErrors, lTransID, lCancelID
'/* Check for errors
For i = 1 To lNumitems
If arErrors(i) > 0 Then
Call DisplayErrorString(arErrors(i))
End If
Next 'i
Exit Sub
ErrorHandler:
PostMessage Err.Number
End Sub
Public Sub AsyncWrite()
'/*
'/* This function demonstrates how to perform an OPC Group Asynchronous Write operation.
'/* Any errors are reported in the callback function MyOPCGroup_AsyncWriteComplete
Dim lNumitems As Long
Dim arData() As Variant
Dim arHandles() As Long
Dim arErrors() As Long
Dim lTransID As Long
Dim lCancelID As Long
Dim i As Long
Dim sData As String
On Error GoTo ErrorHandler
txtStatus = "OPC Group Async Write operation in progress ..."
'/* Specify number of elements
lNumitems = MyOPCGroup.OPCItems.Count
ReDim arHandles(1 To lNumitems)
ReDim arData(1 To lNumitems)
For i = 1 To lNumitems
'/* Pass in the server handles
arHandles(i) = MyOPCGroup.OPCItems(i).ServerHandle
'/* Pass in the data
sData = txtData(MyOPCGroup.OPCItems(i).ClientHandle).Text
If InStr(sData, ",") Then
'/* Convert multi-item string to array
arData(i) = ConvertStringToArray(sData)
Else
'/* Single item value
arData(i) = sData
End If
Next 'i
'/* Set TransactionID to keep track of AsyncWrite request
lTransID = 4
'/* Write data to server
MyOPCGroup.AsyncWrite lNumitems, arHandles, arData, arErrors, lTransID, lCancelID
'/* Check for errors
For i = 1 To lNumitems
If arErrors(i) > 0 Then
Call DisplayErrorString(arErrors(i))
End If
Next 'i
Exit Sub
ErrorHandler:
PostMessage Err.Number
End Sub
法的な注意事項:
本版は、英文テクニカルノートの和訳です。英文原文を正文といたします。
ロックウェル・ソフトウェア(RSI) のサポートライブラリに記載された情報は、いかなる保証もなく「そのままで」提供されます。RSI は、明示または暗示されたいかなる保証も負いません。また、RSI がそのような損害の可能性を忠告していた場合でも、直接、間接、偶発的、必然的な利益の損失または損害を含むいかなる損害についても、RSI は責任を負いません。
©2005 Rockwell Software Inc. All rights reserved.
