Trang chủ Liên hệ

Cách sử dụng ODBC trong Cimon-SCADA

CÔNG TY TNHH THIẾT BỊ ĐO LƯỜNG VÀ ĐIỀU KHIỂN 21/06/2023

Cách sử dụng ODBC trong Cimon-SCADA?

Q: How to use CIMON-SCADA ODBC?

A: Insert, Search, Update and Delete are available with CIMON-SCADA ODBC function through Microsoft Access.

[Instruction]

In order to use ODBC function, click [Microsoft Office]  [Microsoft Access 2010] as following.
+ Write ‘myDM.mdb’ at File Name

+ Click [Table1]  [Design View] and write ‘Table1’ at Table Name.

+ Then write the Field Name and Data Type as below picture.
+ Field Name : im_ID, im_name, im_major
+ Data Type : Text
+ Change the Field Properties only with im_ID as following:
Required : No  Yes
Allow Zero Length : Yes  No
+ Field Properties of im_name and im_major are default (You do not need to change them)

+ Double click ‘Table1’ and then write the ID, name and major as below picture.

+ Click ‘Save’ and close Access 2010

Since you already made Database with Access 2010, it is time to set up ODBC at Windows.
+ Click [Start]  [Control Panel] and then click [Administrative Tools]

+ Click [Data Sources (ODBC)] and then click [Add] to register Database you made.

+ Since Database is made by Access 2010, select Microsoft Access Driver(*.mdb) and then click [Finish]

+ Click [Select] and find out the Directories you saved myDB.mdb.
+ If you see the first picture, there is Directories C:\ Users\ Marketing\ Documents\
+ Write ‘myDB’ at [Data Source Name] and then click ‘OK

Open CimonD and register tags and set up ODBC
+ Register 4tags as below
Name : ID, IDSEARCH, NAME and MAJOR
Type : String

+ Click [Tools]  [ODBC]
+ Click [New DBMS] icon and write ‘myDB’ at [DB Name] and click ‘OK

+ Click [New Query] icon and set up as below:
Query Name : SelectQ
Query Type : SELECT Statement
How to Run Query : Run By Command Function
+ Click “Create SQL”

+ Click [New Field] and register 3 Field Name and following:

Field Name: im_ID
Tag Name: ID
Data Type: VARCHAR
Field Name: im_name
Tag Name: NAME
Data Type: VARCHAR
Field Name: im_major
Tag Name: MAJOR
Data Type: VARCHAR

+ Write “Table1” at [FROM] and “im_ID=’[IDSEARCH]’” at [WHERE]

+ If you click “OK”, you can see the “SelectQ” at [Query Name]

+ Click [New Query] icon and set up as below:
Query Name : InsertQ
Query Type : Others
How to Run Query : Run By Command Function
+ Click “Create SQL”

+ Click [New Field] and register 3 Field Name and following:

Tag Name: ID
Data Type: VARCHAR
Tag Name: NAME
Data Type: VARCHAR
Tag Name: MAJOR
Data Type: VARCHAR

+ Write “Insert Into Table1(im_ID, im_name, im_major) Values(‘[1]’, ‘[2]’, ‘[3]’)” and then click “OK”

+ Click [New Query] icon and set up as below:

Query Name : UpdateQ
Query Type : Others
How to Run Query : Run By Command Function

+ Click “Create SQL”

+ Click [New Field] and register 3 Field Name and following:

Tag Name: ID
Data Type: VARCHAR
Tag Name: NAME
Data Type: VARCHAR
Tag Name: MAJOR
Data Type: VARCHAR

+ Write “Update Table1 Set im_name=’[2]’, im_major=’[3]’, Where im_ID=’[1]’” at SQL and
then click “OK

+ Click [New Query] icon and set up as below:

Query Name : DeleteQ
Query Type : Others
How to Run Query : Run By Command Function

+ Click “Create SQL”

+ Click [New Field] and register a Field Name and following:

Tag Name: ID
Data Type: VARCHAR

+ Write “Delete From Table1 Where im_ID=’[1]’” at SQL and then click “OK

After ODBC setting, create Script to run Select, Insert, Update and Delete function.

+ Click [Tools]  [Script] and make 4 scripts as following:

Select Script;

Sub SelectS()
CSqlOpen(“SelectQ”)
CSqlClose(“SelectQ”)
End Sub

Insert Script;

Sub InsertS()
CSqlRun “InsertQ”
End Sub

Update Script;

Sub UpdateS()
CSqlRun “UpdateQ”
End Sub

Delete Script;

Sub DeleteS()
CSqlRun “DeleteQ”
End Sub

In order to test ODBC, make a page as below:

+ Make 3 dynamic tags : ID, name and major (red box)

Config: EntryData
Action: Text

+ Make 1 dynamic tag : IDSEARCH (yellow box)

Config: EntryData
Action: Tex

+Make 4 texts and rectangle objects : Insert, Update, Delete and Select

Config: Touch
Action: Command Expression
Command Down: RunScript(“InsertS”)

RunScript(“UpdateS”)
RunScript(“DeleteS”)
RunScript(“SelectS”)

+ Save the page and run CimonX with DS license key lock.
+ If you double click dynamic tag and write ID and click “Select”, you can see the its
database information.

+ If you double click dynamic tag and write ID, name and major and then click “Insert”, you can see the new database is inserted in Access 2010 as below picture.

You can test other functions like Update and Delete with the same method.

Download

Bài viết liên quan