Building EPICS Environment on Windowsand
Example Usage of CA.DLL
Takashi OBINATakashi NOGAMI
Photon Factory, KEK
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
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
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?
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
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
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/
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
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.
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.
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
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
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!
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.
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
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>
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
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
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
Hands-on 1
● Open a command window● Check environmentC:\> cd \C:\> set | moreC:\> set | findstr /i epicsC:\> make -vC:\> perl -vC:\> cl
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
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
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 ?
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 )
CA client example : Visual Basic 2005
● Example : caget
● This example is not good! Only an example.● Please use CA monitor for REAL application....
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);}
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()
Need more?
● Add Sound in the application (catest4.exe)● Use Win32API● winmm.dll● PlaySound (ASYNC mode)● please refer to MSDN document
● StripTool (catest5.exe)
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
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!!!!
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
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
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'; }
}
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;
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