diff -r c23daa6996c2 -r 22e65b8e20f4 targets/Win32/plc_Win32_main.c --- a/targets/Win32/plc_Win32_main.c Tue Mar 24 17:33:46 2009 +0100 +++ b/targets/Win32/plc_Win32_main.c Mon Mar 30 17:04:30 2009 +0200 @@ -1,6 +1,6 @@ /** * Win32 specific code - **/ + **/ #include #include @@ -19,7 +19,7 @@ void PLC_GetTime(IEC_TIME *CURRENT_TIME) { _ftime(&timetmp); - + (*CURRENT_TIME).tv_sec = timetmp.time; (*CURRENT_TIME).tv_nsec = timetmp.millitm * 1000000; } @@ -36,11 +36,11 @@ LARGE_INTEGER liDueTime; /* arg 2 of SetWaitableTimer take 100 ns interval*/ liDueTime.QuadPart = next / (-100); - + /* printf("SetTimer(%lld,%lld)\n",next, period); */ - + if (!SetWaitableTimer(PLC_timer, &liDueTime, common_ticktime__, NULL, NULL, 0)) { printf("SetWaitableTimer failed (%d)\n", GetLastError()); @@ -66,9 +66,9 @@ HANDLE PLC_thread; HANDLE debug_sem; -HANDLE debug_wait_sem; +HANDLE debug_wait_sem; HANDLE python_sem; -HANDLE python_wait_sem; +HANDLE python_wait_sem; #define maxval(a,b) ((a>b)?a:b) int startPLC(int argc,char **argv) @@ -77,54 +77,54 @@ /* Translate PLC's microseconds to Ttick nanoseconds */ Ttick = 1000000 * maxval(common_ticktime__,1); - debug_sem = CreateSemaphore( + debug_sem = CreateSemaphore( NULL, // default security attributes 1, // initial count 1, // maximum count NULL); // unnamed semaphore - if (debug_sem == NULL) + if (debug_sem == NULL) { printf("startPLC CreateSemaphore debug_sem error: %d\n", GetLastError()); return; } - - debug_wait_sem = CreateSemaphore( + + debug_wait_sem = CreateSemaphore( NULL, // default security attributes 0, // initial count 1, // maximum count NULL); // unnamed semaphore - if (debug_wait_sem == NULL) + if (debug_wait_sem == NULL) { printf("startPLC CreateSemaphore debug_wait_sem error: %d\n", GetLastError()); return; } - python_sem = CreateSemaphore( + python_sem = CreateSemaphore( NULL, // default security attributes 1, // initial count 1, // maximum count NULL); // unnamed semaphore - if (python_sem == NULL) + if (python_sem == NULL) { printf("startPLC CreateSemaphore python_sem error: %d\n", GetLastError()); return; } - python_wait_sem = CreateSemaphore( + python_wait_sem = CreateSemaphore( NULL, // default security attributes 0, // initial count 1, // maximum count NULL); // unnamed semaphore - if (python_wait_sem == NULL) + if (python_wait_sem == NULL) { printf("startPLC CreateSemaphore python_wait_sem error: %d\n", GetLastError()); return; } - + /* Create a waitable timer */ PLC_timer = CreateWaitableTimer(NULL, FALSE, "WaitableTimer"); if(NULL == PLC_timer) @@ -172,10 +172,10 @@ /* from plc_debugger.c */ int WaitDebugData() { - WaitForSingleObject(debug_wait_sem, INFINITE); + if(WaitForSingleObject(debug_wait_sem, INFINITE) != WAIT_OBJECT_0) return -1; return __debug_tick; } - + /* Called by PLC thread when debug_publish finished * This is supposed to unlock debugger thread in WaitDebugData*/ void InitiateDebugTransfer() @@ -190,7 +190,7 @@ { __DEBUG = 0; /* Prevent PLC to enter debug code */ - WaitForSingleObject(debug_sem, INFINITE); + WaitForSingleObject(debug_sem, INFINITE); } void resumeDebug() @@ -204,9 +204,9 @@ int WaitPythonCommands(void) { /* Wait signal from PLC thread */ - WaitForSingleObject(python_wait_sem, INFINITE); -} - + return WaitForSingleObject(python_wait_sem, INFINITE); +} + /* Called by PLC thread on each new python command*/ void UnBlockPythonCommands(void) {