? chris.patch5 ? chris3.patch ? hal/.tm_project.cache ? hal/classicladder.prj ? hal/classicladder.pws ? hal/hal.prj ? hal/hal.pws Index: hal/classicladder/arrays.c =================================================================== RCS file: /cvs/emc2/src/hal/classicladder/arrays.c,v retrieving revision 1.8.2.1 diff -u -r1.8.2.1 arrays.c --- hal/classicladder/arrays.c 21 Jan 2007 19:10:39 -0000 1.8.2.1 +++ hal/classicladder/arrays.c 24 May 2007 04:58:44 -0000 @@ -126,7 +126,10 @@ .nbr_phys_outputs = NBR_PHYS_OUTPUTS_DEF, .nbr_arithm_expr = NBR_ARITHM_EXPR_DEF, .nbr_sections = NBR_SECTIONS_DEF, - .nbr_symbols = NBR_SYMBOLS_DEF + .nbr_symbols = NBR_SYMBOLS_DEF, + .nbr_refresh = NBR_REFRESH_DEF, + .nbr_s32in = NBR_S32IN_DEF, + .nbr_s32out = NBR_S32OUT_DEF }; #endif @@ -154,8 +157,7 @@ #ifdef RTAPI pSizesInfos = &sinfo; // Calculate SHMEM size. - numBits = - pSizesInfos->nbr_bits + pSizesInfos->nbr_phys_inputs + + numBits = pSizesInfos->nbr_bits + pSizesInfos->nbr_phys_inputs + pSizesInfos->nbr_phys_outputs; numWords = pSizesInfos->nbr_words; #ifdef SEQUENTIAL_SUPPORT @@ -174,6 +176,7 @@ #endif bytes += numWords * sizeof(int); bytes += numBits * sizeof(TYPE_FOR_BOOL_VAR); + bytes += 1 * sizeof(int); // am guessing for numRefresh variable cm #endif // Attach SHMEM with proper size. if ((ShmemId = rtapi_shmem_new(CL_SHMEM_KEY, compId, bytes)) < 0) { @@ -225,7 +228,7 @@ InfosGene->CurrentSection = 0; #endif - rtapi_print("Sizes: %d %d %d %d %d %d %d %d %d %d %d\n", + rtapi_print("Sizes: rungs- %d bits- %d words- %d timers- %d mono- %d count- %d \n HAL Bin- %d HAL Bout- %d expressions- %d sections- %d symbols - %d\n refresh- %d s32in - %d s32out- %d\n", pSizesInfos->nbr_rungs, pSizesInfos->nbr_bits, pSizesInfos->nbr_words, @@ -236,7 +239,10 @@ pSizesInfos->nbr_phys_outputs, pSizesInfos->nbr_arithm_expr, pSizesInfos->nbr_sections, - pSizesInfos->nbr_symbols); + pSizesInfos->nbr_symbols, + pSizesInfos->nbr_refresh, + pSizesInfos->nbr_s32in, + pSizesInfos->nbr_s32out); // Set global SHMEM pointers. pByte = (unsigned char *) InfosGene; @@ -468,7 +474,6 @@ InitIOConf( ); InfosGene->AskConfirmationToQuit = FALSE; InfosGene->DisplaySymbols = TRUE; - return TRUE; } @@ -555,4 +560,4 @@ DisplaySymbols( ); } #endif -} +} Index: hal/classicladder/classicladder.c =================================================================== RCS file: /cvs/emc2/src/hal/classicladder/classicladder.c,v retrieving revision 1.8.2.2 diff -u -r1.8.2.2 classicladder.c --- hal/classicladder/classicladder.c 20 Feb 2007 01:45:46 -0000 1.8.2.2 +++ hal/classicladder/classicladder.c 24 May 2007 04:58:45 -0000 @@ -67,10 +67,7 @@ #if !defined( MODULE ) && !defined( RTAPI ) -#ifdef __WIN32__ -HANDLE ThreadHandleCyclicRefresh = NULL; -DWORD ThreadIdCyclicRefresh; -#else + pthread_t thread_cyclic_refresh; #endif int CyclicThreadRunning = 0; @@ -78,12 +75,8 @@ void HandlerSignalInterrupt( int signal_id ) { printf("End of application asked\n"); -#ifdef HAL_SUPPORT +// HAL_SUPPORT hal_exit(compId); -#else - CloseSocketModbusMaster( ); - CloseSocketServer( ); -#endif ClassicLadderFreeAll(); exit( 0 ); } @@ -102,21 +95,23 @@ "-c file --config=file read PLC configuration from file\n" #endif ); + hal_exit(compId); exit(0); } void display_version (void) { - printf("ClassicLadder v" RELEASE_VER_STRING "\n" RELEASE_DATE_STRING "\n" - "\n" - "Copyright (C) 2001-2004 Marc Le Douarain\nmavati@club-internet.fr\n" - "\n" + printf("\nClassicLadder v" RELEASE_VER_STRING "\n" RELEASE_DATE_STRING "\n" + "Copyright (C) 2001-2004 Marc Le Douarain\nmavati@club-internet.fr\n" + "Adapted to EMC\n" + "\n" "ClassicLadder comes with NO WARRANTY\n" "to the extent permitted by law.\n" "\n" "You may redistribute copies of ClassicLadder\n" "under the terms of the GNU Lesser General Public Licence.\n" "See the file `lesserGPL.txt' for more information.\n"); + hal_exit(compId); exit(0); } @@ -140,9 +135,7 @@ int c = getopt_long(argc, argv, short_options, long_options, &option_index); - if (c == EOF) { - break; - } + if (c == EOF) {break;} switch (c) { case 0: @@ -156,13 +149,12 @@ } break; case 'c': -#ifndef RT_SUPPORT - read_config (optarg); -#else - printf("Config file is used by the RT module in RTLinux version !!!\n"); -#endif + + printf("Config file is not used in EMC.\n Configure info is specified when loading the classicladder RT module only!\n"); + hal_exit(compId); + exit(0); break; - case 'n': + case 'n': nogui = 1; break; case 'p': @@ -181,199 +173,85 @@ VerifyDirectorySelected (argv[optind]); } -#ifndef HAL_SUPPORT -void DoPauseMilliSecs( int Time ) -{ -#ifdef __WIN32__ - Sleep( Time ); -#else - struct timespec time; - time.tv_sec = 0; - time.tv_nsec = Time*1000000; - nanosleep( &time, NULL ); - //usleep( Time*1000 ); -#endif -} - -void CyclicCalcRefresh( void ) -{ -#ifdef __XENO__ - struct timespec start, period, now; - unsigned long overruns; - int err = 0; - pthread_set_name_np( pthread_self(), __FUNCTION__ ); - clock_gettime( CLOCK_REALTIME, &start ); - start.tv_sec += 1; /* Start in one second from now. */ - period.tv_sec = 0; - period.tv_nsec = TIME_REFRESH_RUNG_MS*1000000; - if ( pthread_make_periodic_np(pthread_self(), &start, &period)!=0 ) - { - printf("Xenomai make_periodic failed: err %d\n", err); - exit(EXIT_FAILURE); - } -#endif - while( CyclicThreadRunning ) - { -#ifdef __XENO__ - err = pthread_wait_np(&overruns); - if (err || overruns) { - printf( "Xenomai wait_period failed: err %d, overruns: %lu\n", err, overruns); -// exit(EXIT_FAILURE); - } -#else - DoPauseMilliSecs( TIME_REFRESH_RUNG_MS ); -#endif - - if (InfosGene->LadderState==STATE_RUN) - { -#ifdef __XENO__ - clock_gettime( CLOCK_REALTIME, &start ); -#endif - ReadPhysicalInputs(); - RefreshAllRungs(); - WritePhysicalOutputs(); - -#ifdef __XENO__ - clock_gettime( CLOCK_REALTIME, &now ); - if ( now.tv_sec==start.tv_sec ) - InfosGene->DurationOfLastScan = now.tv_nsec-start.tv_nsec; -#endif - } - } -#ifndef __WIN32__ - pthread_exit(NULL); -#endif -} - -int InitCyclicThread( void ) -{ - int InitOk = 0; - int Error; - CyclicThreadRunning = 1; -#ifdef __WIN32__ - ThreadHandleCyclicRefresh = CreateThread( NULL/*no security attributes*/, 16*1024L/*default stack size*/, - (LPTHREAD_START_ROUTINE)CyclicCalcRefresh/* thread function*/, - NULL/*argument to thread function*/, - THREAD_QUERY_INFORMATION/*use default creation flags*/, - &ThreadIdCyclicRefresh/* returns the thread identifier*/); - if ( ThreadHandleCyclicRefresh==NULL ) -#else - pthread_attr_t ThreadAttributes; - pthread_attr_init(&ThreadAttributes); - pthread_attr_setdetachstate(&ThreadAttributes, PTHREAD_CREATE_DETACHED /*PTHREAD_CREATE_JOINABLE*/); -#ifdef __XENO__ - pthread_attr_setschedpolicy(&ThreadAttributes, SCHED_FIFO); - struct sched_param paramA = { .sched_priority = 98 }; - pthread_attr_setschedparam(&ThreadAttributes, ¶mA); -#endif - pthread_attr_setstacksize(&ThreadAttributes, 32*1024); - Error = pthread_create( &thread_cyclic_refresh, &ThreadAttributes, (void *(*)(void *))CyclicCalcRefresh, (void *)NULL ); - if (Error==-1) -#endif - printf("Failed to create cyclic calc thread...\n"); - else - InitOk = 1; - return InitOk; -} -#endif - -#ifdef HAL_SUPPORT +// HAL_SUPPORT static void do_exit(int unused) { hal_exit(compId); + printf("Error inticalising classicladder user module"); _exit(0); } -#endif + int main( int argc, char *argv[] ) { -#ifdef __XENO__ - mlockall(MCL_CURRENT | MCL_FUTURE); -#endif + int used=0, NumRung; -#if defined(HAL_SUPPORT) && defined(ULAPI) - compId = hal_init("classicladder"); +//HAL_SUPPORT + + compId = hal_init("classicladder"); if(compId < 0) return -1; signal(SIGTERM, do_exit); - hal_ready(compId); -#endif - -#ifdef USE_MODBUS - InitModbusMasterBeforeReadConf( ); -#endif + process_options (argc, argv); if (ClassicLadderAllocAll()) { - if ( nogui ) { - InitAllLadderDatas( TRUE ); - InitTempDir( ); - LoadProjectFiles( LadderDirectory ); - InfosGene->LadderState = STATE_RUN; - ClassicLadderFreeAll(); - hal_exit(compId); - return 0; - } -#if !defined(HAL_SUPPORT) - InitAllLadderDatas( TRUE ); - InitSocketServer( 0/*UseUdpMode*/, ModbusServerPort/*PortNbr*/ ); - InitSocketModbusMaster( ); -#endif + if ( nogui ) + { + printf("**** NO GUI! ****\n"); + InitAllLadderDatas( TRUE ); + InitTempDir( ); + LoadProjectFiles( LadderDirectory ); +// start the ladder program + InfosGene->LadderState = STATE_RUN; +// Let HAL know we are ready now + hal_ready(compId); + printf("Ladder project loaded\n"); + hal_exit(compId); + return 0; + } + + + else{ +//check for used rungs +// check for previous program loaded + printf("checking for used rungs\n"); + for(NumRung=0;NumRungLadderState = STATE_RUN; - +// start running ladder program + InfosGene->LadderState = STATE_RUN; +//let HAL know we are ready... + hal_ready(compId); + #ifdef GTK_INTERFACE - //ProblemWithPrint gdk_threads_enter( ); +//ProblemWithPrint gdk_threads_enter( ); + printf("Loading GUI\n"); gtk_main(); - //ProblemWithPrint gdk_threads_leave( ); -#else - signal( SIGINT /*SIGTERM*/, HandlerSignalInterrupt ); - printf("Running...\n"); - for( ;; ) - sleep( 1 ); -#endif - CyclicThreadRunning = 0; -#ifdef __WIN32__ - if ( ThreadHandleCyclicRefresh ) - TerminateThread( ThreadHandleCyclicRefresh, 0); -#endif - } - } - else - { - ClassicLadderFreeAll(); + printf("GUI closed realtime module still runs till HAL closes\n"); +//ProblemWithPrint gdk_threads_leave( ); + } } - + else { ClassicLadderFreeAll();} + hal_exit(compId); - return 0; } -#endif +#endif Index: hal/classicladder/classicladder.h =================================================================== RCS file: /cvs/emc2/src/hal/classicladder/classicladder.h,v retrieving revision 1.4 diff -u -r1.4 classicladder.h --- hal/classicladder/classicladder.h 16 Nov 2006 01:45:33 -0000 1.4 +++ hal/classicladder/classicladder.h 24 May 2007 04:58:45 -0000 @@ -41,6 +41,9 @@ #define NBR_ARITHM_EXPR_DEF 100 #define NBR_SECTIONS_DEF 10 #define NBR_SYMBOLS_DEF 100 +#define NBR_REFRESH_DEF 50 +#define NBR_S32IN_DEF 0 +#define NBR_S32OUT_DEF 0 #define NBR_INPUTS_CONF 5 #define NBR_OUTPUTS_CONF 5 @@ -58,7 +61,10 @@ int nbr_arithm_expr; int nbr_sections; int nbr_symbols; -}plc_sizeinfo_s; + int nbr_refresh; //number of ms between refresh of rungs + int nbr_s32in; //number of HAL signed inputs + int nbr_s32out; // number of HAL signed outputs + }plc_sizeinfo_s; #define NBR_RUNGS InfosGene->SizesInfos.nbr_rungs #define NBR_BITS InfosGene->SizesInfos.nbr_bits @@ -71,7 +77,10 @@ #define NBR_ARITHM_EXPR InfosGene->SizesInfos.nbr_arithm_expr #define NBR_SECTIONS InfosGene->SizesInfos.nbr_sections #define NBR_SYMBOLS InfosGene->SizesInfos.nbr_symbols - +#define NBR_REFRESH InfosGene->SizesInfos.nbr_refresh //add cm +#define NBR_S32IN InfosGene->SizesInfos.nbr_s32in +#define NBR_S32OUT InfosGene->SizesInfos.nbr_s32out + #else /* static size */ #define NBR_RUNGS NBR_RUNGS_DEF @@ -85,6 +94,10 @@ #define NBR_ARITHM_EXPR NBR_ARITHM_EXPR_DEF #define NBR_SECTIONS NBR_SECTIONS_DEF #define NBR_SYMBOLS NBR_SYMBOLS_DEF +#define NBR_REFRESH NBR_REFRESH_DEF +#define NBR_S32IN NBR_S32IN_DEF +#define NBR_S32OUT NBR_S32OUT_DEF + #endif #define ARITHM_EXPR_SIZE 32 @@ -95,7 +108,7 @@ #define TYPE_FOR_BOOL_VAR char #endif -#define TIME_REFRESH_RUNG_MS 100 +#define TIME_REFRESH_RUNG_MS 100 #define TIME_BASE_MINS 60000 #define TIME_BASE_SECS 1000 #define TIME_BASE_100MS 100 @@ -379,4 +392,4 @@ #include "hal.h" extern int compId; #endif -extern int nogui; +extern int nogui; Index: hal/classicladder/classicladder_gtk.c =================================================================== RCS file: /cvs/emc2/src/hal/classicladder/classicladder_gtk.c,v retrieving revision 1.16.2.3 diff -u -r1.16.2.3 classicladder_gtk.c --- hal/classicladder/classicladder_gtk.c 14 Mar 2007 23:47:28 -0000 1.16.2.3 +++ hal/classicladder/classicladder_gtk.c 24 May 2007 04:58:45 -0000 @@ -33,9 +33,9 @@ #include "classicladder_gtk.h" // #include "hardware.h" -#define NBR_BOOLS_VAR_SPY 15 -#define NBR_TYPE_BOOLS_SPY 3 -#define NBR_FREE_VAR_SPY 5 +#define NBR_BOOLS_VAR_SPY 15 //for bit variable list (15 in each column) +#define NBR_TYPE_BOOLS_SPY 3 // for 3 columns +#define NBR_FREE_VAR_SPY 10 //for word variable list (10 variables) GdkPixmap *pixmap = NULL; GtkWidget *drawing_area = NULL; @@ -43,7 +43,8 @@ int ValOffsetBoolVar[ NBR_TYPE_BOOLS_SPY ] = { 0, 0, 0 }; GtkWidget *chkvar[ NBR_TYPE_BOOLS_SPY ][ NBR_BOOLS_VAR_SPY ]; GtkWidget *EntryVarSpy[NBR_FREE_VAR_SPY*2]; -int VarSpy[NBR_FREE_VAR_SPY][2] = { {VAR_MEM_WORD,0}, {VAR_MEM_WORD,1}, {VAR_MEM_WORD,2}, {VAR_MEM_WORD,3}, {VAR_MEM_WORD,4} }; /* defaults vars to spy */ +int VarSpy[NBR_FREE_VAR_SPY][2] = { {VAR_MEM_WORD,0}, {VAR_MEM_WORD,1}, {VAR_MEM_WORD,2}, {VAR_MEM_WORD,3}, {VAR_MEM_WORD,4}, {VAR_MEM_WORD,5}, {VAR_MEM_WORD,6}, {VAR_MEM_WORD,7}, {VAR_MEM_WORD,8},{VAR_MEM_WORD,9 } }; /* defaults vars to spy */ +static int VarWindowToggle; // toggle display of vars window variable GtkWidget *DisplayFormatVarSpy[NBR_FREE_VAR_SPY]; GtkWidget *entrylabel,*entrycomment; GtkWidget *CheckDispSymbols; @@ -58,7 +59,8 @@ GtkWidget *FileSelector; GtkWidget *ConfirmDialog; GtkWidget *RungWindow; - +GtkWidget *windowvars; +GtkWidget *windowvars2; #include "drawing.h" #include "vars_access.h" #include "calc.h" @@ -395,7 +397,18 @@ gtk_widget_set_sensitive(entrycomment, TRUE); } } - +void ButtonRefresh_click() +{ + if (InfosGene->SizesInfos.nbr_refresh <=10) + { + InfosGene->SizesInfos.nbr_refresh=100; + } + else + { + InfosGene->SizesInfos.nbr_refresh-=10; + } + } + void ButtonRunStop_click() { if (InfosGene->LadderState==STATE_RUN) @@ -610,11 +623,20 @@ GtkWidget *dialog, *label, *okay_button; /* Create the widgets */ dialog = gtk_dialog_new(); - label = gtk_label_new ("ClassicLadder v" RELEASE_VER_STRING "\n" RELEASE_DATE_STRING "\n" + label = gtk_label_new (" Classicladder v" RELEASE_VER_STRING "\n" RELEASE_DATE_STRING "\n" + "EMC2 Development of Classicladder\n" "Copyright (C) 2001-2006 Marc Le Douarain\nmarc . le - douarain /At\\ laposte \\DoT/ net\n" "http://www.sourceforge.net/projects/classicladder\n" "http://www.multimania.com/mavati/classicladder\n" - "Released under the terms of the\nGNU Lesser General Public License v2.1"); + "Released under the terms of the\nGNU Lesser General Public License v2.1\n" + "Updates:\n" + " ***New to this update ***\n" + "-compare/equate works properly, accepts symbols\n" + "-Two variable windows, toggle button to show/hide\n" + "-HAL s32 IN and OUT equipt words \n" + "-refresh rate button, rate is variable\n" + "-symbols checkbox in section display controls variable window also\n" + "number of HAL s32 IN / OUT pins and rate of rung refresh configurable when loading classicladder RT module\n" ); gtk_label_set_justify( GTK_LABEL(label), GTK_JUSTIFY_CENTER ); okay_button = gtk_button_new_with_label("Okay"); /* Ensure that the dialog box is destroyed when the user clicks ok. */ @@ -688,8 +710,8 @@ } void DoQuit( void ) -{ - gtk_widget_destroy( RungWindow ); +{ + gtk_widget_destroy( RungWindow ); //sends signal 'destroy' to end the GUI } void ConfirmQuit( void ) { @@ -700,8 +722,8 @@ } gint RungWindowDeleteEvent( GtkWidget * widget, GdkEvent * event, gpointer data ) { - ConfirmQuit( ); - // we do not want that the window be destroyed. + ConfirmQuit( ); //If confirm quit returns then + // we do not want the window to be destroyed. return TRUE; } void OpenEditWindow( void ) @@ -712,13 +734,14 @@ #endif } + void RungWindowInitGtk() { GtkWidget *vbox,*hboxtop,*hboxbottom,*hboxbottom2; GtkWidget *hboxmiddle; GtkWidget *ButtonQuit; GtkWidget *ButtonNew,*ButtonLoad,*ButtonSave,*ButtonSaveAs,*ButtonReset,*ButtonConfig,*ButtonAbout; - GtkWidget *ButtonEdit,*ButtonSymbols; + GtkWidget *ButtonEdit,*ButtonSymbols,*ButtonVars,*ButtonRefresh; #ifdef GNOME_PRINT_USE GtkWidget *ButtonPrint,*ButtonPrintPreview; #endif @@ -837,7 +860,12 @@ gtk_signal_connect(GTK_OBJECT (ButtonReset), "clicked", (GtkSignalFunc) ButtonReset_click, 0); gtk_widget_show (ButtonReset); - ButtonRunStop = gtk_button_new_with_label ("Stop"); + ButtonRefresh= gtk_button_new_with_label ("Refresh"); + gtk_box_pack_start (GTK_BOX (hboxbottom), ButtonRefresh, TRUE, TRUE, 0); + gtk_signal_connect(GTK_OBJECT (ButtonRefresh), "clicked", + (GtkSignalFunc) ButtonRefresh_click, 0); + gtk_widget_show (ButtonRefresh); + ButtonRunStop = gtk_button_new_with_label ("Stop"); gtk_box_pack_start (GTK_BOX (hboxbottom), ButtonRunStop, TRUE, TRUE, 0); gtk_signal_connect(GTK_OBJECT (ButtonRunStop), "clicked", (GtkSignalFunc) ButtonRunStop_click, 0); @@ -853,7 +881,12 @@ gtk_signal_connect(GTK_OBJECT (ButtonSymbols), "clicked", (GtkSignalFunc) OpenSymbolsWindow, 0); gtk_widget_show (ButtonSymbols); - ButtonConfig = gtk_button_new_with_label ("Config"); + ButtonVars = gtk_button_new_with_label ("Vars"); // add button to open vars list + gtk_box_pack_start (GTK_BOX (hboxbottom2), ButtonVars, TRUE, TRUE, 0); + gtk_signal_connect(GTK_OBJECT (ButtonVars), "clicked", + (GtkSignalFunc) OpenVarsWindow, 0); + gtk_widget_show (ButtonVars); + ButtonConfig = gtk_button_new_with_label ("Config"); gtk_box_pack_start (GTK_BOX (hboxbottom2), ButtonConfig, TRUE, TRUE, 0); gtk_signal_connect(GTK_OBJECT (ButtonConfig), "clicked", (GtkSignalFunc) ButtonConfig_click, 0); @@ -909,31 +942,34 @@ } gint VarsWindowDeleteEvent( GtkWidget * widget, GdkEvent * event, gpointer data ) -{ - // we do not want that the window be destroyed. +{ + VarWindowToggle=(VarWindowToggle-1)*-1; //toggle the windowtoggle variable + gtk_widget_hide (windowvars2); + gtk_widget_hide (windowvars); + // we can not destroy return TRUE; } void VarsWindowInitGtk() { - GtkWidget *windowvars; + //GtkWidget *windowvars; // used for bit variables + //GtkWidget *windowvars2; // used for word variable list GtkWidget *vboxboolvars[ NBR_TYPE_BOOLS_SPY ],*vboxmain,*hboxvars,*hboxvars2; - GtkWidget * hboxfreevars[ NBR_FREE_VAR_SPY ]; + GtkWidget *hboxfreevars[ NBR_FREE_VAR_SPY ],*vboxmain2;//added cm int NumCheckWidget,ColumnVar,NumVarSpy,NumEntry; GList *DisplayFormatItems = NULL; - + windowvars = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_title ((GtkWindow *)windowvars, "Vars"); + gtk_window_set_title ((GtkWindow *)windowvars, "Bit Vars"); + vboxmain = gtk_vbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (windowvars), vboxmain); gtk_widget_show (vboxmain); + hboxvars = gtk_hbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (vboxmain), hboxvars); gtk_widget_show (hboxvars); - hboxvars2 = gtk_hbox_new (FALSE, 0); - gtk_container_add (GTK_CONTAINER (vboxmain), hboxvars2); - gtk_widget_show (hboxvars2); - + for( ColumnVar=0; ColumnVar