Посмотрите мой пример чтения показаний из весового терминала CAS CI-1560 https://owen.ru/forum/showthread.php...l=1#post306065
Код:
#define Alarm 300 // Number PSB from error flag
#define adrPR 16 // Addres PR200
#define adrRegPR 512 // Addres register "Weight"
WORD timeOut;
WORD status = 0;
BYTE byArr[44] = {' '};
char *strWeight = " 0";
int i = 0;
static short int Weight = 0;
//---- change timeout port of PLC (only for ModBus)
Read(HMI_LOCAL_MCH, 0, TYPE_PFW, 38, 0, TYPE_WORD, &timeOut);
if(timeOut == 1000) Write(HMI_LOCAL_MCH, 0, TYPE_PFW, 38, 0, TYPE_WORD, 200);
//----- Get string (22 bytes) from CAS1560
while(status != 22 && i <= 3) {
status = Receive(DOWNLOAD, byArr, 22, 1000, 100);
i++; //next try
PSW[500] = status; //debug only !!
PSW[501] = i; //debug only !!
}
//--- if three attempts were unsuccessful, set error flag for three seconds
if (i >= 3 && status != 22) {
SetPSB(Alarm);
Delay(3000);
ResetPSB(Alarm);
}
else if (byArr[20] =='\r' && byArr[21] =='\n') {
memcpy(strWeight, byArr +10, 7); //extract string weight
Weight = atoi(strWeight); //convert string to number
if (byArr[9] == '-') Weight = Weight * (-1);
//----
PSW[314] = Weight; //debug only !!
memcpy(&PSW[300], byArr, 22); //debug only !!
}
Leave(DOWNLOAD); //close port DOWNLOAD
//Delay(100);
//--- write weight in the register PR200
Write(PLC, adrPR, MODBUS_RTU_REG_4X, adrRegPR, 0, TYPE_WORD, Weight);
ЗЫ,
Прошу помочь с форматом команды или направить, где посмотреть
Еще один пример чтения (команда Receive)- Гипертерминал для панели СП https://owen.ru/forum/showthread.php...l=1#post247040