06-01-2017 08:04 AM - edited 06-01-2017 08:07 AM
Hello Mr Roberto ,
i try your structure and it work thank you so much for your help also i pass -1 in the in OutputQueueSize parameter
this my function i think i have a problem with the buffer always show the same value any suggestions please
//PSA_MODE char* PSA_MODE (int Port_CAN ,char* RES) { unsigned char target[20]={0}; char msg[512]; char msg1[512]; char msg2[512]; //1 FlushInQ(Port_CAN); FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x03); ComWrtByte(Port_CAN,0x2D); ComWrtByte(Port_CAN,0xF3); //2 FlushInQ(Port_CAN); FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x0E); ComWrtByte(Port_CAN,0x22); ComWrtByte(Port_CAN,0x07); ComWrtByte(Port_CAN,0x65); ComWrtByte(Port_CAN,0x08); ComWrtByte(Port_CAN,0x02); ComWrtByte(Port_CAN,0x10); ComWrtByte(Port_CAN,0x03); ComWrtByte(Port_CAN,0xFF); ComWrtByte(Port_CAN,0xFF); ComWrtByte(Port_CAN,0xFF); ComWrtByte(Port_CAN,0xFF); ComWrtByte(Port_CAN,0xFF); ComWrtByte(Port_CAN,0x75); //3 FlushInQ(Port_CAN); FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x03); ComWrtByte(Port_CAN,0x2C); ComWrtByte(Port_CAN,0xF2); ComRd(Port_CAN,Reponse,20); memcpy(target,Reponse,7); strcpy (msg, "String ="); for (i = 0; i <7;i++) { sprintf (msg, "%s 0x%X", msg, target[i]); } strcat (msg, "\n"); printf(msg); if(Reponse[3]==0x47) { printf ("PASSED_1 \n "); Delay(1); } else { printf ( "NOT_PASSED_1 \n "); } //3' FlushInQ(Port_CAN); FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x03); ComWrtByte(Port_CAN,0x2C); ComWrtByte(Port_CAN,0xF2); ComRd(Port_CAN,Reponse,20); memcpy(target,Reponse,7); strcpy (msg1,"String ="); for (i = 0; i <7;i++) { sprintf (msg1,"%s 0x%X", msg1,target[i]); } strcat (msg1,"\n"); printf(msg1); if(Reponse[3]==0x47) { printf ("PASSED_1' \n "); Delay(1); } else { printf ( "NOT_PASSED_1' \n "); } //4 FlushInQ(Port_CAN); FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x03); ComWrtByte(Port_CAN,0x24); ComWrtByte(Port_CAN,0xFA); ComRd(Port_CAN,Reponse,20); ; memcpy(target,Reponse,11); strcpy (msg2,"String ="); for (i = 0; i <11;i++) { sprintf (msg2,"%s 0x%X", msg2,target[i]); } strcat (msg2,"\n"); strcpy(RES ,msg2); printf(msg2); if(Reponse[3]==0x40) { printf ("PASSED_2 \n "); Delay(1); } else { printf ( "NOT_PASSED_2 \n "); ; } return RES ; }
06-02-2017 06:02 AM
Of course you receive only the last formatted string! A function can return only one value and the way your code is written RES string is overwritten each time.
You could modify your function to receive three independent strings and format the output message in one or the other. The caller must use the three strings as input/output parameters.
06-02-2017 06:24 AM
i need the function to return only the last frame readed
i do strcpy (RES,msg) only with the last one the others just msg to show them to verify
this is the function i need only to explore the last frame readed
06-05-2017 08:40 AM
A few hints to help you debug this situation.
These are only common-sense suggestions, as I don't know the device you are speaking to. Communications with external devices is not always a simple task as it involves two independent devices to sync together.
06-06-2017 09:48 AM
Thank you for your help
i trying to communicate with an PSA automobile display using CAN box AXIA and USB/ RS232 adapter
- yes Reponse it's a global variable and it''s overwritten in every functions
- i delete memcpy and i'm manipulate the 'Reponse' directly
- the device respond immediatly and i'm not using any delay between write and read
my problem start from the PSA_MODE function all the previous functions work so well
this the whole code and the functions that i'm trying to developp and the last result that i get
CAN : Paramétrage Port : 1 CAN : Paramétrage Baud : 9600 CAN : Paramétrage Parity : 2 CAN : Paramétrage StopBits : 1 CAN : Paramétrage DataBits : 8 CAN : Paramétrage Vitesse : 125 CAN : Init Vitesse Can1 CAN :->88 55 06 21 C3 3A FA F9 CAN :<-88 55 03 41 9F :OK CAN : Init Nouvelle vitesse RS CAN :->88 55 05 20 F4 01 0D CAN :<-88 55 03 46 98 :OK CAN : Test Liaison Serie CAN :->88 55 03 2B F5 CAN :<-88 55 03 46 98 :OK CAN : Init Registre CAN :->88 55 05 23 FF FF FB CAN : RAZ Buffer Reception Can CAN :->88 55 03 2D F3 CAN : temps entre 2 octets sur le lien serie est à 200 ms CAN :->88 55 04 2E 14 E3 CAN : Demande Stop Acquitement Message Can CAN :->88 55 03 29 F7 Wake up Commandes BSI ON CAN : Envoi Data Frame Periodique 2.A CAN :->88 55 10 3B 00 36 08 00 00 00 0F 01 00 00 A0 01 0A 6D Wake up Donnees BSI Lentes ON CAN : Envoi Data Frame Periodique 2.A CAN :->88 55 10 3B 00 F6 08 08 00 00 00 00 00 00 00 02 32 30 Wake up BSI_INF_PROFILS ON CAN : Envoi Data Frame Periodique 2.A CAN :->88 55 0D 3B 02 60 05 80 04 00 00 00 03 32 39 Wake up DONNEES_BSI_LENTES_3 ON CAN : Envoi Data Frame Periodique 2.A CAN :->88 55 0D 3B 02 76 05 89 0B 1E 10 0F 04 64 79 Mask2A (0665..0765) CAN Véhicule CAN :->88 55 05 23 00 CC 37 PSA MODE RAZ Buffer Reception Can CAN :->88 55 03 2D F3 CAN : Envoi DIAG ON CAN Frame 2.A CAN :->88 55 0E 22 07 65 08 02 10 03 FF FF FF FF FF 75 CAN : Demande Nb Message Can CAN :->88 55 03 2C F2 CAN6 :<-88 55 05 47 00 00 9F :OK CAN : Demande Nb Message Can CAN :->88 55 03 2C F2 CAN6 :<-88 55 05 47 00 01 9E :OK CAN : Demande Message Can CAN :->88 55 03 24 FA CAN6 :<-88 55 09 40 06 65 03 02 50 03 A5 :OK CAN -> N° message Can1 CAN :<-025003A5 : OK UNLOCKK 11 OCTET RAZ Buffer Reception Can CAN :->88 55 03 2D F3 CAN : Envoi DIAG ON CAN Frame 2.A CAN :->88 55 0E 22 07 65 08 10 0A 27 61 4E 4F 45 54 D7 CAN : Demande Nb Message Can CAN :->88 55 03 2C F2 CAN6 :<-88 55 05 47 00 01 9E :OK CAN : Demande Message Can CAN :->88 55 03 24 FA CAN6 :<-88 55 09 40 06 65 03 30 00 0A CE :OK CAN -> N° message Can1 CAN : Envoi DIAG ON CAN Frame 2.A CAN :->88 55 0E 22 07 65 08 21 53 49 56 00 00 00 00 F6 CAN : Demande Nb Message Can CAN :->88 55 03 2C F2 CAN6 :<-88 55 05 47 00 00 9F :OK CAN : Demande Nb Message Can CAN :->88 55 03 2C F2 CAN6 :<-88 55 05 47 00 01 9E :OK CAN : Demande Message Can CAN :->88 55 03 24 FA CAN6 :<-88 55 09 40 06 65 03 02 67 61 F0 :OK CAN -> N° message Can1 CAN :<-026761F0 : OK Enter diag mode RAZ Buffer Reception Can CAN :->88 55 03 2D F3 CAN : Envoi DIAG ON CAN Frame 2.A CAN :->88 55 0E 22 07 65 08 02 10 60 FF FF FF FF FF 16 CAN : Demande Nb Message Can CAN :->88 55 03 2C F2 CAN6 :<-88 55 05 47 00 00 9F :OK CAN : Demande Nb Message Can CAN :->88 55 03 2C F2 CAN6 :<-88 55 05 47 00 01 9E :OK CAN : Demande Message Can CAN :->88 55 03 24 FA CAN6 :<-88 55 09 40 06 65 03 02 50 60 C6 :OK CAN -> N° message Can1 CAN :<-025060C6 : OK
#include "stdtst.h" #include "tsutil.h" //============================================================================== // // Title: BX_1008_TEST_CASE // Purpose: A short description of the application. // // Copyright: VISTEON. All Rights Reserved. // //============================================================================== //============================================================================== // Include files #include <rs232.h> #include "toolbox.h" #include <utility.h> #include <formatio.h> #include <ansi_c.h> #include <cvirte.h> #include "toolbox.h" //============================================================================== // Constants //============================================================================== // Types //============================================================================== // Static global variables int TD=0, CW=0, error=0, wT; int Port_CAN=6; char Reponse[20], CH[50]; char DEVICE[5]="COM6";; char ADR[4],ADR1[4]="0",CMD[40],AFF[40]; int i=0, j=0; //============================================================================== // Static functions //============================================================================== // Global variables //***************************************************************************************/ //***************************************************************************************/ //***************************** MAIN MENU *********************************************/ /// HIFN The main entry-point function. int main (int argc, char *argv[]) { return 0; } //***************************** END MAIN MENU *****************************************/ //***************************************************************************************/ //***************************************************************************************/ //============================================================================== // UI callback function prototypes /****************************************************************************/ /****************************************************************************/ /******** INIT CAN Callback **************/ char* init_can (int Port_CAN) { unsigned char target[20]={0}; char msg[512] ; int state=0; strcpy(DEVICE,"COM6"); //TD=OpenComConfig(Port_CAN,DEVICE,57600, 2, 8, 1, 0, 0); //COM pour la passerelle CAN TD=OpenComConfig(Port_CAN,DEVICE,9600, 2, 8, 1, 0,0); if(TD != 0) { printf ("port not open\n" ); goto END; } FlushInQ(Port_CAN); FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x06); ComWrtByte(Port_CAN,0x21); ComWrtByte(Port_CAN,0xC3); ComWrtByte(Port_CAN,0x3A); ComWrtByte(Port_CAN,0xFA); ComWrtByte(Port_CAN,0xF9); ComRd(Port_CAN,Reponse,20); memcpy(target,Reponse,5); strcpy (msg, "String ="); for (i = 0; i <5;i++) { sprintf (msg, "%s 0x%X", msg, target[i]); } strcat (msg, "\n"); printf(msg); // strcpy (RES,msg); if(Reponse[3]==0x41) { printf (" INIT VITESSE CAN SUCCESS\n "); state++; Delay(1); } else { printf ( " ERROR CAN INIT VITESSE\n "); CloseCom(Port_CAN); goto END; } FlushInQ(Port_CAN); FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x05); ComWrtByte(Port_CAN,0x20); ComWrtByte(Port_CAN,0xFE); ComWrtByte(Port_CAN,0x01); ComWrtByte(Port_CAN,0x07); ComRd(Port_CAN,Reponse,5); if(Reponse[3]==0x46) { printf (" SYNCHRO RS232 SUCCESS\n "); state++; Delay(1); } else { printf ( " ERROR CAN SYNCHRO RS232\n "); CloseCom(Port_CAN); goto END; } CloseCom(Port_CAN); OpenComConfig(Port_CAN, DEVICE, 57600, 2, 8, 1, 0, 0); // COM pour la passerelle CAN 115200 FlushInQ(Port_CAN); FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x03); ComWrtByte(Port_CAN,0x2B); ComWrtByte(Port_CAN,0xF5); ComRd(Port_CAN,Reponse,5); if(Reponse[3]==0x46) { printf (" TEST RS232 SUCCESS\n "); state++; Delay(1); } else { printf ( " ERROR CAN TEST RS232\n "); CloseCom(Port_CAN); goto END; } // INIT REGISTER FlushInQ(Port_CAN); FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x05); ComWrtByte(Port_CAN,0x23); ComWrtByte(Port_CAN,0xFF); ComWrtByte(Port_CAN,0xFF); ComWrtByte(Port_CAN,0xFB); // RESET Can Reception Buffer FlushInQ(Port_CAN); FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x03); ComWrtByte(Port_CAN,0x2D); ComWrtByte(Port_CAN,0xF3); //Time maxi beetween 2 char is 200 ms ( on RS232 link) FlushInQ(Port_CAN); FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x04); ComWrtByte(Port_CAN,0x2E); ComWrtByte(Port_CAN,0x14); ComWrtByte(Port_CAN,0xE3); // Can Message not acknowledge request FlushInQ(Port_CAN); FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x03); ComWrtByte(Port_CAN,0x29); ComWrtByte(Port_CAN,0xF7); if(state==3) { printf (" CAN INIT SUCCESS...PLEASE PRESS BSI ON\n"); } else { printf ( "ERROR CAN INIT\n"); } END: return msg ; } /******** Display ON screen Callback **************/ int Wake_up_Commandes_BSI_ON (int Port_CAN) { //CloseCom(Port_CAN); //OpenComConfig(Port_CAN, DEVICE, 57600, 2, 8, 1, 0, 0); */ // COM pour la passerelle CAN 115200 FlushInQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x10); ComWrtByte(Port_CAN,0x3B); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x36); ComWrtByte(Port_CAN,0x08); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x0F); ComWrtByte(Port_CAN,0x01); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x01); ComWrtByte(Port_CAN,0x0A); ComWrtByte(Port_CAN,0x6D); return 1; } int Wake_up_Donnees_BSI_Lentes_ON (int Port_CAN) { //Wake up Donnees BSI Lentes ON FlushInQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x10); ComWrtByte(Port_CAN,0x3B); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0xF6); ComWrtByte(Port_CAN,0x08); ComWrtByte(Port_CAN,0x08); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x02); ComWrtByte(Port_CAN,0x32); ComWrtByte(Port_CAN,0x30); Delay(1); //printf ("GOOD BSI ON "); return 2; } int Wake_up_BSI_INF_PROFILS_ON (int Port_CAN) { //Wake up BSI_INF_PROFILS ON FlushInQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x10); ComWrtByte(Port_CAN,0x0D); ComWrtByte(Port_CAN,0x3B); ComWrtByte(Port_CAN,0x02); ComWrtByte(Port_CAN,0x60); ComWrtByte(Port_CAN,0x05); ComWrtByte(Port_CAN,0x80); ComWrtByte(Port_CAN,0x04); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x03); ComWrtByte(Port_CAN,0x32); ComWrtByte(Port_CAN,0x39); Delay(1); return 3; } int Wake_up_DONNEES_BSI_LENTES_3_ON (int Port_CAN) { //Wake up DONNEES_BSI_LENTES_3 ON FlushInQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x0D); ComWrtByte(Port_CAN,0x3B); ComWrtByte(Port_CAN,0x02); ComWrtByte(Port_CAN,0x76); ComWrtByte(Port_CAN,0x05); ComWrtByte(Port_CAN,0x89); ComWrtByte(Port_CAN,0x0B); ComWrtByte(Port_CAN,0x1E); ComWrtByte(Port_CAN,0x10); ComWrtByte(Port_CAN,0x0F); ComWrtByte(Port_CAN,0x04); ComWrtByte(Port_CAN,0x64); ComWrtByte(Port_CAN,0x79); Delay(1); return 4; } int Wake_up_Commandes_BSI_OFF (int Port_CAN) { //CloseCom(Port_CAN); //OpenComConfig(Port_CAN, DEVICE, 57600, 2, 8, 1, 0, 0); */ // COM pour la passerelle CAN 115200 FlushInQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x10); ComWrtByte(Port_CAN,0x3B); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x36); ComWrtByte(Port_CAN,0x08); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x01); ComWrtByte(Port_CAN,0x0A); ComWrtByte(Port_CAN,0xC3); return 5; } int Wake_up_Donnees_BSI_Lentes_OFF (int Port_CAN) { //Wake up Donnees BSI Lentes OFF FlushInQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x10); ComWrtByte(Port_CAN,0x3B); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0xF6); ComWrtByte(Port_CAN,0x08); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x02); ComWrtByte(Port_CAN,0x32); ComWrtByte(Port_CAN,0x38); Delay(1); //printf ("GOOD BSI ON "); return 6; } int Wake_up_BSI_INF_PROFILS_OFF (int Port_CAN) { //Wake up BSI_INF_PROFILS OFF FlushInQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x0D); ComWrtByte(Port_CAN,0x3B); ComWrtByte(Port_CAN,0x02); ComWrtByte(Port_CAN,0x60); ComWrtByte(Port_CAN,0x05); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x03); ComWrtByte(Port_CAN,0x32); ComWrtByte(Port_CAN,0xBD); Delay(1); return 7; } int Wake_up_DONNEES_BSI_LENTES_3_OFF (int Port_CAN) { //Wake up DONNEES_BSI_LENTES_3 OFF FlushInQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x0D); ComWrtByte(Port_CAN,0x3B); ComWrtByte(Port_CAN,0x02); ComWrtByte(Port_CAN,0x76); ComWrtByte(Port_CAN,0x05); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x04); ComWrtByte(Port_CAN,0x64); ComWrtByte(Port_CAN,0xFA); Delay(1); return 8; } int Commandes_BSI (int Port_CAN) { //Commandes BSI FlushInQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x10); ComWrtByte(Port_CAN,0x3B); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x36); ComWrtByte(Port_CAN,0x08); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x0F); ComWrtByte(Port_CAN,0x01); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x01); ComWrtByte(Port_CAN,0x0A); ComWrtByte(Port_CAN,0xCC); Delay(1); return 9; } int Mask2A_CAN_Vehicule (int Port_CAN) { //Mask2A FlushInQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x05); ComWrtByte(Port_CAN,0x23); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0xCC); ComWrtByte(Port_CAN,0x37); Delay(1); return 9; } //PSA_MODE int PSA_MODE(int Port_CAN ) { // unsigned char target[20]={0}; char msg[512]; // //1 FlushInQ(Port_CAN); //FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x03); ComWrtByte(Port_CAN,0x2D); ComWrtByte(Port_CAN,0xF3); //2 FlushInQ(Port_CAN); //FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x0E); ComWrtByte(Port_CAN,0x22); ComWrtByte(Port_CAN,0x07); ComWrtByte(Port_CAN,0x65); ComWrtByte(Port_CAN,0x08); ComWrtByte(Port_CAN,0x02); ComWrtByte(Port_CAN,0x10); ComWrtByte(Port_CAN,0x03); ComWrtByte(Port_CAN,0xFF); ComWrtByte(Port_CAN,0xFF); ComWrtByte(Port_CAN,0xFF); ComWrtByte(Port_CAN,0xFF); ComWrtByte(Port_CAN,0xFF); ComWrtByte(Port_CAN,0x75); //3 FlushInQ(Port_CAN); // FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x03); ComWrtByte(Port_CAN,0x2C); ComWrtByte(Port_CAN,0xF2); ComRd(Port_CAN,Reponse,7); strcpy (msg, "String ="); for (i = 0; i <7;i++) { sprintf (msg,"%s 0x%X", msg,Reponse[i]); } strcat (msg,"\n"); printf(msg); if(Reponse[3]==0x47) { printf ("PASSED_1 \n "); Delay(1); } else { printf ( "NOT_PASSED_1 \n "); } //4 FlushInQ(Port_CAN); //FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x03); ComWrtByte(Port_CAN,0x24); ComWrtByte(Port_CAN,0xFA); ComRd(Port_CAN,Reponse,11); ; strcpy (msg, "String ="); for (i = 0; i <11;i++) { sprintf (msg, "%s 0x%X", msg, Reponse[i]); } strcat (msg, "\n"); printf(msg); if(Reponse[3]==0x40 ) { printf ("PASSED_2 \n "); Delay(1); } else { printf ( "NOT_PASSED_2 \n "); ; } return 0; } // UNLOCKK_11_OCTET int UNLOCKK_11_OCTET (int Port_CAN ) { // unsigned char target[20]={0}; char msg[512]; //1 FlushInQ(Port_CAN); // FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x03); ComWrtByte(Port_CAN,0x2D); ComWrtByte(Port_CAN,0xF3); //2 FlushInQ(Port_CAN); // FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x0E); ComWrtByte(Port_CAN,0x22); ComWrtByte(Port_CAN,0x07); ComWrtByte(Port_CAN,0x65); ComWrtByte(Port_CAN,0x08); ComWrtByte(Port_CAN,0x10); ComWrtByte(Port_CAN,0x0A); ComWrtByte(Port_CAN,0x27); ComWrtByte(Port_CAN,0x61); ComWrtByte(Port_CAN,0x4E); ComWrtByte(Port_CAN,0x4F); ComWrtByte(Port_CAN,0x45); ComWrtByte(Port_CAN,0x54); ComWrtByte(Port_CAN,0xD7); //3 FlushInQ(Port_CAN); // FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x03); ComWrtByte(Port_CAN,0x2C); ComWrtByte(Port_CAN,0xF2); ComRd(Port_CAN,Reponse,7); strcpy (msg, "String ="); for (i = 0; i <7;i++) { sprintf (msg,"%s 0x%X", msg,Reponse[i]); } strcat (msg,"\n"); printf(msg); if(Reponse[3]==0x47) { printf ("PASSED_3 \n "); Delay(1); } else { printf ( "NOT_PASSED_3 \n "); } //4 FlushInQ(Port_CAN); // FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x03); ComWrtByte(Port_CAN,0x24); ComWrtByte(Port_CAN,0xFA); ComRd(Port_CAN,Reponse,11); strcpy (msg, "String ="); for (i = 0; i <11;i++) { sprintf (msg,"%s 0x%X", msg,Reponse[i]); } strcat (msg,"\n"); printf(msg); if(Reponse[3]==0x40) { printf ("PASSED_4 \n "); Delay(1); } else { printf ( "NOT_PASSED_4 \n "); } //5 FlushInQ(Port_CAN); // FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x0E); ComWrtByte(Port_CAN,0x22); ComWrtByte(Port_CAN,0x07); ComWrtByte(Port_CAN,0x65); ComWrtByte(Port_CAN,0x08); ComWrtByte(Port_CAN,0x21); ComWrtByte(Port_CAN,0x53); ComWrtByte(Port_CAN,0x49); ComWrtByte(Port_CAN,0x56); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0x00); ComWrtByte(Port_CAN,0xF6); //6 FlushInQ(Port_CAN); //FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x03); ComWrtByte(Port_CAN,0x2C); ComWrtByte(Port_CAN,0xF2); ComRd(Port_CAN,Reponse,7); strcpy (msg, "String ="); for (i = 0; i <7;i++) { sprintf (msg, "%s 0x%X", msg, Reponse[i]); } strcat (msg, "\n"); printf(msg); if(Reponse[3]==0x47) { printf ("PASSED_6 \n "); Delay(1); } else { printf ( "NOT_PASSED_6 \n "); } //7 FlushInQ(Port_CAN); // FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x03); ComWrtByte(Port_CAN,0x2C); ComWrtByte(Port_CAN,0xF2); ComRd(Port_CAN,Reponse,7); strcpy (msg, "String ="); for (i = 0; i <7;i++) { sprintf (msg, "%s 0x%X", msg, Reponse[i]); } strcat (msg, "\n"); printf(msg); if(Reponse[3]==0x47) { printf ("PASSED_7 \n "); Delay(1); } else { printf ( "NOT_PASSED_7 \n "); } //8 FlushInQ(Port_CAN); // FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x03); ComWrtByte(Port_CAN,0x24); ComWrtByte(Port_CAN,0xFA); ComRd(Port_CAN,Reponse,11); strcpy (msg, "String ="); for (i = 0; i <11;i++) { sprintf (msg, "%s 0x%X", msg, Reponse[i]); } strcat (msg, "\n"); printf(msg); if(Reponse[3]==0x40) { printf ("PASSED_8 \n "); Delay(1); } else { printf ( "NOT_PASSED_8 \n "); } return 0; } //Entrer_Mode_Diag int Entrer_Mode_Diag (int Port_CAN ) { // unsigned char target[20]={0}; char msg[512]; //1 FlushInQ(Port_CAN); // FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x03); ComWrtByte(Port_CAN,0x2D); ComWrtByte(Port_CAN,0xF3); //2 FlushInQ(Port_CAN); // FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x0E); ComWrtByte(Port_CAN,0x22); ComWrtByte(Port_CAN,0x07); ComWrtByte(Port_CAN,0x65); ComWrtByte(Port_CAN,0x08); ComWrtByte(Port_CAN,0x02); ComWrtByte(Port_CAN,0x10); ComWrtByte(Port_CAN,0x60); ComWrtByte(Port_CAN,0xFF); ComWrtByte(Port_CAN,0xFF); ComWrtByte(Port_CAN,0xFF); ComWrtByte(Port_CAN,0xFF); ComWrtByte(Port_CAN,0xFF); ComWrtByte(Port_CAN,0x16); //3 FlushInQ(Port_CAN); //FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x03); ComWrtByte(Port_CAN,0x2C); ComWrtByte(Port_CAN,0xF2); ComRd(Port_CAN,Reponse,7); strcpy (msg, "String ="); for (i = 0; i <7;i++) { sprintf (msg, "%s 0x%X", msg,Reponse[i]); } strcat (msg, "\n"); printf(msg); if(Reponse[3]==0x47) { printf ("PASSED_9 \n "); Delay(1); } else { printf ( "NOT_PASSED_9 \n "); } //4 FlushInQ(Port_CAN); // FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x03); ComWrtByte(Port_CAN,0x2C); ComWrtByte(Port_CAN,0xF2); ComRd(Port_CAN,Reponse,7); strcpy (msg, "String ="); for (i = 0; i <7;i++) { sprintf (msg, "%s 0x%X", msg, Reponse[i]); } strcat (msg, "\n"); printf(msg); if(Reponse[3]==0x47) { printf ("PASSED_10 \n "); Delay(1); } else { printf ( "NOT_PASSED_10 \n "); } //5 FlushInQ(Port_CAN); // FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x03); ComWrtByte(Port_CAN,0x24); ComWrtByte(Port_CAN,0xFA); ComRd(Port_CAN,Reponse,11); strcpy (msg, "String ="); for (i = 0; i <11;i++) { sprintf (msg, "%s 0x%X", msg, Reponse[i]); } strcat (msg, "\n"); printf(msg); if(Reponse[3]==0x40) { printf ("PASSED_11 \n "); Delay(1); } else { printf ( "NOT_PASSED_11 \n "); } return 0; };
06-07-2017 12:31 AM
Ahmed,
I see little of my suggestions in that code and this last PSA_MODE function does not even return a string so please keep calm, revise this entire discussion, implement all suggestions and try again!
With this I mean:
Finally, do not publish all the code! You are wasting forum resources with plenty of unnecessary code and screenshots that really add nothing to the discussion.
06-07-2017 07:30 PM
Hello Mr Roberto
thank you for your help
i implement all the suggestions , this structure work with previous functions like init can, i don't have any problem with communication my problem is i can't get the right received response especially when i send this frame i receive null bytes and when i delete memset (Reponse, 0, 20); i receive the same previous response
CAN :->88 55 03 24 FA
CAN6 :<-88 55 09 40 06 65 03 02 50 03 A5 :OK
as you can see in the capture result iget the right response in previous sended frame
this my try any suggestions please
char* PSA_MODE (int Port_CAN , char*RES) { unsigned char target[20]={0}; char msg[512]; //1 FlushInQ(Port_CAN); FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x03); ComWrtByte(Port_CAN,0x2D); ComWrtByte(Port_CAN,0xF3); //2 FlushInQ(Port_CAN); FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x0E); ComWrtByte(Port_CAN,0x22); ComWrtByte(Port_CAN,0x07); ComWrtByte(Port_CAN,0x65); ComWrtByte(Port_CAN,0x08); ComWrtByte(Port_CAN,0x02); ComWrtByte(Port_CAN,0x10); ComWrtByte(Port_CAN,0x03); ComWrtByte(Port_CAN,0xFF); ComWrtByte(Port_CAN,0xFF); ComWrtByte(Port_CAN,0xFF); ComWrtByte(Port_CAN,0xFF); ComWrtByte(Port_CAN,0xFF); ComWrtByte(Port_CAN,0x75); //3 FlushInQ(Port_CAN); FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x03); ComWrtByte(Port_CAN,0x2C); ComWrtByte(Port_CAN,0xF2); memset (Reponse, 0, 20); ComRd(Port_CAN,Reponse,7); memcpy(target,Reponse,7); strcpy (msg, ""); for (i = 0; i <7;i++) { sprintf (msg, "%s 0x%X", msg, target[i]); } strcat (msg, "\n"); printf(msg); if(Reponse[3]==0x47) { printf ("PASSED_1 \n "); Delay(1); } else { printf ( "NOT_PASSED_1 \n "); } //4 FlushInQ(Port_CAN); FlushOutQ(Port_CAN); ComWrtByte(Port_CAN,0x88); ComWrtByte(Port_CAN,0x55); ComWrtByte(Port_CAN,0x03); ComWrtByte(Port_CAN,0x24); ComWrtByte(Port_CAN,0xFA); memset (Reponse, 0, 20); ComRd(Port_CAN,Reponse,11); ; memcpy(target,Reponse,11); strcpy (msg, ""); for (i = 0; i <11;i++) { sprintf (msg, "%s 0x%X", msg, target[i]); } strcat (msg, "\n"); strcpy(RES,msg); printf(msg); if(Reponse[3]==0x40) { printf ("PASSED_2 \n "); Delay(1); } else { printf ( "NOT_PASSED_2 \n "); ; } return RES; }
06-08-2017 02:46 AM
Apparently your device does no respond or returns a string of NULLs, which seems strange to me. I cannot comment on this as I don't know what the device is expected to respond and within which time.
But you are still missing to check the result of ComRd! Go and check it before continuing to argue on the code: you cannot be sure of what's happening as far as you don't check it!
06-08-2017 04:52 AM
this what the device is expected to respond CAN6 :<-88 55 09 40 06 65 03 02 50 03 A5
and it respond immediately i verify this with other development environment from where i get these frames
i cannot check ComRd with breakpoint i get error always
how can i check response in CVI not in Labview after i build the dll like i do ?
06-08-2017 05:17 AM - edited 06-08-2017 05:17 AM
ahmedkochbati92 ha scritto:
i cannot check ComRd with breakpoint i get error always
Which error? Do I have to guess it out of my gazing ball?
And without thinking to breakpoints, why not saving the result to a variable and printf-ing it on output?