Building EPICS Environment on Windows and Example ... -...

35
Building EPICS Environment on Windows and Example Usage of CA.DLL Takashi OBINA Takashi NOGAMI Photon Factory, KEK

Transcript of Building EPICS Environment on Windows and Example ... -...

Page 1: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

Building EPICS Environment on Windowsand

Example Usage of CA.DLL

Takashi OBINATakashi NOGAMI

Photon Factory, KEK

Page 2: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

Outline

● Time Table● 30min : Talk● 30min : Hands-on

●bulid example Application on Windows● 30min : Demo with Visual Basic

● Table of Contents● CA Client/Server on Windows?● Requirement, Prebuild setup● Getting EPICS source code● Build EPICS base● How to create EPICS application on Windows● How to use CA.DLL from Visual Basic

Page 3: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

TOC

● CA Client/Server on Windows?● Requirement, Prebuild setup● Getting EPICS source code● Build EPICS base● How to create EPICS application on Windows● How to use CA.DLL from Visual Basic

Page 4: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

CA Client/Server on Windows

● CA Client● Advantage

●Rapid application development tool●Debugger

● Disadvantage●Cost?●Stability?

● CA Server● How to control from remote host?● Stability?●Windows update?● Security?

Page 5: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

CA Client/Server on Windows (cont.)

● This is my opinion:● LabView?● I don't want to relay upon 1 Product / 1 Company

●VC?, Version, security, long term stability of PC● If you use 1 PC for control, LabView is a good soluti

on, however ....... If you want to compare the data to another parameters, such as beam charge, beam position, vacuum pressure, etc...

● If you are a good programmer and can do everything by youself, and no need to communicate with other person/groups, there are less reason to adopt EPICS

Page 6: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

TOC

● CA Client/Server on Windows?● Requirement, Prebuild setup● Getting EPICS source code● Build EPICS base● How to create EPICS application on Windows● How to use CA.DLL from Visual Basic

Page 7: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

What is your favorite environment?● cygwin

●Unix like environment, GNU tools●Easy-to-use installation tool is available●X-window emulator included●http://www.cygwin.com/

●Microsoft●Visual C++6.0, Visual C .NET, Visual Studio 2005

●MinGW●Minimalist GNU for Win32●Free GNU C compiler + ●http://www.mingw.org/

● Borland C++●http://www.borland.com/

Page 8: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

Microsoft Visual C++ selection● 3 versions● Visual C++ 6.0 : VC6● Visual C++ .NET : VC7● Visual Studio .NET : VC8

● Default compiler for EPICS : VC7● VC6 / VC8 also works.● VC8 not tested well, however

● Today's talk● Visual Studio .NET "Express Edition"● Download / Install from Microsoft Web site● FREE

● In your PC, "VC6" is already installed

Page 9: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

Environment Setup -- Prebuild(1)● Install "Visual Studio 2005 Express Edition"● Visual C++ 2005 Express Edition● Visual Basic 2005 Express Edition●Windows Platform SDK

● GNU make ● GNU http://www.gnu.org/● cygwin gmake

● perl● CPAN● Active Perl (http://www.activestate.com/)● cygwin perl

It is possible to use cygwin, however, I tried to build EPICS without cygwin environenet today. (Because if you already installed cygwin, you can build EPICS inside cygwin environment. It is relatively easier than VC6.) Today, I build CA.DLL and CA.LIB using MSVC.

Page 10: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

Setup – Prebuild (2)

● Check PATH● perl, make must be included in your PATH.

C:\obina>perl -vThis is perl, v5.8.8 built for MSWin32-x86-multi-thread(with 25 registered patches, see perl -V for more detail)...

C:\obina>make -vGNU Make 3.80Copyright (C) 2002 Free Software Foundation, Inc.This is free software; see the source for copying conditions.There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR APARTICULAR PURPOSE.

Page 11: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

Setup -- Prebuild (3) : Optional

● Directory Structure Example● EPICS --> C:\VECC\base3.14.8.2

● Create .BAT file for VC and EPICS (only for convenience)●%SystemRoot%\system32\cmd.exe /K "C:\vecc\epic

s\DevEnv.bat"set EPICS_HOST_ARCH=win32-x86set EPICS_BASE=C:\VECC\base-3.14.8.2set EPICS_BIN=%EPICS_BASE%\bin\%EPICS_HOST_ARCH%set EPICS_CA_ADDR_LIST=172.xxx.yyy.255set EPICS_CA_AUTO_ADDR_LIST=NOset PATH=%EPICS_BIN%;%PATH%

"%VS80COMNTOOLS%vsvars32.bat"

After the successful build of EPICS:You should set the environment variable (EPICS_CA..., etc) withControl Panel -> System -> Detail -> Environment Variables

Page 12: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

TOC

● CA Client/Server on Windows?● Requirement, Prebuild setup● Getting EPICS source code● Build EPICS base● How to create EPICS application on Windows● How to use CA.DLL from Visual Basic

Page 13: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

Building EPICS base (1)

● Download from http://www.aps.anl.gov/epics/● At first, please read documentation carefully.● Using the "Latest" version is important !!!●Many number of bug fixes are exist in Windows port.● I personally felt that....Linux port was relatively stable

and easy...but now, things are getting better.● Expand to some directory● For example C:\VEEC\base-3.14.8

● Edit : CONFIG_SITE.win32-x86.win32-x86● in %EPICS_BASE%\configure\os

● Edit : CONFIG_SITE, CONFIG_SITE_ENV● in %EPICS_BASE%\configure\

make!

Page 14: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

for VC6

● you must modify some files● I will explain the detail procedure in the last pa

rt of this file...

● please forget for a while.● EPICS base are already build and installed in

your PC.

Page 15: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

EPICS base Build (2)● Check● Binary file, Environment Variables

●EPICS_BASE = C:\pf\epics\base-3.14.8.2cvs●%EPICS_BASE%\bin\win32-x86●%EPICS_BASE%\lib\win32-x86

●%PATH% include "bin" directory?● Execute "excas" in bin directory● example record : jane, fred, freddy, etc● caget● camonitor

● If you've got an error:● security setting (Firewall of Windows, Norton, etc)● You MUST be connected to network● check environment variable

●EPICS_CA_ADDR_LIST●EPICS_CA_AUTO_ADDR_LIST

Page 16: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

Useful command-line Tool (General)● Show network port statistics● netstat -a● netstat -o : Windows XP● netstat -b : WinXP SP2

● tasklist , taskkill : Win XP Pro● Use "grep" on Linux, "findstr" on Windows● Linux: netstat -a | grep 5064●Win: netstat -a | findstr 5064 set | findstr EPICS findstr /i <---- ignore case findstr /s <---- search subdir

● Find a file in sub-directory● example: dir /s makeBase*

● Command line suppliment● Cursor, <F8>, <F7>

Page 17: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

TOC

● CA Client/Server on Windows?● Requirement, Prebuild setup● Getting EPICS source code● Build EPICS base● How to create EPICS application on Windows● How to use CA.DLL from Visual Basic

Page 18: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

EPICS Application

● Create EPICS Application●makeBaseApp.pl

makeBaseApp.pl -h :show helpmakeBaseApp.pl -l : list application types

Example 1makeBaseApp.pl -t example examplemakeBaseApp.pl -i -t example examplemakecd iocBoot\iocexample..\..\bin\win32-x86\example st.cmd

Example 2makeBaseApp.pl -t caClient caexmake

Page 19: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

EPICS Application (2)● Execute "example.exe st.cmd" (prev. page)● Open a new cmd window● test caget/caput● caget fooHost:aiExample● camonitor fooHost:aiExample● caput fooHost:xxxExample

● In order to create command-line program, use "makeBaseApp.pl" and check the source code is easy way.

● To create GUI, IDE of Visual C is possible● Visual Basic / Delphi / C++ Builder is also OK

Page 20: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

Hands-on 1

● Open a command window● Check environmentC:\> cd \C:\> set | moreC:\> set | findstr /i epicsC:\> make -vC:\> perl -vC:\> cl

Page 21: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

Hands-on 2● Create an Example Application

C:\> cd \C:\> mkdir group1 <--- replace by your groupnameC:\> cd group1C:\group1> makeBaseApp.pl -t example myexampleC:\group1> makeBaseApp.pl -i -t example myexampleC:\group1> make..... wait for a while .....C:\group1> cd iocBoot\iocmyexampleC:\group1\iocBoot\iocmyexample> notepad st.cmd..... edit "st.cmd" ..... dbLoadRecords("db/dbExample1.db","user=lenovoHost")dbLoadRecords("db/dbExample1.db","user=group1")C:\group1\**\> ..\..\bin\win32-x86\example.exe st.cmd..... open another cmd window, try caget, camonitor

replace

Page 22: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

TOC

● CA Client/Server on Windows?● Requirement, Prebuild setup● Getting EPICS source code● Build EPICS base● How to create EPICS application on Windows● How to use CA.DLL from Visual Basic

Page 23: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

How to use CA.DLL

● Dynamic-Link Library (DLL)●Microsoft's implementation of the shared library conc

ept in the Microsoft Windows operating systems● In Linux or other UNIX-like operating systems, .so o

r .sl file extensions are used

● Demo: caClient by Visual Basic● Procedure● create an interface file● design form (place Button, Label, Timer, etc)● assign event● execute● add some functionalities ?

Page 24: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

Interface file for CA.DLL / Com.DLL

● EXCUSE: not full-functional.....● Convenient Tool : "dependency walker"● Interface file "modCA.vb"

Public Declare Function ca_array_get : Declare "ca_array_get" Lib "ca.dll" : in "CA.DLLt"Alias "_ca_array_get@16" : exported as _ca_array.... (ByVal chtype As Integer, ByVal count As Integer, ByVal chanId As Integer, : To check file type, args, ByRef pValue As Any) As Integer : please read "cadef.h"

"As Any" is NOT allowed in Visual Studio 2005

Example ( written in 1 line in the program )

Page 25: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

CA client example : Visual Basic 2005

● Example : caget

● This example is not good! Only an example.● Please use CA monitor for REAL application....

Page 26: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

CA client in C

● caExample.c (simplified)● Please refer to "How to write CA client" doc.● makeBaseApp.pl -t caClient clientex#include "cadef.h"int main(int argc,char **argv){ double data; chid mychid;

ca_context_create(ca_disable_preemptive_callback); ca_create_channel("recname",NULL,NULL,10,&mychid); ca_pend_io(5.0);

ca_get(DBR_DOUBLE,mychid,(void *)&data); ca_pend_io(5.0);

printf("%s %f\n",argv[1],data); return(0);}

Page 27: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

CA client example : Visual Basic 2005

● Execute IDE● Create New Project -> Windows Application● Create New Form● Place Button, Labe, Timer

● Add "modCA.vb" in the project● Assign Event● Form1_Loadstatus = ca_context_create(ca_preemptive_callback_select.ca_disable_preemptive_callback)status = ca_create_channel("recn", 0, 0, CA_PRIORITY_DEFAULT, pCh)status = ca_pend_io(5.0)● Timer1_Tickstatus = ca_array_get(DBR_DOUBLE, 1, pCh, recval)status = ca_pend_io(5.0)lblValue.Text = Format(recval, "f")● Form1_FormClosingstatus = ca_clear_channel(pCh)Call ca_context_destroy()

Page 28: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

Need more?

● Add Sound in the application (catest4.exe)● Use Win32API● winmm.dll● PlaySound (ASYNC mode)● please refer to MSDN document

● StripTool (catest5.exe)

Page 29: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

Application

● Voice Message● It is possible to use Microsoft API

● LabVIEW / Matlab● ActiveX, LabCA, etc● Please ask to Tech-talk

● Scripting languate : Python, Perl, etc● you can use CA.DLL, COM.DLL

Page 30: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

But please think....

● If IOC is disconnected....

●MEDM --> PVs on the panel went to BLANK● you should write this feture in your application

● I must emphasize again:● Polling is not a good method● use CA monitor!!!!

Page 31: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

Comment on VC6

● You many need to modify some source codes or setting files for now.

● These error will be fixed in the future release of EPICS base.

● Some of them are already fixed in CVS repository.

● C:\VECC\base-3.14.8.2\configure\RULES_BUILD● C:\VECC\base-3.14.8.2\src\gdd\dbMapper.cc● C:\VECC\base-3.14.8.2\src\makeBaseApp\makeBaseApp.pl● C:\VECC\base-3.14.8.2\src\catools\camonitor.c

● For detail, please refer to the following pages

Page 32: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

VC6C:\VECC\base-3.14.8.2\configure\RULES_BUILD● in perl script, * does not interpreted correctlly.

before correctionifdef WIN32ifdef BORLAND

@$(INSTALL_PRODUCT) -d -m 555 $< $(INSTALL_BIN)else

@$(INSTALL_PRODUCT) -d -m 555 $<* $(INSTALL_BIN)endifendifafter correctionifdef WIN32ifdef BORLAND

@$(INSTALL_PRODUCT) -d -m 555 $<* $(INSTALL_BIN)else

@$(INSTALL_PRODUCT) -d -m 555 $< $(INSTALL_BIN)endifendif

Page 33: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

VC6

● C:\VECC\base-3.14.8.2\src\gdd\dbMapper.cc

line 1138before correction

for ( int i = db->no_str; i < MAX_ENUM_STATES; i++ ) {db->strs[i][0] = '\0';

}

after correction{for ( int i = db->no_str; i < MAX_ENUM_STATES; i++ ) {

db->strs[i][0] = '\0'; }

}

Page 34: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

VC6● C:\VECC\base-3.14.8.2\src\makeBaseApp\makeBaseApp.plbefore correctionsub UnixPath { my ($newpath) = @_; if ($^O eq "cygwin") {

$newpath =~ s|\\|/|go;$newpath =~ s%^([a-zA-Z]):/%/cygdrive/$1/%;

} elsif ($^O eq 'sunos') {$newpath =~ s(^\/tmp_mnt/)(/);

} return $newpath;}

after correctionsub UnixPath { my ($newpath) = @_; if ($^O eq "cygwin") {

$newpath =~ s|\\|/|go;$newpath =~ s%^([a-zA-Z]):/%/cygdrive/$1/%;

} elsif ($^O eq 'MSWin32') {$newpath =~ s|\\|/|go;

} elsif ($^O eq 'sunos') {$newpath =~ s(^\/tmp_mnt/)(/);

} return $newpath;

Page 35: Building EPICS Environment on Windows and Example ... - KEKahfb1.kek.jp/epics/slides/epics-win-obina.pdf · CA Client/Server on Windows (cont.) This is my opinion: LabView? I don't

VC6

● C:\VECC\base-3.14.8.2\src\catools\camonitor.c

before correction setvbuf(stdout,NULL,_IOLBF,BUFSIZ);

/* Set stdout to line buffering */

after correctioncomment this lineor#define BUFSIZ 2