Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PLC cannot execute background C program
#1
Enter system "/var/ftp/usrflash/Project/C Language/Background Programs/xoptical.out" in the terminal window; the background c program can run correctly.
Then, it cannot be executed in the plc.
When xoptical.out runs, prepare will be changed to 0. PLC1data will record the number of executions and complete the count. The program cannot run as designed, only PLC1data has been accumulating. I think it is because the PLC cannot issue the system command correctly to make xoptical.out run. How to avoid this problem?


// open plc 1
// --------------------User Code Goes Here------------------------
open plc Xoptical

if(prepare==1)
{
system "/var/ftp/usrflash/Project/C Language/Background Programs/xoptical.out" ;
call timer(10);
PLC1data++;
}

if(compWipe==1)
{
system "/var/ftp/usrflash/Project/C Language/Background Programs/xoptical.out";
call timer(10);
PLC2data++;
}

close
Reply
#2
I think it has to do with file names containing spaces. Try this.
Code:
system "/var/ftp/usrflash/Project/C\ Language/Background\ Programs/xoptical.out“
Reply
#3
Thanks ,Eric, my firmware version is 2.5.4.0. I have followed your instructions many times and still cannot run the background program C in the plc. Another strange problem also appeared.

float *compdataptr;
compdataptr = pshm->CompTable[16].Data + OffsetTblSHM;

if(Fisprepare==1&&FcompLoad==0)
{
int i,j;
data1=0;
data2=0;
int diffs=MatfCpoint + 1 ;

for(i=0;i<=MatfLinear;i++)
{
for(j=0;j<=MatfCpoint;j++)
{

*(compdataptr + diffs*i + j) = tempCuttingDepth; // send to the comp table
data2++;
}

data1++;
}
}

When I run the compensation table data assignment program, the IDE's terminal window prompts "egmentation fault", and then the background C program terminates. I wonder if my assignment is wrong? But can't find the problem?
Reply
#4
Because compensation tables dynamically resize, it is not possible to write to those structures from C in that manner.

Command quotes can be used instead.
Code:
Command("CompTable[16].Data[0]=0");
Reply
#5
This is a bad thing. I followed the Entering Table Data Points in C section of the Power PMAC User’s Manual. In my actual application now, I do need to dynamically assign CompTable[m].Data[i]. Command("CompTable[16].Data[0]=0") implements assignment, unfortunately, it cannot satisfy my application. I'm wondering why, suddenly I can't use the C language to assign values, but Power PMAC User’s Manual explains that POWER PMAC has this function?
I do need this feature. Does another version of the firmware have this function? Can I re-order a Power CPU to realize this function? If possible, please email me Eric, thanks again for your reply.
Reply
#6
I am sorry. I remembered something about CamTables and assumed it was true for Compensation Tables as well. Compensation Table Correction Sizes can be configured in C as shown in the Power PMAC Users Manual.
Reply
#7
Eric,Through the Command (Command("CompTable[0].Data[0]=0")), in the background C language program, about 10 thousand assignments can be completed per second.
I am trying to increase the speed of assignment. Exercise time is precious, especially when there are many cycles. Are there any good suggestions worth trying?
Reply
#8
The following code worked to change the first 2 table entries for me with either a 1D or 2D compensation table. I am using firmware 2.6.0.1 and IDE 4.5.1.3 on a UMAC 1040 CPU, but I would expect it to work the same on any Power PMAC.

Code:
float *CompDataPtr;
CompDataPtr = pshm->CompTable[1].Data + OffsetTblSHM;
*CompDataPtr = pshm->P[0];
*(CompDataPtr+1) = pshm->P[1];

I'm not sure why this isn't working for you. I tried writing to values past the end of the table, but I can't get a segmentation fault.

Can you try code that manual writes to the same location as the first couple iterations of that loop?
Reply
#9
Thanks, Eric
*CompDataPtr = pshm->P[0];
It is possible to assign pointers to P variables. I used to be local variables and always reported errors.
This method can efficiently complete the assignment, I am very happy.
Reply
#10
I was just using "pshm->P[0]" as a placeholder so I could edit the value and not have to re-compile. You can also use C-Variables or literal numbers.
Reply
#11
Eric. I'm trying an electronic cam table. I want to know if there is a definite relationship between CamTable[m].PosData[i] and CamTable[m].OutData[i]? I set CamTable[m].PosData[1] to 1000, CamTable[m].OutData[1] will automatically become 1148846080? I checked the manual document, but did not find the content in this regard. Can you answer it or provide some information for reference?
Reply
#12
CamTable[m].OutData[i] is used for enabling GPIO based on motor position.

If you bring the motor to a position of CamTable[m].X0 with the camtable properly enabled, then...
The location specified by CamTable[m].pOut will be set to CamTable[m].OutData[0]
CamTable[m].PosOffset/Motor[x].CompDesPos will be set to CamTable[m].PosData[0]
Reply
#13
Eric, thanks for your reply.
I use C language to assign 1000 to CamTable[16].OutData[i]. However, the result is 1148846080. What surprised me is that the values of CamTable[16].PosData[3], CamTable[16].PosData[5], CamTable[16].PosData[7], CamTable[16].PosData[9] are 1000 (It is the value I want to assign to CamTable[16].OutData[i]).


float *CamDataPtr;
CamDataPtr = pshm->CamTable[16].OutData+OffsetTblSHM;
for(Ccount=0;Ccount<MatftsCpoint;Ccount++)
{
*(CamDataPtr + Ccount) =myval;
}


Attached Files Image(s)
   
Reply
#14
For OutData, the pointer must be declared as an int.
Code:
int *OutDataPtr;
OutDataPtr = pshm->CamTable[0].OutData + OffsetTblSHM;
*OutDataPtr = (int) pshm->P[0];
*(OutDataPtr+1) = (int) pshm->P[1];
Reply
#15
Eric, thanks .
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)