artag Posted March 10, 2011 Share Posted March 10, 2011 I need to execute a named subprog from a background C program. It seems that I need to translate the name into the program number before I can do this, and the function ConvertSymbolicToPMACExp() will do this for me. However, it returns the result "100000\nInvalidResponse:". The 100000 is the value I need : can I safely ignore the 'InvalidResponse' or does it signify something important ? I would prefer to have the IDE convert the name for me at compile time rather than perform the lookup, but I can only find variable name translations (in pp_proj.h), not prog and subprog names. Is there a way to do this ? -adrian Link to comment Share on other sites More sharing options...
Sina.Sattari Posted March 11, 2011 Share Posted March 11, 2011 Adrian, How exactly do you want to call the subprogram? My understanding is that subprograms can only be called from other programs/PLCs and can't be called directly. Can you explain a bit more so I can duplicate the situation and figure out where the "InvalidRespose" is coming from? Thanks, Link to comment Share on other sites More sharing options...
artag Posted March 11, 2011 Author Share Posted March 11, 2011 Adrian, How exactly do you want to call the subprogram? My understanding is that subprograms can only be called from other programs/PLCs and can't be called directly. Can you explain a bit more so I can duplicate the situation and figure out where the "InvalidRespose" is coming from? Thanks, Calling is probably an inaccurate term : maybe I should have said invoking or launching. I'm actually calling the function GetResponse with the string "cx ldata.coord=1; call 100000;" . However, that part works OK - it's the assumption that the program created by name in the IDE has the numeric label 100000 that I want to avoid. (I tried using the name in the string above but that wasn't successful). So I'm using ConvertSymbolicToPMACExp to first obtain the numeric label from the name given in the 'open subprog' statement. Again, it seems to work but I get that additional response. -adrian Link to comment Share on other sites More sharing options...
bradp Posted March 14, 2011 Share Posted March 14, 2011 Adrian, I am not getting this error. I made something quick as follows and I get no errors. What is different from your system? int main(void) { char cmd[255], resp[255]; int error; InitLibrary(); pshm->P[101]++; // sprintf(cmd, "&1 b1 r"); //no error // sprintf(cmd, "&1 cpx call Test02"); //error // sprintf(cmd, "&1 cpx call 100001"); //no error // sprintf(cmd, "&1 cx Ldata.Coord=1 call 100001"); //no error sprintf(resp, "Test02"); ConvertSymbolicToPMACExp((unsigned char *) resp); sprintf(cmd, "&1 cx Ldata.Coord=1 call %s", resp); //no error error = GetResponse(cmd, resp, 255, 7); pshm->P[102]++; sprintf(cmd, "response = %s: error = %d\n", resp, error); error = Send(0, cmd); CloseLibrary(); return 0; } open subprog Test02 local myvar; linear inc ta100 tm1000 p1++ x3000 dwell0 p2++ return; close open prog 1 local mylocal; Call Test02 p3 = mylocal close Link to comment Share on other sites More sharing options...
artag Posted March 15, 2011 Author Share Posted March 15, 2011 Adrian, I am not getting this error. I made something quick as follows and I get no errors. What is different from your system? There was no error detected in a return value : it's simply that my debugging output showed a spurious string, apparently in the value returned by ConvertSymbolicToPMACExp. However, working from your example and incorporating bits of test code, I found that the problem was entirely in the Send I was using to check the result. This can more simply be shown up by : int main(void) { char resp[255]; InitLibrary(); Send(1, "aaa aaa\n"); Send(1, "AAA"); Send(1, "bbb \n bbb"); Send(1, "BBB"); CloseLibrary(); return 0; } which produces the output Port 1: aaa aaa Port 1: AAA Port 1: bbb InvalidResponse: bbb Port 1: BBB So it seems Send() doesn't like to have a newline in the string, unless it's at the end. This isn't particularly important to me - I only had a newline there because ConvertSymbolicToPMACExp() happens to append one to the result. I guess it might be related to the IDE window that extracts and prints unsolicited messages, or the 'Port n' formatting, rather than Send() itself. -adrian Link to comment Share on other sites More sharing options...
bradp Posted March 15, 2011 Share Posted March 15, 2011 Thanks. I wil pass this on to the IDE team and see if there is something they can do about it. Link to comment Share on other sites More sharing options...
Recommended Posts