Hi at all and thank to anyone that will answer
here is my problem.
i have a function in a 0.025 ms timer implemented in this way
int CVICALLBACK UpdateKollmorgen(int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
static int timer_kollmorgen_occupato = 0;
switch (event) {
case EVENT_TIMER_TICK:
if(timer_kollmorgen_occupato == 0){
timer_kollmorgen_occupato = 1;
gestione_kollmorgen(0);
timer_kollmorgen_occupato = 0;
}
break;
}
return 0;
}
in this function i have a call to a modbus driver that i have write personally and it is this code, with other part that i've cutted
int gestione_kollmorgen(unsigned short int quale_kollmorgen)
{
// gestione errore
unsigned char ReadBuffer[2000] = {0};
int error_number = 0;
char error_title[40] = {0};
char error_string[760] = {0};
static int numero_ciclo[2] = {0};
///////////////////////////////
// eseguo un loop di letture //
///////////////////////////////
error_number = ricevi_kollmorgen(numero_ciclo[quale_kollmorgen], quale_kollmorgen);
// se ho un errore salto al case di pulizia buffer
numero_ciclo[quale_kollmorgen]++;
if (error_number != 0){
goto error;
}
if(numero_ciclo[quale_kollmorgen] >= 5){
numero_ciclo[quale_kollmorgen] = 0;
}
// altrimenti esco
return error_number;
error:
// se ho un errore converto il messaggio, faccio il log e mostro un popup
Modbus_TLGB_TCP_ErrorTranslation(error_number, error_title, error_string);
Modbus_TLGB_TCP_Log_Errori(file_address_log[quale_kollmorgen], error_number, error_title, error_string);
MessagePopup(error_title, error_string);
// eseguo una lettura per svuotare il buffer
SetBreakOnLibraryErrors(0);
ClientTCPRead(g_hconversation[quale_kollmorgen], ReadBuffer, 2000, 5000);
SetBreakOnLibraryErrors(1);
return error_number;
}
this function then call
int ricevi_kollmorgen(int numero_ciclo, int quale_kollmorgen){
int error_number = 0;
switch (numero_ciclo){
// se si aggiunge un case bisogna sistemare anche il ciclo for nella gestione_kollmorgen
case 0: // leggo DRV_ACTIVE e DRV_MOTIONSTAT
error_number = Modbus_TLGB_TCP_ReadHoldingRegister(g_hconversation[quale_kollmorgen], 220, 50, result_sint[quale_kollmorgen]);
if (error_number == 0){
// se va tutto bene converto i risultati
kollmorgen[quale_kollmorgen].DRV_ACTIVE = result_sint[quale_kollmorgen][221];
kollmorgen[quale_kollmorgen].DRV_MOTIONSTAT = convert_2_short_int_to_1_int(result_sint[quale_kollmorgen][268], result_sint[quale_kollmorgen][269]);;
}
break;
case 1:
-----------some code after--------
break;
}
return error_number;
}
and finally my modbus driver where after creating a buffer i read the answer and decode in this way
SetBreakOnLibraryErrors(0);
Status = ClientTCPWrite(ConversationHandle, WriteBuffer, WriteBufferTotalLength, 5000);
SetBreakOnLibraryErrors(1);
if (Status < 0) {
return Status;
}
//////////////////////////////////
// fase di lettura e decodifica //
//////////////////////////////////
SetBreakOnLibraryErrors(0);
while((ReadBufferToBeReadLength > 0) && (Status > 0)){
Status = ClientTCPRead(ConversationHandle, &ReadBuffer[ReadBufferTotalLength - ReadBufferToBeReadLength], ReadBufferToBeReadLength, 5000);
ReadBufferToBeReadLength -= Status;
}
SetBreakOnLibraryErrors(1);
the problem that i have is that when i am in the main page of my software, the one that include the timer, everything work correctly.
when i open a subpage that have a RunUserInterface() the ClientTCPRead() stop answering and the timer freeze and restart when i close the page.
this happen only if i open the page when the software is doing a reading and not if the cicle have finished, i try to explain better.
if i control with the flag
static int timer_kollmorgen_occupato = 0;
if the timer is working or not and then i open the page, if the flag is = 1 so the timer is doing a reading this will stop, if i open the page with the flag at 0 there are no problem and the timer will continue working correctly.
i have done this only to check if i have some disconnection
int CVICALLBACK Modbus_TLGB_TCP_CallBackFunction(unsigned handle, int event, int error, void *Void_Pointer_to_Flag_ConversationHandle)
{
int *Int_Pointer_to_Flag_ConversationHandle;
char file_address_log[260] = {0};
char error_title[40] = {0}, error_string[760] = {0};
switch (event) {
case TCP_DATAREADY:
break;
case TCP_DISCONNECT:
GetDir(file_address_log);
strcat(file_address_log,"\\LOG_MODBUS.txt");
Modbus_TLGB_TCP_ErrorTranslation(-14, error_title, error_string);
MessagePopup(error_title, error_string);
Modbus_TLGB_TCP_Log_Errori(file_address_log, -14, error_title, error_string);
Int_Pointer_to_Flag_ConversationHandle=(int*)Void_Pointer_to_Flag_ConversationHandle;
*Int_Pointer_to_Flag_ConversationHandle = 0;
break;
}
return 0;
}
can somebody help me?