Vladimir Nemera / Mbed 2 deprecated MW771LP-2seam

Dependencies:   RA8875 SDFileSystem mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers comm.cpp Source File

comm.cpp

00001 // MW771 Laser Press HMI.
00002 // V.Nemera, 10/12/2016, ver.1.0, C++
00003 // CPU: mbed NXP LPC1768 (ARM Cortex-M3, 32bit, 90MHz)
00004 
00005 #include "RA8875.h"         
00006 #include "main.h"         
00007 #include "comm.h"         
00008 
00009 //-----------HMI i/o---------------------
00010 DigitalIn inEStop(p19);     //input: E-Stop ON = 1
00011 DigitalIn inBtnStart(p20);  //input: Btn Start ON = 0
00012 DigitalIn inLPactive(p26);  //input: Laser power active = 1
00013 DigitalIn in1(p24);         //input: in1 ON = 0
00014 DigitalIn in2(p23);         //input: in2 ON = 0
00015 
00016 DigitalOut outIrq(p14);         //output: interrupt for IO
00017 DigitalOut outLampStart(p25);   //output: Start Lamp ON = 1
00018 DigitalOut out1(p22);           //output: out1 ON = 1
00019 DigitalOut out2(p21);           //output: out2 ON = 1
00020 
00021 Ticker resetTime;                //time for e-stop reset pulse
00022 
00023 int iCh;
00024 char hexArr[] = "0123456789ABCDEF";
00025 const char err100[] = "Wrong command\n";
00026 const char err101[] = "No response\n";
00027 
00028 Serial ioRS232(p28, p27);  // tx, rx
00029 int     ioRS232baud = 115200;
00030 int     ioRS232bits = 8;
00031 SerialBase::Parity  ioRS232parity = SerialBase::None;
00032 int     ioRS232stop_bits = 1; 
00033 
00034 Serial LasRS232(p9, p10);  // tx, rx
00035 int     LasRS232baud = 57600;
00036 int     LasRS232bits = 8;
00037 SerialBase::Parity  LasRS232parity = SerialBase::None;
00038 int     LasRS232stop_bits = 1; 
00039 
00040 char hmiLBuf[64];   //buffer hmi command to send to laser
00041 
00042 int indLhmi = 0;       //index of buffer hmiLBuf[]
00043 
00044 char LasBufCom[64];   //buffer command to send to laser
00045 char LasBufResp[64];  //buffer response from laser
00046 
00047 int indLCom = 0;       //index of buffer LasBufCom[]
00048 int indLResp = 0;      //index of buffer LasBufResp[]
00049 
00050 char IOBufCom[32];   //buffer command from io controller
00051 char IOBufResp[32];  //buffer response to send to io controller
00052 
00053 int indIOCom = 0;       //index of buffer IOBufCom[]
00054 int IOBufSize = 32;      //buffer IOBufResp[] size
00055 int sBio = 0;           //send ioBuf pointer
00056 int wBio = 0;           //write ioBuf pointer
00057 
00058 char comBuf[128];      //buffer command from pc 
00059 int comBufPointer = 0;
00060 
00061 int sBp = 0;           //send pcBuf pointer
00062 int wBp = 0;           //write pcBuf pointer
00063 const int pcBufSize = 128;
00064 char pcBuf[pcBufSize];
00065 
00066 int stLhmi = 0;        //status of hmi L.command
00067 int stLpc = 0;         //status of pc L.command
00068 int iPCcmd = 0;        //command # from pc
00069 int stL3 = 0;          //status of execution L.command
00070 int iCounts = 0;
00071 int iSta = 0;
00072 int c; 
00073 int usta;
00074 int iLasO, iLasO1, iLasO2;
00075 int iCmax = 10;
00076 //=========================================================
00077 const char *cLC[80];      //array of laser commands string
00078 
00079 void cLCinit(void) {
00080     cLC[0] = "";
00081     cLC[1] = "STA";     //cod 0x4001 STA -   read laser status 
00082     cLC[2] = "RCS";     //cod 0x4002 RCS -   read current setpoint
00083     cLC[3] = "RNC";     //cod 0x4003 RNC -   read minimum current setpoint
00084     cLC[4] = "ROP";     //cod 0x4004 ROP -   read output power
00085     cLC[5] = "RPP";     //cod 0x4005 RPP -   read peak power
00086     cLC[6] = "RPW";     //cod 0x4006 RPW -   read pulse width
00087     cLC[7] = "RPRR";    //cod 0x4007 RPRR -  read pulse repetition rate
00088     cLC[8] = "RFV";     //cod 0x4008 RFV -   read current software revision
00089     cLC[9] = "RCT";     //cod 0x4009 RCT -   read laser temperature
00090     cLC[10] = "RET";    //cod 0x400A RET -   read elapsed time  the laser has been on
00091     cLC[11] = "RMEC";   //cod 0x400B RMEC -  read module error code
00092     cLC[12] = "RSN";    //cod 0x400C RSN -   read serial number
00093     cLC[13] = "REC";    //cod 0x400D REC -   read error counter
00094     cLC[14] = "RICDT";  //cod 0x400E RICDT - read input circuit discharge time
00095     cLC[15] = "RIP";    //cod 0x400F RIP -   read the current IP address
00096     cLC[16] = "RMASK";  //cod 0x4010 RMASK - read the current subnet mask
00097     cLC[17] = "RDGW";   //cod 0x4011 RDGW -  read the current default gateway address
00098     cLC[18] = "RMAC";   //cod 0x4012 RMAC -  read MAC address
00099     cLC[19] = "RBAUD";  //cod 0x4013 RBAUD - read the current RS232 baud rate
00100     cLC[20] = "";
00101     cLC[21] = "";
00102     cLC[22] = "";
00103     cLC[23] = "";
00104     cLC[24] = "";
00105     cLC[25] = "";
00106     cLC[26] = "";
00107     cLC[27] = "";
00108     cLC[28] = "";
00109     cLC[29] = "";
00110     cLC[30] = "";
00111     cLC[31] = "";
00112     cLC[32] = "EPM";    //cod 0x4020 EPM -   enable pulse mode
00113     cLC[33] = "DPM";    //cod 0x4021 DPM -   disable pulse mode
00114     cLC[34] = "ABN";    //cod 0x4022 ABN -   aiming beam on
00115     cLC[35] = "ABF";    //cod 0x4023 ABF -   aiming beam off
00116     cLC[36] = "EEC";    //cod 0x4024 EEC -   enable external analog power control input
00117     cLC[37] = "DEC";    //cod 0x4025 DEC -   disable external analog power control input
00118     cLC[38] = "EGM";    //cod 0x4026 EGM -   enable gate mode (internal pulse generator gated by external modulation input)
00119     cLC[39] = "DGM";    //cod 0x4027 DGM -   disable gate mode
00120     cLC[40] = "EMOD";   //cod 0x4028 EMOD -  enable external modulation input
00121     cLC[41] = "DMOD";   //cod 0x4029 DMOD -  disable external modulation input
00122     cLC[42] = "ELE";    //cod 0x402A ELE -   enable external emission input
00123     cLC[43] = "DLE";    //cod 0x402B DLE -   disable external emission input
00124     cLC[44] = "EHC";    //cod 0x402C EHC -   enable compatibility mode
00125     cLC[45] = "EDC";    //cod 0x402D EDC -   disable compatibility mode
00126     cLC[46] = "EEABC";  //cod 0x402E EEABC - enable external aiming beam control input
00127     cLC[47] = "DEABC";  //cod 0x402F DEABC - disable external aiming beam control input
00128     cLC[48] = "EWPM";   //Enable Waveform Pulse Mode
00129     cLC[49] = "DWPM";   //Disable Waveform Pulse Mode
00130     cLC[50] = "PCFG";   //Configure Waveform Mode
00131     cLC[51] = "RCE";    //Reset critical error
00132     cLC[52] = "RERR";   //Resers any resettable errors
00133     cLC[53] = "EMON";   //Start Emission
00134     cLC[54] = "EMOFF";  //Stop Emission
00135     cLC[55] = "";
00136     cLC[56] = "";
00137     cLC[57] = "";
00138     cLC[58] = "";
00139     cLC[59] = "";
00140     cLC[60] = "";
00141     cLC[61] = "";
00142     cLC[62] = "";
00143     cLC[63] = "";
00144     cLC[64] = "SDC ";    //cod 0x4040 SDC -   set diode current, min current < xx.x% < 100%
00145     cLC[65] = "SPW ";    //cod 0x4041 SPW -   set pulse width, xx.x mS
00146     cLC[66] = "SPRR ";   //cod 0x4042 SPRR -  set pulse repetition rate, xxx Hz
00147     cLC[67] = "SIP ";    //cod 0x4043 SIP -   set IP, xxx.xxx.xxx.xxx
00148     cLC[68] = "SMASK ";  //cod 0x4044 SMASK - set subnet mask, xxx.xxx.xxx.xxx
00149     cLC[69] = "SDGW ";   //cod 0x4045 SDGW -  set default gateway, xxx.xxx.xxx.xxx
00150     cLC[70] = "SMAC ";   //cod 0x4046 SMAC -  set MAC address xx-xx-xx-xx-xx-xx
00151     cLC[71] = "SBAUD ";  //cod 0x4047 SBAUD - set baud rate x (0-110,1-300,2-1200,3-2400,4-4800,5-9600
00152                         //                                    6-19200,7-38400,8-57600default,9-115200)
00153     cLC[72] = "PRSEL "; //Select Profile
00154     cLC[73] = "SQSEL "; //Select Sequence
00155     cLC[74] = "";
00156     cLC[75] = ""; 
00157     cLC[76] = "";
00158     cLC[77] = "";
00159     cLC[78] = "";
00160     cLC[79] = "";
00161 }
00162 
00163 //-------------------------------------------
00164 int SetLasComm(int icLC) {
00165     for(int i=0; i<15; i++) {   //wait 15*20ms stLhmi=0 (last command executed)
00166         if(stLhmi == 0) {
00167             indLhmi++;
00168             for(int j=0; j<indLhmi; j++) {hmiLBuf[j] = '\0';}
00169             indLhmi = strlen(cLC[icLC]);
00170             strncpy(hmiLBuf, cLC[icLC], indLhmi);
00171             //pc.printf("-s%i %s %s %i\n", icLC, hmiLBuf, cLC[icLC], indLhmi);
00172             if(icLC == 1) iSta = 1;
00173             stLhmi = 2;
00174             wait_ms(20);
00175             return 0;        
00176         }
00177         else {
00178             wait_ms(20);    
00179         }
00180     }
00181     //pc.printf("-e%i %s %s %i\n", icLC, hmiLBuf, cLC[icLC], indLhmi);
00182     return 1;
00183 }
00184     
00185 void initHMIio(void) {
00186     ioRS232.format(ioRS232bits, ioRS232parity, ioRS232stop_bits);
00187     ioRS232.baud(ioRS232baud);
00188     
00189     LasRS232.format(LasRS232bits, LasRS232parity, LasRS232stop_bits);
00190     LasRS232.baud(LasRS232baud);
00191     
00192     outIrq = 0;         //output: interrupt for IO
00193     outLampStart = 0;   //output: Start Lamp ON = 1
00194     out1 = 0;           //output: out1 ON = 1
00195     out2 = 0;           //output: out2 ON = 1
00196 
00197     cLCinit();
00198     
00199     for(int i=0; i<64; i++) {
00200         LasBufCom[i] = '\0';
00201         LasBufResp[i] = '\0';
00202     }  
00203 }
00204 //write char to pc buffer
00205 void wrChar(char cCh) {
00206     pcBuf[wBp++] = (cCh);
00207     if(wBp == pcBufSize) {wBp = 0;}    
00208 }
00209 //write char array to pc buffer
00210 void wrCharArr(const char* err) {
00211     int iM;
00212     iM = strlen(err);
00213     for(int i=0; i<iM; i++) {
00214         wrChar(err[i]);
00215     }
00216 }
00217 //write 16bit word to pc buffer
00218 void wrWord(uint16_t uWrd) {
00219     wrChar(hexArr[uWrd/4096]);
00220     uWrd = uWrd % 4096;    
00221     wrChar(hexArr[uWrd/256]);
00222     uWrd = uWrd % 256;    
00223     wrChar(hexArr[uWrd/16]);
00224     wrChar(hexArr[uWrd%16]);
00225 }
00226 //write 32bit word to pc buffer
00227 void wrInt(int i32) {
00228     wrWord((uint16_t)(i32/65536));
00229     wrWord((uint16_t)(i32%65536));
00230 }
00231     
00232 void comParser() {
00233     if(comBufPointer < 2) {
00234         wrCharArr(err100);    //err100 = Wrong command
00235         wrChar('>');
00236         comBufPointer =0;
00237         return;
00238     }
00239     //pc.printf("1 %i 2 %i\n", comBuf[0], comBuf[1]); 
00240         
00241     //for (int j = 3; j < comBufPointer; j++) {
00242     //    pc.printf("%i %i \n", j, comBuf[j]);
00243     //}
00244 
00245     int a = comBuf[0];
00246     int b = comBuf[1];
00247     
00248     //-----------------------
00249     if (((a == 76) || (a == 108)) && (b == 32)) {  //L<SP> or l<SP>
00250         if(stLpc == 0) {
00251 //            pc.printf("<%i>", comBufPointer); 
00252             iPCcmd = 1;
00253         }
00254         else {
00255             wrChar('?');
00256             wrChar('>');
00257         }            
00258     }
00259     
00260     //-----------------------
00261     else if (((a == 76) || (a == 108)) && ((b == 83) || (b == 15))) {  //LS or ls
00262         iPCcmd = 2;
00263     }
00264     
00265     //-----------------------
00266     else if (((a == 76) || (a == 108)) && ((b == 73) || (b == 105))) {  //LI or li
00267         iPCcmd = 3;
00268     }
00269     
00270     //----------------------- 
00271     else if(((a == 76) || (a == 108)) & ((b == 65) || (b == 97))) {  //LA or la
00272         iPCcmd = 4;
00273     }
00274     
00275     //----------------------- 
00276     else if(((a == 76) || (a == 108)) & ((b == 67) || (b == 99))) {  //LC or lc
00277         iPCcmd = 5;
00278     }
00279     
00280     //----------------------- 
00281     else if(((a == 76) || (a == 108)) & ((b == 82) || (b == 114))) {  //LR or lr
00282         iPCcmd = 6;
00283     }
00284     
00285     else {
00286         wrCharArr(err100);    //err100 = Wrong command
00287         wrChar('>');
00288         comBufPointer =0;
00289     }
00290 }
00291 //=========================================================
00292 void wrIOChar(char cCh) {       //write 1 char to io buffer
00293     IOBufResp[wBio++] = (cCh);
00294     if(wBio == IOBufSize) wBio = 0;    
00295 }
00296 
00297 void wrIObyte(int iCh) {       //write byte (2 char) to io buffer
00298     iCh = iCh & 0xFF;
00299     wrIOChar(hexArr[iCh/16]);
00300     wrIOChar(hexArr[iCh%16]);
00301 }
00302 
00303 void wrIOword(uint16_t uWrd) {    //write 16bit word (4 char) to io buffer
00304     wrIOChar(hexArr[uWrd/4096]);
00305     uWrd = uWrd % 4096;    
00306     wrIOChar(hexArr[uWrd/256]);
00307     uWrd = uWrd % 256;    
00308     wrIOChar(hexArr[uWrd/16]);
00309     wrIOChar(hexArr[uWrd%16]);
00310 }
00311 
00312 void wrIOint(int i32) {           //write 32bit word to io buffer
00313     wrIOword((uint16_t)(i32/65536));
00314     wrIOword((uint16_t)(i32%65536));
00315 }
00316 void ioSt(void) {
00317     int b0st = 0;   //send bits d7-d4
00318     if(in2) b0st = b0st + 1;
00319     if(flagParChanged == 0) b0st = b0st + 2;
00320     if(flagLrsConnected) b0st = b0st + 4;
00321     if(flagLcomProcess) b0st = b0st + 8;
00322     wrIOChar(hexArr[b0st]);
00323         
00324     b0st = 0;       //send bits d3-d0
00325     if(inEStop) b0st = b0st + 1;
00326     if(inBtnStart) b0st = b0st + 2;
00327     if(inLPactive) b0st = b0st + 4;
00328     if(in1) b0st = b0st + 8;
00329     wrIOChar(hexArr[b0st]);
00330     
00331     wrIOChar(0xD);          //send <CR>
00332 }
00333 
00334 void sendIOerr(int iErr) {
00335     wrIOChar(hexArr[iErr | 8]); //1<err> send
00336     wrIOChar(0x30);             //0-status send
00337     ioSt();
00338     showTPstatus(iErr);        
00339 }
00340 
00341 void sendIOstatus(void) {
00342     uint8_t b0st = 0;
00343     if(flagParChanged == 0) {
00344         b0st = 0x0010;      //param. send request
00345         
00346         led3 = 1;
00347         wait_us(4);
00348         led3 = 0;
00349     }    
00350     else b0st = ioReq << 4;                     //another requests
00351     wrIObyte(b0st);
00352 
00353     ioSt();        
00354     flagParChanged = 1;
00355 }
00356 
00357 void sendIOpar(void) {
00358     int b0par;
00359     
00360     wrIOChar(0x30);   //0000-ready & no err
00361     wrIOChar(0x31); //1-parameters send
00362     
00363     b0par = prPar[progNumber].wMode + (prPar[progNumber].Lmode * 64);
00364     wrIObyte(b0par); //send mode
00365 
00366     wrIObyte(prPar[progNumber].LPbeg);
00367     wrIObyte(prPar[progNumber].LPend);
00368     wrIOword(prPar[progNumber].Lfreq);
00369     wrIObyte(prPar[progNumber].Lpulse);
00370     wrIObyte(prPar[progNumber].amplBeg);
00371     wrIObyte(prPar[progNumber].amplEnd);
00372     wrIObyte(prPar[progNumber].wFreq);
00373     wrIOword(prPar[progNumber].wTime);
00374     wrIObyte(prPar[progNumber].amplNum);
00375 
00376     wrIOChar(0xD);          //senr <CR>
00377     //flagParChanged = 1;
00378     c7 = c7 | 0x7700;
00379 }
00380 
00381 void sendIOout(void) {
00382     for(int i=0; i<2; i++) {
00383         ioPar.o3[i] = IOBufCom[i+2];
00384         ioPar.o2[i] = IOBufCom[i+4];
00385         ioPar.o1[i] = IOBufCom[i+6];
00386     }    
00387 
00388     if(bitOstate > 0x7F) {  //send output
00389         wrIOChar(0x30);     //0000-ready & no err
00390         wrIOChar(0x32);     //2-output send
00391         
00392         wrIObyte(bitOstate & 0x7F);        
00393         wrIOChar(0xD);          //senr <CR>
00394     }
00395     else sendIOstatus();
00396 }
00397 
00398 void sendIOinp(void) {
00399     for(int i=0; i<2; i++) {
00400         ioPar.i3[i] = IOBufCom[i+8];
00401         ioPar.i2[i] = IOBufCom[i+10];
00402         ioPar.i1[i] = IOBufCom[i+12];
00403         ioPar.aiLPow[i] = IOBufCom[i+14];
00404         ioPar.aiLCur[i] = IOBufCom[i+16];
00405         ioPar.aiLTemp[i] = IOBufCom[i+18];
00406         ioPar.aiLBR[i] = IOBufCom[i+20];
00407     }    
00408     sendIOstatus();
00409 }
00410 
00411 void flip() {
00412     out2 = 0;
00413     led4 = 0;
00414     wait_us(1);
00415     led4 = 1;
00416     wait_us(2);
00417     led4 = 0;
00418     //    pc.printf("o20 ");
00419     
00420 }    
00421 
00422 void sendIOmsg(int iMsg) {
00423     switch (iMsg) {
00424     case 48:          //0-READY FOR WELDING
00425         showTPstatus(16);
00426         int t = SetLasComm(52);
00427         flagWeld = 0; 
00428         sendIOstatus(); 
00429         break;
00430     case 49: {showTPstatus(17); flagWeld = 0; sendIOstatus(); break;}    //1-WOBBLE HEAD INIT...
00431     case 50: {showTPstatus(18); flagWeld = 0; sendIOstatus(); break;}    //2-WOBBLE HEAD ERROR
00432     case 51: {showTPstatus(19); flagWeld = 0; sendIOstatus(); break;}    //3-IO CONTROLLER ERROR
00433     case 52: {showTPstatus(20); flagWeld = 1; sendIOstatus(); break;}    //4-WELDING IN PROGRESS..
00434     case 53:                                                             //5-auto reset e-stop
00435         showTPstatus(16);
00436         out2 = 1;
00437         led4 = 1;
00438         resetTime.attach(&flip, 0.5); //the address of the function to be attached (flip) to ticker
00439         //printf("o21 ");
00440         flagWeld = 0;
00441         sendIOstatus();
00442         break;
00443     case 54:                                                             //6-send laser command
00444         if(TPstatus == 0) wrIOChar(0x30);   //0000-ready & no err
00445         else wrIOChar(0x38);                //1000-not ready & no err 
00446         wrIOChar(0x33); //3-laser STA send
00447         
00448         wrIOint(usta);        
00449         wrIOChar(0xD);          //senr <CR>
00450 
00451         flagWeld = 0;
00452         break;
00453     }
00454 }    
00455 
00456 void ioCommand(void) {
00457     if(indIOCom < 2) {
00458         sendIOerr(06);    //err 06 = Short command
00459         indIOCom =0;
00460         return;
00461     }
00462     int a = IOBufCom[0];
00463     int b = IOBufCom[1];
00464     if (((a == 67) || (a == 99)) && (b == 48)) sendIOstatus();   //C0 or c0
00465     else if (((a == 67) || (a == 99)) && (b == 49)) sendIOpar();  //C1 or c1
00466     else if (((a == 67) || (a == 99)) && (b == 50)) sendIOout();  //C2 or c2
00467     else if (((a == 67) || (a == 99)) && (b == 51)) sendIOinp();  //C3 or c3
00468     else if ((a == 69) || (a == 101)) sendIOmsg(b);  //E<b> or e<b> command
00469     else sendIOerr(07);    //err 07 = Wrong command
00470     indIOCom =0;
00471 }    
00472 
00473 //=========================================================
00474 
00475 //execute L.command
00476 void LaserCommand(void)  //laser control
00477 {
00478     if(stL3 == 0) {     // check commands will be execute
00479 
00480         if(stLhmi == 2) {stL3 = stL3 + 1;}  //command from hmi
00481         if(iPCcmd != 0) {     //command from pc
00482             stLpc = 2;
00483             stL3 = stL3 + 2;
00484         }
00485         if(stL3 == 0) flagLcomProcess = 0;
00486         else flagLcomProcess = 1;
00487     }
00488 
00489     if(stL3 & 1) {   //hmi command
00490         if(stLhmi == 2) {      //send hmi command to laser
00491             while(LasRS232.readable()) {
00492                 iLasO = LasRS232.getc();
00493             }
00494             iLasO = 0;
00495             
00496             for (int i = 0; i < indLhmi; i++) {
00497                 LasRS232.printf("%c", hmiLBuf[i]);
00498             }
00499             LasRS232.printf("\r");
00500             iCounts = 0;
00501             stLhmi = 3;    
00502         }
00503         else if(stLhmi == 3) {      //wait response from laser
00504             if(LasRS232.readable()) {
00505 lasRS2:
00506                 iLasO = LasRS232.getc();
00507                 LasBufResp[indLResp++] = (char)iLasO;
00508                 if(iLasO == 13) {
00509                     stLhmi = 4;
00510                     iCounts = 0;
00511                     flagLrsConnected = 1;
00512                 }
00513                 if(LasRS232.readable()) goto lasRS2;
00514             }
00515             else {        
00516                 ++iCounts;
00517                 if(iCounts > 400) {
00518                     indStat = 11;       //error 11 - lazer does not answer
00519                     indLResp = 0;
00520                     stLhmi = 0;
00521                     stL3 = stL3 & 0xE;  //no hmi command
00522                     flagLrsConnected = 0;
00523                }
00524             }
00525         }
00526         else if(stLhmi == 4) {      //response to hmi 
00527             //printf("L %c %c\n", *LasBufResp, *hmiLBuf);
00528             if (*LasBufResp == *hmiLBuf) {
00529                 if (iSta == 1) {    //update L.status to hmi 
00530                     c = 0;
00531                     for(int i=6; i<indLResp; i++) {
00532                         c = (c * 10) + LasBufResp[i-1] - '0';
00533                     }
00534                     usta = c;
00535                     iSta = 0;
00536                 }
00537                 indStat = 0;        //done
00538                 stLhmi = 5;
00539             }
00540             else {
00541                 indStat = 12;       //error 12 - laser command error
00542                 stLhmi = 5;
00543             }
00544         }               
00545         else if(stLhmi == 5) {      //delay for next command
00546             ++iCounts;
00547             if(iCounts > iCmax) {
00548                 indLResp = 0;
00549                 stL3 = stL3 & 0xE;  //no hmi command
00550                 stLhmi = 0;
00551             }
00552         }               
00553     }
00554         
00555     else if(stL3 & 2) {   //pc command       
00556         if(iPCcmd == 1) {
00557             if(stLpc == 2) {   //send pc command to laser
00558                 while(LasRS232.readable()) {
00559                     iLasO2 = LasRS232.getc();
00560                 }
00561                 for (int i = 2; i < (comBufPointer-1); i++) {
00562                    LasRS232.printf("%c", comBuf[i]);
00563                    //pc.printf("a%c ", comBuf[i]);
00564                 }    
00565                 LasRS232.printf("\r");
00566                 iCounts = 0;
00567                 stLpc = 3;
00568             }
00569             else if(stLpc == 3) {    //wait response from laser
00570                 if(LasRS232.readable()) {
00571 lasRS1:
00572                     iCh = LasRS232.getc();
00573                     iCounts = 0;
00574                     if(iCh == 13) {         //CR - carrier return
00575                         wrChar('\n');       //send LF to pc
00576                         wrChar('>');
00577                         stLpc = 4;
00578                     }    
00579                     else {
00580                         wrChar(char(iCh));
00581                     }
00582                     if(LasRS232.readable())    goto lasRS1;
00583                 }        
00584                 else {        
00585                     ++iCounts;
00586                     if(iCounts > 400) { //200mS
00587                         wrCharArr(err101);    //err101 = "No response\n"
00588                         comBufPointer =0;
00589                         stL3 = stL3 & 0xD;
00590                         iPCcmd = 0;
00591                         stLpc = 0; 
00592                     }
00593                 }        
00594             }
00595             else if(stLpc == 4) {      //delay for next command
00596                 ++iCounts;
00597                 if(iCounts > iCmax) {
00598                     comBufPointer =0;
00599                     stL3 = stL3 & 0xD;
00600                     iPCcmd = 0;
00601                     stLpc = 0;
00602                 }
00603             }               
00604             
00605         }
00606         else if(iPCcmd == 2) {
00607 
00608             wrChar('S');
00609             wrChar('T');
00610             wrChar('A');
00611             wrChar(' ');
00612             wrInt(usta);
00613             wrChar('\n');
00614             wrChar('>');
00615             comBufPointer =0;
00616             stL3 = stL3 & 0xD;
00617             iPCcmd = 0;
00618             stLpc = 0;
00619             
00620         }              
00621         else if(iPCcmd == 3) {
00622 
00623             wrChar('I');
00624             wrChar(' ');
00625             wrWord(wBp);
00626             wrChar(' ');
00627             wrWord(sBp);
00628             wrChar(' ');
00629             //wrChar('\n');
00630             int a = sBp;
00631             for(int i=0; i<32; i++) {
00632                 wrChar(pcBuf[a--]);
00633                 if(a<0) {a=pcBufSize-1;}
00634             }    
00635             wrChar('\n');
00636             wrChar('>');
00637             comBufPointer =0;
00638             stL3 = stL3 & 0xD;
00639             iPCcmd = 0;
00640             stLpc = 0;
00641             
00642         }
00643         else if(iPCcmd == 4) {
00644 
00645             wrChar('L');
00646             wrChar('A');
00647             wrChar(' ');
00648             wrInt(a7);
00649             wrChar(' ');
00650             wrInt(b7);
00651             wrChar(' ');
00652             wrInt(c7);
00653             wrChar(' ');
00654             wrInt(d7);
00655             wrChar('\n');
00656             wrChar('>');
00657             comBufPointer =0;
00658             stL3 = stL3 & 0xD;
00659             iPCcmd = 0;
00660             stLpc = 0;
00661             a7 = 0; b7 = 0; c7 = 0; d7 = 0;
00662         }
00663         else if(iPCcmd == 5) {
00664 /*
00665             wrInt(indLCabcc);
00666             wrChar(' ');
00667             wrChar('L');
00668             wrChar('C');
00669             wrChar(' ');
00670             wrChar('"');
00671             
00672             for(int i=0; i<indLCabcc; i++) {
00673                 wrChar(LabccBufCom[i]);        
00674             }    
00675 */          a7=0; b7=0, c7=0; d7=0;
00676             wrChar('5');
00677             wrChar('\n');
00678             wrChar('>');
00679             comBufPointer =0;
00680             stL3 = stL3 & 0xD;
00681             iPCcmd = 0;
00682             stLpc = 0;
00683             
00684         }
00685         else if(iPCcmd == 6) {
00686             pc.printf("wMode %i\n", prPar[progNumber].wMode); 
00687             pc.printf("Lmode %i\n", prPar[progNumber].Lmode); 
00688             pc.printf("LPbeg %i\n", prPar[progNumber].LPbeg); 
00689             pc.printf("LPend %i\n", prPar[progNumber].LPend); 
00690             pc.printf("Lfreq %i\n", prPar[progNumber].Lfreq); 
00691             pc.printf("Lpulse %i\n", prPar[progNumber].Lpulse); 
00692             pc.printf("amplBeg %i\n", prPar[progNumber].amplBeg); 
00693             pc.printf("amplEnd %i\n", prPar[progNumber].amplEnd); 
00694             pc.printf("wFreq %i\n", prPar[progNumber].wFreq); 
00695             pc.printf("wTime %i\n", prPar[progNumber].wTime); 
00696             pc.printf("amplNum %i\n", prPar[progNumber].amplNum); 
00697     
00698             wrChar('\n');
00699             wrChar('>');
00700             comBufPointer =0;
00701             stL3 = stL3 & 0xD;
00702             iPCcmd = 0;
00703             stLpc = 0;
00704             
00705         }
00706     }
00707 }
00708 
00709 void flipRS(void) {
00710     led2 = 1;
00711     //check io RS232 command
00712     if(ioRS232.readable()) {
00713 flip01:
00714         iCh = ioRS232.getc();
00715         IOBufCom[indIOCom++] = (char)iCh;
00716         if(iCh == 13) {    //CR - carriage return
00717             ioCommand();
00718         }
00719         if(ioRS232.readable()) goto flip01;
00720     }
00721     //check response
00722     if(ioRS232.writeable()) {
00723         if(sBio != wBio) {    //ioBuf not empty
00724             int ff = 12;
00725 flip02:
00726             ioRS232.putc(IOBufResp[sBio++]);
00727             if(sBio == IOBufSize) {sBio = 0;}
00728             --ff;
00729             if((sBio != wBio) && (ff > 0)) goto flip02;
00730         }    
00731     }
00732     //check pc RS232 command
00733     if(pc.readable()) {
00734         iCh = pc.getc();
00735         comBuf[comBufPointer++] = (char)iCh;
00736         wrChar(iCh);
00737         if(iCh == 10) {    //LF - new line
00738             comParser();
00739         }    
00740     }
00741     
00742     if(pc.writeable()) {
00743         if(sBp != wBp) {    //pcBuf not empty
00744             pc.putc(pcBuf[sBp++]);
00745             if(sBp == pcBufSize) {sBp = 0;}
00746         }    
00747     }
00748     //serve Laser RS232 command
00749     LaserCommand();
00750     led2 = 0;
00751 }
00752 
00753 //=========================================================
00754 int lampSt;
00755 
00756 void main_cycle_add(void)
00757 {
00758     if((flagWeld == 0) & (lampSt == 1)) {
00759         outLampStart = 0;
00760         lampSt = 0;
00761     }    
00762     else if((flagWeld == 1) & (lampSt == 0)) {
00763         outLampStart = 1;
00764         lampSt = 1;
00765     }    
00766 }
00767