// чтение коэффициентов для счётчика Меркурий-230 bool ReadKoeffDeviceB_Special(void) { uchar i; if (QueryOpenB_Full(25) == 0) return(0); for (i=0; i<bMINORREPEATS; i++) { InitPush(0); PushChar(diCurr.bAddress); PushChar(8); PushChar(2); // чтение коэффициентов DelayOff(); QueryIO(1+4+2, 2+1+2); if (Input() == SER_GOODCHECK) break; if (fKey == true) return(0); } if (i == bMINORREPEATS) return(0); ShowPercent(50); // K трансформации dbKtrans = (InBuff(1)*0x100 + InBuff(2)) * (InBuff(3)*0x100 + InBuff(4)); // K преобразования dbKpulse = 2000; return(1); }
void ReadTopBNew(void) { // адрес обрабатываемого блока if (!UseBounds()) { dwBaseCurr = InBuff(1); dwBaseCurr <<= 12; dwBaseCurr += InBuff(2) << 4; ResetLimitsAux(ibDig); } else { if (mpboStartCan[ibDig] == false) { dwBaseCurr = InBuff(1); dwBaseCurr <<= 12; dwBaseCurr += InBuff(2) << 4; if (boShowMessages == true) sprintf(szLo," начало %05lX * ",dwBaseCurr); ResetLimitsAux(ibDig); } else { dwBaseCurr = mpcdwStartAbs32Can[ibDig]; if (boShowMessages == true) sprintf(szLo," начало %05lX ",dwBaseCurr); iwMajor = dwBaseCurr % 0x10000; AddDigRecord(EVE_PREVIOUS_TOP); } if (boShowMessages == true) DelayMsg(); } // индекс по получасовому массиву iwDigHou = 0; // счЄтчик получасов в выключенном состо¤нии iwMajor = 0; }
bool AutomaticN(void) { uchar i; for (i=0; i<bMINORREPEATS; i++) { InitPush(0); PushChar(0); PushChar(diCurr.bAddress); PushChar(8); PushChar(0); PushChar(0); PushChar(0); PushChar(0); PushChar(0); PushChar(0); PushChar(0); PushChar(0); QueryIO(5+8, 5+8); if (Input() == SER_GOODCHECK) break; if (fKey == true) return(0); } if (i == bMINORREPEATS) return(0); sprintf(szLo+1,"версия:"); szLo[ 9] = InBuff(3); szLo[10] = InBuff(4); szLo[11] = InBuff(5); szLo[12] = InBuff(6); szLo[13] = InBuff(7); DelayInf(); Clear(); for (i=0; i<bMINORREPEATS; i++) { QueryEnergyAbsN(); if (Input() == SER_GOODCHECK) break; if (fKey == true) return(0); } if (i == bMINORREPEATS) return(0); ShowPercent(50); ReadEnergyN(); mpdwBase[ibDig] = mpdwChannelsA[0]; return(1); }
serial Input31(void) { InputStart(); InitWaitAnswer(); while (1) { if (fKey == true) { mpSerial[ibPort] = SER_BADLINK; break; } ResetWatchdog(); ShowWaitAnswer(1); if (GetWaitAnswer()) { mpSerial[ibPort] = SER_BADLINK; break; } if (mpSerial[ibPort] == SER_INPUT_MASTER) { if ((InBuff(0) == 0x7E) && (IndexInBuff() > 3) && (IndexInBuff() == InBuff(1)+4)) mpSerial[ibPort] = SER_BADLINK; } if (mpSerial[ibPort] == SER_POSTINPUT_MASTER) { uchar bCrc = MakeCrc8Bit31InBuff(1, CountInBuff()-1); if (bCrc == 0) { Unpack31(); InputGoodCheck(); mpSerial[ibPort] = SER_GOODCHECK; } else mpSerial[ibPort] = SER_BADCHECK; break; } else if (mpSerial[ibPort] == SER_BADLINK) { uchar bCrc = MakeCrc8Bit31InBuff(1, IndexInBuff()-1); if (bCrc == 0) { Unpack31(); InputGoodCheck(); mpSerial[ibPort] = SER_GOODCHECK; } else mpSerial[ibPort] = SER_BADCHECK; break; } else if (mpSerial[ibPort] == SER_OVERFLOW) break; } MonitorIn(); return mpSerial[ibPort]; }
uchar GetModemAnswer(void) { uchar i,j; uchar w; if ((IndexInBuff() >= 2) && (IndexInBuff() <= 4)) { w = 0; for (i=0; i<IndexInBuff()-1; i++) { j = InBuff(i); if ((j >= '0') && (j <= '9')) w = w*10 + ToChar(j); else { w = 0xFF; break; } } } else w = 0xFE; if (w < 0x100) return(w); else return(0xFD); }
bool ReadTimeDateD_Short(void) { DelayOff(); QueryOpenD(); if (ExtInput() != SER_GOODCHECK) return(0); DelayOff(); QueryPasswordD(); if (ExtInput() != SER_GOODCHECK) return(0); if (InBuff(2) != 0) return(0); DelayOff(); QueryTimeD(); if (ExtInput() != SER_GOODCHECK) return(0); ReadTimeD(); QueryCloseD(0); return(1); }
bool AutomaticK(void) { uchar i,bT; for (i=0; i<bMINORREPEATS; i++) { QueryCloseK(); QueryOpenK(); if (BccInput() == SER_GOODCHECK) break; if (fKey == true) return(0); bT = InBuff(IndexInBuff() - 1) & 0x7F; if ((bT == '\r') || (bT == '\n')) break; } if (i == bMINORREPEATS) return(0); ReadOpenK(); QueryCloseK(); dbKtrans = 1; // K трансформации reBuffA = 5000; // K преобразования Delay(1000); SetCanalsAll(); // сохранение К преобразования и К трасформации return(1); }
void SaveReviewBuff(uchar ibMin, uchar ibMax) { MonitorString("\n save review buff"); memset(&mmbBuff[CurrIdx()], 0, REVIEW_BUFF_SIZE); uchar i; for (i=ibMin; i<=ibMax; i++) { ASSERT(i < REVIEW_BUFF_SIZE); mmbBuff[CurrIdx()][i] = InBuff(i); } }
bool TestReviewBuff(uchar ibMin, uchar ibMax) { uchar i; for (i=ibMin; i<=ibMax; i++) { ASSERT(i < REVIEW_BUFF_SIZE); if (mmbBuff[CurrIdx()][i] != InBuff(i)) { MonitorString("\n test review buff: false"); return false; } } MonitorString("\n test review buff: true"); return true; }
void ShowModemQuality(uchar ibPrt) { Clear(); ibPort = ibPrt; diCurr.ibPort = ibPrt; if (SafeReadModemQuality(ibPrt) != 1) Error(); else { uchar i; for (i=0; i<IndexInBuff()-1; i++) { szLo[i] = InBuff(i); } } }
bool ChangeSpeed34(void) { InitPush(0); PushChar(0); PushChar(0x64); PushChar(0x00); PushChar(0x46); PushChar(0x00); PushChar(0x09); QueryIO(3+18+2, 6+2); if (Input() != SER_GOODCHECK) return(0); Beep(); ShowFoundNumber(InBuff(0)); return(1); }
void UnpackW(bool fShow, uchar bOffset) { if (cbHeaderBcc == 0) return; if (cwInBuffBcc == IndexInBuff()) return; cwInBuffBcc = IndexInBuff(); if ((fShow == true) && (IndexInBuff() > 60)) sprintf(szLo," прием: %-4u ",IndexInBuff()); if (IndexInBuff() > 2) { InitPop(1); uint j = 0; uchar i; for (i=0; i<IndexInBuff()-2; i++) { if (PopChar0Bcc() == ')') j++; // MonitorString("\n"); MonitorCharDec(j); MonitorString(" ? "); MonitorCharDec(cbHeaderBcc); // MonitorString(" "); MonitorCharDec(i); MonitorString(" + "); MonitorCharDec(bOffset); MonitorString(" ? "); MonitorCharDec(IndexInBuff()); if ((j == cbHeaderBcc) && (i+bOffset == IndexInBuff()) && (InBuff(IndexInBuff()-2) == 0x03)) { SetCountInBuff(i+bOffset); if ((fShow == true) && (IndexInBuff() > 60)) sprintf(szLo," прием: %-4u ",IndexInBuff()); MonitorIn(); InputMode(); mpSerial[ibPort] = SER_POSTINPUT_MASTER; break; } } } }
// открытие канала для счётчиков ABB Альфа bool OpenDeviceD(void) { uchar i; for (i=0; i<bMAJORREPEATS; i++) { ShowPercent(i); DelayOff(); QueryOpenD(); if (ExtInput() == SER_GOODCHECK) break; if (fKey == true) return(0); } if (i == bMAJORREPEATS) return(0); ShowPercent(48); for (i=0; i<bMINORREPEATS; i++) { DelayOff(); QueryPasswordD(); if (ExtInput() == SER_GOODCHECK) break; if (fKey == true) return(0); } if (i == bMINORREPEATS) return(0); ShowPercent(49); if (InBuff(2) != 0) return(0); ShowPercent(50); return(1); }
void ShowResponseCRC(uchar bState) { if (wProgram == bTEST_RESPONSE) { #ifdef MODBUS sprintf(szHi,"Порт %u: Mod%03u %u",ibPort+1,InBuff(3),bState); #else if (InBuff(4) == 0xFF) sprintf(szHi,"Порт %u: CFF%03u %u",ibPort+1,InBuff(5),bState); else if (InBuff(4) == 0xFE) sprintf(szHi,"Порт %u: CFE%03u %u",ibPort+1,InBuff(5),bState); else sprintf(szHi,"Порт %u: CRC%03u %u",ibPort+1,InBuff(4),bState); #endif ibPortActive = ibPort; HideCurrTime(0); } }
// задание параметров для счётчиков ABB Альфа bool AutomaticD(void) { uchar i; if (OpenDeviceD() == 0) return(0); for (i=0; i<bMINORREPEATS; i++) { DelayOff(); QueryConfigD(); if (ExtInput() == SER_GOODCHECK) break; if (fKey == true) return(0); } if (i == bMINORREPEATS) return(0); ShowPercent(51); if (InBuff(2) != 0) return(0); ShowPercent(52); ReadConfigD(); if (ReadAllEnergyD() == 0) return(0); QueryCloseD(0); MakeEnergyD(); SetCanReal(mpreCount,ibDig); return(1); }
// чтение коэффициентов для счётчика Меркурий-230 bool ReadKoeffDeviceB(void) { uchar i; if (QueryOpenB_Full(25) == 0) return(0); for (i=0; i<bMINORREPEATS; i++) { InitPush(0); PushChar(diCurr.bAddress); PushChar(8); PushChar(2); // чтение коэффициентов DelayOff(); QueryIO(1+4+2, 2+1+2); if (Input() == SER_GOODCHECK) break; if (fKey == true) return(0); } if (i == bMINORREPEATS) return(0); ShowPercent(50); // K трансформации dbKtrans = (InBuff(1)*0x100 + InBuff(2)) * (InBuff(3)*0x100 + InBuff(4)); for (i=0; i<bMINORREPEATS; i++) { // первый вариант: ответ 3 байта InitPush(0); PushChar(diCurr.bAddress); PushChar(8); PushChar(0x12); // чтение постоянной счётчика DelayOff(); QueryIO(1+3+2, 2+1+2); if (Input() == SER_GOODCHECK) break; if (fKey == true) return(0); // второй вариант: ответ 6 байт InitPush(0); PushChar(diCurr.bAddress); PushChar(8); PushChar(0x12); // чтение постоянной счётчика DelayOff(); QueryIO(1+6+2, 2+1+2); if (Input() == SER_GOODCHECK) break; if (fKey == true) return(0); } if (i == bMINORREPEATS) return(0); ShowPercent(75); switch (InBuff(3) & 0x0F) // K преобразования { case 1: dbKpulse = 10000; break; case 2: dbKpulse = 2000; break; case 3: dbKpulse = 1000; break; case 4: dbKpulse = 2000; break; default: return(0); } mpdbLevel[ibDig] = dbKpulse / 1000; return(1); }
bool DoneProfileW(void) { return ((IndexInBuff() == 10) && ((InBuff(1) & 0x7F) == 'E') && ((InBuff(2) & 0x7F) == 'R') && ((InBuff(3) & 0x7F) == 'R')); }
// чтение коэффициентов для счётчика СЭТ-4ТМ bool ReadKoeffDeviceA(void) { uchar i; if (QueryOpenA_Full(25) == 0) return(0); for (i=0; i<bMINORREPEATS; i++) { InitPush(0); PushChar(diCurr.bAddress); PushChar(8); PushChar(2); // чтение коэффициентов DelayOff(); QueryIO(1+10+2, 2+1+2); if (Input() == SER_GOODCHECK) break; if (fKey == true) return(0); } if (i == bMINORREPEATS) return(0); ShowPercent(50); // K трансформации dbKtrans = (InBuff(1)*0x100 + InBuff(2)) * (InBuff(3)*0x100 + InBuff(4)); for (i=0; i<bMINORREPEATS; i++) { InitPush(0); PushChar(diCurr.bAddress); PushChar(8); PushChar(0x12); // чтение постоянной счётчика DelayOff(); QueryIO(1+3+2, 2+1+2); if (Input() == SER_GOODCHECK) break; if (fKey == true) return(0); } if (i == bMINORREPEATS) return(0); ShowPercent(75); switch (InBuff(2) & 0x0F) // K преобразования { case 0: dbKpulse = 10000; break; case 1: dbKpulse = 50000; break; case 2: dbKpulse = 2500; break; case 3: dbKpulse = 1000; break; // 12500 case 4: dbKpulse = 2000; break; // ? case 5: dbKpulse = 500; break; // ? default: return(0); } return(1); }
// чтение коэффициентов для счётчика СС-301 bool ReadKoeffDeviceC(void) { uchar i; for (i=0; i<bMINORREPEATS; i++) { DelayOff(); QueryOpenC(); // открытие канала связи if (RevInput() == SER_GOODCHECK) break; if (fKey == true) return(0); } if (i == bMINORREPEATS) return(0); ShowPercent(25); for (i=0; i<bMINORREPEATS; i++) { DelayOff(); InitPush(0); PushChar(diCurr.bAddress); PushChar(3); PushChar(34); PushChar(0); PushChar(0); PushChar(0); RevQueryIO(4+18+2, 3+3+2); if (RevInput() == SER_GOODCHECK) break; if (fKey == true) return(0); } if (i == bMINORREPEATS) return(0); ShowPercent(50); combo32 co; co.mpbBuff[0] = InBuff(4); co.mpbBuff[1] = InBuff(5); co.mpbBuff[2] = InBuff(6); co.mpbBuff[3] = InBuff(7); dbKtrans = co.dwBuff; co.mpbBuff[0] = InBuff(8); co.mpbBuff[1] = InBuff(9); co.mpbBuff[2] = InBuff(10); co.mpbBuff[3] = InBuff(11); dbKtrans *= co.dwBuff; // K трансформации for (i=0; i<bMINORREPEATS; i++) { DelayOff(); InitPush(0); PushChar(diCurr.bAddress); PushChar(3); PushChar(24); PushChar(0); PushChar(0); PushChar(0); RevQueryIO(4+8+2, 3+3+2); if (RevInput() == SER_GOODCHECK) break; if (fKey == true) return(0); } if (i == bMINORREPEATS) return(0); ShowPercent(60); dbKpulse = InBuff(8) + InBuff(9)*0x100; dbKpulse = 1000000/dbKpulse; // K преобразования return(1); }
void RunResponseCRC(void) { if (mpSerial[ibPort] == SER_POSTINPUT_SLAVE) { mpSerial[ibPort] = SER_BEGIN; ShowResponseCRC(bSTA_BEGIN); MakeCRC16InBuff( 0, IndexInBuff() ); if ((bCRCHi != 0) || (bCRCLo != 0)) { ShowResponseCRC(bSTA_BADCRC); return; } bInBuff0 = InBuff(0); bInBuff1 = InBuff(1); bInBuff2 = InBuff(2); bInBuff3 = InBuff(3); bInBuff4 = InBuff(4); bInBuff5 = InBuff(5); bInBuff6 = InBuff(6); bInBuff7 = InBuff(7); bInBuff8 = InBuff(8); bInBuff9 = InBuff(9); bInBuffA = InBuff(10); bQuery = bInBuff4; if ((bInBuff0 != 0) || (bInBuff1 != 0)) { if ((bInBuff0 != bLogical) || (bInBuff1 != 0)) { ShowResponseCRC(bSTA_BADNUMBER); return; } } if (bInBuff2 + bInBuff3*0x100 != IndexInBuff()) { ShowResponseCRC(bSTA_BADSIZE); Result(bRES_BADSIZE); return; } if ((fDsblAnswer == true) && IsAnswerDisabled()) { if (bInBuff4 != bINQ_ENBL_ANSWER) { ShowResponseCRC(bSTA_BUSY); Result(bRES_BUSY); return; } } ShowResponseCRC(bSTA_OK); Response0_CRC(); } }