You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
2.8 KiB
C++

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

String Prcss_ALL_Read(){
String str = "";
str += "AI?:";
for (int i = 0; i < Size_AI; i++) {
char formattedNumber[5]; // 4자리 숫자 + 널 종료 문자
sprintf(formattedNumber, "%04X", Values_AI[i]); // 4자리로 고정된 형식의 문자열 생성
str += formattedNumber; // 형식화된 문자열 추가
str += ',';
}
str += RcvOK;
str += "DI?:";
char formattedNumber[5];
sprintf(formattedNumber, "%04X", Values_DI);
str += formattedNumber;
str += ',';
str += RcvOK;
str += "PV_0?:";
if(rcv_10_PV){
for (int i = 0; i < RS485_1_Rcv_size*2; i++) {
char formattedNumber[5];
sprintf(formattedNumber, "%04X", RS485_1_Values_PV[i]);
str += formattedNumber;
str += ',';
}
str += RcvOK;
}else{
str += RcvErr;
}
str += "SV_0?:";
if(rcv_10_SV){
for (int i = 0; i < RS485_1_Rcv_size*2; i++) {
char formattedNumber[5];
sprintf(formattedNumber, "%04X", RS485_1_Values_SV[i]);
str += formattedNumber;
str += ',';
}
str += RcvOK;
}else{
str += RcvErr;
}
return str + FIN;
}
String Prcss_DO_Write(unsigned int data[], int dataSize){
String str = "DO!:";
if(dataSize != 1){
str += RcvErr;
return str + FIN;
}
unsigned int data0 = data[0];
for (int bit = 0; bit < 16; bit++) {
digitalWrite(DoPin[bit], bitRead(data0, bit) ? HIGH : LOW);
}
str += RcvOK;
return str + FIN;
}
String Prcss_AO_Write(unsigned int data[], int dataSize){
String str = "AO!:";
int d = 2;
for(int i=0 ; i<dataSize ; i++){
AO_Write(i, data[i]);
}
str += RcvOK;
return str + FIN;
}
String Prcss_SV_Write(unsigned int data[], int dataSize){
String str = "SV!:";
msg_MC9_SV_set(data, dataSize);
str += RcvOK;
return str + FIN;
}
String Prcss_AT_Write(unsigned int data[], int dataSize){
String str = "AT!:";
msg_MC9_AT_set(data, dataSize);
str += RcvOK;
return str + FIN;
}
/*
String Prcss_AT_Write(bool onOff){
String str = "AT!:";
String message, cmd;
cmd = "10DWR,02,0302,0001,0501,";
if(onOff){
cmd += "0001";
}else{
cmd += "0000";
}
message = cmd;
message += sumMC9(message);
message = "" + message + CRLF;
write_buff_first(Buff_485_Wr, message);
str += RcvOK;
return str + FIN;
}
*/
String Prcss_RngAO(unsigned int data[], int dataSize){
String str = "RngAO!:";
int rng = 0;
int d = 20;
for(int i=0 ; i<dataSize ; i++){
if(i+1 < dataSize){
rng = (data[i] > data[i+1]) ? data[i] : data[i+1];
}else{
rng = data[i];
}
AO_setup(i, rng);
delay(d);
i++; // every 0 ch, not 1 ch.
}
str += RcvOK;
return str + FIN;
}
String Prcss_ChMC9(unsigned int data[], int dataSize){
String str = "ChMC9!:";
int d = 20;
for(int i=0 ; i<dataSize ; i++){
setupMC9_1(i, data[i]);
delay(d);
}
str += RcvOK;
return str + FIN;
}