int RKC_CommData ( int _ACT, int _ID, double *_Val) { int rLop = 0; int RTNval = 0; int BuffLEN = 0; char Buff[128]={0}; char BBC = 0x00; char dTRN[64] = {0}; static int Rs232Err = 0, NullPort = 0; switch (_ACT) { case Config: CloseCom(rkc.COM); if (Rs232Err = ReturnRS232Err (), Rs232Err < 0) return Rs232Err; OpenComConfig(rkc.COM, "", rkc.Baud, rkc.Pari, rkc.Dbit, rkc.Sbit, 512, 512); if (Rs232Err = ReturnRS232Err (), Rs232Err < 0) { NullPort = 1; return Rs232Err; } SetCTSMode(rkc.COM, rkc.Flc); if (Rs232Err = ReturnRS232Err (), Rs232Err < 0) return Rs232Err; SetComTime(rkc.COM, rkc.Tout); if (Rs232Err = ReturnRS232Err (), Rs232Err < 0) return Rs232Err; NullPort = 0; break; case getTP: Fmt(Buff, "%c%i[w2p0]%s[w2]%c", _EOT, (_ID & 0xFF), "M1", _ENQ); // MessagePopup("getTP",Buff); //DJ_Added_0502KB_12_57 break; case getSP: Fmt(Buff, "%c%i[w2p0]%s[w2]%c", _EOT, (_ID & 0xFF), "S1", _ENQ); break; case getAL1: Fmt(Buff, "%c%i[w2p0]%s[w2]%c", _EOT, (_ID & 0xFF), "A1", _ENQ); break; case getAL2: Fmt(Buff, "%c%i[w2p0]%s[w2]%c", _EOT, (_ID & 0xFF), "A2", _ENQ); break; case getAT: Fmt(Buff, "%c%i[w2p0]%s[w2]%c", _EOT, (_ID & 0xFF), "G1", _ENQ); break; case getST: Fmt(Buff, "%c%i[w2p0]%s[w2]%c", _EOT, (_ID & 0xFF), "G2", _ENQ); break; case setRUN: Fmt(Buff, "%c%i[w2p0]%c%s[w2]%f[p1]%c", _EOT, (_ID & 0xFF), _STX, "SR", *_Val, _ETX); break; case setSP: Fmt(Buff, "%c%i[w2p0]%c%s[w2]%f[p1]%c", _EOT, (_ID & 0xFF), _STX, "S1", *_Val, _ETX); break; case setAL1: Fmt(Buff, "%c%i[w2p0]%c%s[w2]%f[p1]%c", _EOT, (_ID & 0xFF), _STX, "A1", *_Val, _ETX); break; case setAL2: Fmt(Buff, "%c%i[w2p0]%c%s[w2]%f[p1]%c", _EOT, (_ID & 0xFF), _STX, "A2", *_Val, _ETX); break; case setAT: Fmt(Buff, "%c%i[w2p0]%c%s[w2]%f[p1]%c", _EOT, (_ID & 0xFF), _STX, "G1", *_Val, _ETX); break; case setST: Fmt(Buff, "%c%i[w2p0]%c%s[w2]%f[p1]%c", _EOT, (_ID & 0xFF), _STX, "G2", *_Val, _ETX); break; case setPB: Fmt(Buff, "%c%i[w2p0]%c%s[w2]%f[p1]%c", _EOT, (_ID & 0xFF), _STX, "PB", *_Val, _ETX); break; } if (NullPort) { *_Val = 0.00; } // Command Transfer Process if ((_ACT > 0x1F) && (NullPort == 0)) { // ========================================================= [ Set RKC Data ] // Flush Out Queue FlushOutQ (rkc.COM); Delay(0.5); // Count Buffer Length BuffLEN = StringLength (Buff); // Calc BBC BBC = 0x00; for (rLop=4; rLop < BuffLEN; rLop++) BBC ^= Buff[rLop]; // Append BBC Fmt ( Buff, "%s[a]<%c", BBC); BuffLEN +=1; // Sending Command ComWrt ( rkc.COM, Buff, BuffLEN); // Flush In Queue FlushInQ (rkc.COM); Delay(0.5); ComRd (rkc.COM, dTRN, 1); if (dTRN[0] == 0x06) RTNval = 0; // Sending OK else if (dTRN[0] == 0x15) RTNval = -10; // Sending Lost else RTNval = -1; // Connect Lost } else if ((_ACT > 0x0F) && (NullPort == 0)) { // ========================================================= [ Get RKC Data ] // Flush OUT Queue FlushOutQ (rkc.COM); Delay(0.5); // Send CMD ComWrt ( rkc.COM, Buff, 6); // Flush IN Queue FlushInQ (rkc.COM); Delay(0.5); // Receive CMD dTRN[0] = 0x00; ComRd (rkc.COM, dTRN, 11); Rs232Err = ReturnRS232Err(); if (ReturnRS232Err() == 0) Scan (dTRN ,"%s[i5]>%f", _Val); Delay(0.5); Fmt ( Buff, "%c%c", _EOT, 0x00); ComWrt (rkc.COM, Buff, 1); } return RTNval; }
int post(int run) { int ret_val; int test_item, index; int byte_in_queue ; // old: int byte_in_queue ; char portname[6]; //char hwID_limit[5] = {" "} ; char pos_capture[3000]; //char char_read ; double begin, end ; float testtime ; FillBytes(portname, 0, 5, 32) ; portname[5] = '\0' ; sprintf(portname,"COM%d",g_dev_serial_port) ; //test_item = InsertTestItem("RESET test", NULL, NULL, NULL, NULL); ret_val = ConfirmMessage ("Turn unit back on", "Press the Power button and the Reset button. Did the three LEDs flash?"); /******************************************************************************** if (ret_val == YES) UpdateTestItem(test_item, "RESET test", NULL, NULL, NULL, "PASS") ; else UpdateTestItem(test_item, "RESET test", NULL, NULL, NULL, "FAIL"); ****************************************************************************/ Delay(1.0) ; //test_item = InsertTestItem("Power On Self Test",NULL,NULL,NULL,NULL); begin = Timer() ; FillBytes(pos_capture, 0, 2999, 32); pos_capture[2999] = '\0' ; test_item = InsertTestItem("Opening device port",NULL,NULL,NULL,NULL); ret_val = OpenComConfig (g_dev_serial_port, portname, 115200, 0, 8, 1, 512, 512); if (ret_val < 0) { UpdateTestItem(test_item, "Opening UUT port", "ERROR", NULL, NULL, "FAIL") ; return FAILURE ; } else UpdateTestItem(test_item, "Opening UUT port", NULL, NULL, NULL, "PASS") ; if (!run) { ComWrtByte (1, 'n'); } else { ComWrtByte (1, 'Y'); test_item = InsertTestItem("Power On Self Test",NULL,NULL,NULL,NULL); SetComTime(g_dev_serial_port, 5.0) ; FlushInQ(g_dev_serial_port) ; FlushOutQ(g_dev_serial_port) ; //ComRd(g_dev_serial_port, pos_capture, 3000) ; for (index = 0; index < 2999; index++) { byte_in_queue = ComRdByte(g_dev_serial_port) ; if (byte_in_queue < 0) break ; // no more byte to read if ( (byte_in_queue == CR) || (byte_in_queue == LF) ) pos_capture[index] = 32 ; else pos_capture[index] = (char) byte_in_queue; } // for all chars in COM buffer index = FindPattern(pos_capture, 0, -1, "failed", 0, 0) ; if (index > 0) { //test_item = InsertTestItem("Power On Self Test",NULL,NULL,NULL,"FAILED"); UpdateTestItem(test_item,NULL,NULL,NULL,NULL,"FAIL"); return FAILURE ; } else //test_item = InsertTestItem("Power On Self Test",NULL,NULL,NULL,"PASS"); UpdateTestItem(test_item,NULL,NULL,NULL,NULL,"PASS"); } // else, perform post test return SUCCESS ; }