From f71b963851ddbdf36ba99fcbf11727c2f5c16d2f Mon Sep 17 00:00:00 2001 From: chi Date: Thu, 24 Apr 2025 11:51:55 +0900 Subject: [PATCH] .. --- .../Arduino_CallButton_Line.A.ino | 597 ----------------- Arduino_CallButton/ReadMe.txt | 1 - Arduino_PLC/Arduino_PLC.ino | 105 --- Arduino_PLC/FontList.txt | 120 ---- Arduino_PLC/HmiClass.cpp | 569 ---------------- Arduino_PLC/HmiClass.h | 59 -- Arduino_PLC/IO.cpp | 386 ----------- Arduino_PLC/IO.h | 136 ---- Arduino_PLC/ReadMe.txt | 1 - Arduino_PLC/StructInfo.txt | 0 Arduino_PLC/UtilClass.cpp | 21 - Arduino_PLC/UtilClass.h | 17 - Arduino_PLC/VarClass.cpp | 271 -------- Arduino_PLC/VarClass.h | 119 ---- Arduino_PLC/motor.cpp | 256 ------- Arduino_PLC/motor.h | 52 -- Cs_HMI/AGVCSharp.sln | 15 + Cs_HMI/Project/AGV4.csproj | 9 +- Cs_HMI/Project/CSetting.cs | 14 +- Cs_HMI/Project/CtlAuto.cs | 126 ++-- Cs_HMI/Project/Device/Xbee _OLD.cs | 402 +++++++++++ Cs_HMI/Project/Device/Xbee.cs | 496 ++++---------- Cs_HMI/Project/Dialog/fLog.cs | 4 +- Cs_HMI/Project/PUB.cs | 11 +- Cs_HMI/Project/StateMachine/AGVPosition.cs | 145 ++++ .../StateMachine/AGVProtocolHandler.cs | 107 +++ .../Project/StateMachine/AGVStateManager.cs | 159 +++++ Cs_HMI/Project/StateMachine/Step/_SM_RUN.cs | 27 +- .../StateMachine/Step/_SM_RUN_CHGOFF.cs | 5 +- .../StateMachine/Step/_SM_RUN_GOCHARGE.cs | 17 +- .../Step/_SM_RUN_GOCHARGECHECK.cs | 1 + .../StateMachine/Step/_SM_RUN_GODOWN.cs | 83 ++- .../StateMachine/Step/_SM_RUN_GOHOME.cs | 7 +- .../Project/StateMachine/Step/_SM_RUN_GOUP.cs | 89 ++- .../StateMachine/Step/_SM_RUN_READY.cs | 7 +- .../StateMachine/Step/_SM_RUN_RESET.cs | 1 + .../Project/StateMachine/Step/_SM_RUN_SYNC.cs | 1 + .../Project/StateMachine/Step/_STEP_CLOSE.cs | 4 +- Cs_HMI/Project/StateMachine/_AGV.cs | 1 + Cs_HMI/Project/StateMachine/_BMS.cs | 1 + Cs_HMI/Project/StateMachine/_DIO.cs | 115 +--- Cs_HMI/Project/StateMachine/_Flag.cs | 7 +- Cs_HMI/Project/StateMachine/_Loop.cs | 3 +- Cs_HMI/Project/StateMachine/_SPS.cs | 63 +- Cs_HMI/Project/StateMachine/_TMDisplay.cs | 29 +- Cs_HMI/Project/ViewForm/fAuto.cs | 19 +- Cs_HMI/Project/ViewForm/fFlag.cs | 1 + Cs_HMI/Project/ViewForm/fIO.Designer.cs | 180 +++-- Cs_HMI/Project/ViewForm/fIO.cs | 86 +-- Cs_HMI/Project/ViewForm/fIO.resx | 6 +- Cs_HMI/Project/ViewForm/fManual.cs | 21 +- Cs_HMI/Project/fMain.cs | 75 +-- Cs_HMI/Project/fSetup.Designer.cs | 125 +--- Cs_HMI/Project/fSetup.cs | 18 +- Cs_HMI/SubProject/AGV/Command.cs | 7 +- Cs_HMI/SubProject/AGV/EnumData.cs | 2 + Cs_HMI/SubProject/AGV/NARUMI.csproj | 4 + Cs_HMI/SubProject/AGV/Narumi.cs | 3 +- Cs_HMI/SubProject/AGV/Structure/Signals.cs | 12 + Cs_HMI/SubProject/CommData/Enum.cs | 5 +- Cs_HMI/SubProject/CommData/Var.cs | 622 +++++++++--------- Cs_HMI/SubProject/ProPLC/FakePLC.cs | 8 +- 62 files changed, 1748 insertions(+), 4105 deletions(-) delete mode 100644 Arduino_CallButton/Arduino_CallButton_Line.A.ino delete mode 100644 Arduino_CallButton/ReadMe.txt delete mode 100644 Arduino_PLC/Arduino_PLC.ino delete mode 100644 Arduino_PLC/FontList.txt delete mode 100644 Arduino_PLC/HmiClass.cpp delete mode 100644 Arduino_PLC/HmiClass.h delete mode 100644 Arduino_PLC/IO.cpp delete mode 100644 Arduino_PLC/IO.h delete mode 100644 Arduino_PLC/ReadMe.txt delete mode 100644 Arduino_PLC/StructInfo.txt delete mode 100644 Arduino_PLC/UtilClass.cpp delete mode 100644 Arduino_PLC/UtilClass.h delete mode 100644 Arduino_PLC/VarClass.cpp delete mode 100644 Arduino_PLC/VarClass.h delete mode 100644 Arduino_PLC/motor.cpp delete mode 100644 Arduino_PLC/motor.h create mode 100644 Cs_HMI/Project/Device/Xbee _OLD.cs create mode 100644 Cs_HMI/Project/StateMachine/AGVPosition.cs create mode 100644 Cs_HMI/Project/StateMachine/AGVProtocolHandler.cs create mode 100644 Cs_HMI/Project/StateMachine/AGVStateManager.cs diff --git a/Arduino_CallButton/Arduino_CallButton_Line.A.ino b/Arduino_CallButton/Arduino_CallButton_Line.A.ino deleted file mode 100644 index 1dd1d67..0000000 --- a/Arduino_CallButton/Arduino_CallButton_Line.A.ino +++ /dev/null @@ -1,597 +0,0 @@ -#include -#include "Arduino.h" -#define DEBUG - -bool cstate[3]; // 현재 상태(이전 상태와 비교하여 상태변화를 확인한다) -bool pstate[3]; // 이전 상태 -bool bchange[3]; //특정핀의 상태가 변경되었는가? -unsigned long clicktime[3]; //각 버튼 down 상태의 밀리초를 저장한다(롱 클릭 시간 확인용) -unsigned long ontime = 0; -unsigned long ledtime = 0; - -//bool bCharge = false; //클라이언트 7번 -bool bHWError = false; //클라이언트 8번 -bool bSelected = false; //현재 선택된 클라이언트 (LED가 깜박인다) -bool bEnbCall =false; //콜 가능여부 -bool runtimeledon=false; -String version = "2411291722"; -String recvbuffer = ""; -uint8_t clientno = 0; -uint8_t offmode = 0; -uint8_t clickcnt = 0; - -int pinIn[3] = { 2, 3 , 4 }; -int pinOut[3] = { 5, 6 , 7 }; - - -void setup() { - -delay(2000); - - -#ifdef DEBUG - Serial.begin(19200); -#endif -Serial1.begin(9600); - - //; Serial.println("Setup Start"); - for (int i = 0; i < 3; i++) - { - pinMode(pinIn[i], INPUT_PULLUP); - pinMode(pinOut[i], OUTPUT); - digitalWrite(pinOut[i], HIGH); //처음켜지면 ON상태로 한다. - cstate[i] = false; - pstate[i] = false; - clicktime[i] = 0; - } - - //digitalWrite(13,HIGH); - -/// Serial.println("Serial1 Wait"); -#ifdef DEBUG - clicktime[0] = millis(); - while (!Serial) { - unsigned long runtime = millis() - clicktime[0]; - if (runtime >= 1000) { - //bSerial=false; - // Serial.println("Serial1 timeout"); - break; - } - // wait for serial port to connect. Needed for native USB port only - } -#endif - - //digitalWrite(13,LOW); - clientno = EEPROM.read(0); //내부롬의 0번주소에서 클라이언트 번호를 확인한다. -//#ifdef DEBUG - Serial.print("AGV Caller v");// 1904020000"); - Serial.println(version); - Serial.print("ready #"); - Serial.print(clientno); - Serial.println(); -//#endif - //초기화 완료되면 oFF 한다. - digitalWrite(pinOut[0], LOW); - digitalWrite(pinOut[1], LOW); - digitalWrite(pinOut[2], LOW); - offmode = 0; - - digitalWrite(13,LOW); -} - - -void loop() { - - - #ifdef DEBUG - unsigned long runtimeled = millis() -ledtime; - if(runtimeled > 200) - { - if(runtimeledon==true) - { - digitalWrite(13,LOW); - runtimeledon=false; - }else{ - digitalWrite(13,HIGH); - runtimeledon=true; - } - runtimeled= millis(); - } - #endif - - //버튼입력상태를 확인한다. - for (int i = 0; i < 3; i++) - { - cstate[i] = !digitalRead(pinIn[i]); - if (cstate[i] != pstate[i]) - { - /*Serial.print("#"); - Serial.print(pinIn[i]); - Serial.print(" changed"); - Serial.println(cstate[i]);*/ - - bchange[i] = true; - - if (cstate[i]) //클릭시 - { - clicktime[i] = millis(); - //Serial.print("SET TIME #"); - //Serial.print(i); - //Serial.println(); - } - } - } - - //버튼 상태변화를 감지 - if (cstate[0] && cstate[1]) //두버튼이 동시에 눌려있다면 디버그모드 진입여부를 확인한다. - { - unsigned long time1 = millis() - clicktime[0]; - unsigned long time2 = millis() - clicktime[1]; - if (time1 > 3000 && time2 > 3000) - { - if (offmode == 0) - { - //OFF 상태일때에는 시리얼 버퍼처리를 하지 않는다. - offmode = 1; - #ifdef DEBUG - Serial.println("ENTER MODE SELECT"); - #endif - } - } - //동시에 눌려있지만 아직 지정 시간전이므로 처리하지 않는다. - } - else if (cstate[0] || cstate[1] || cstate[2]) //버튼이 하나만 눌려있을때 - { - if (offmode == 2) //client set mode - { - if (cstate[0] && bchange[0]) - { - clickcnt += 1; - #ifdef DEBUG - Serial.print("Click Count = "); - Serial.println(clickcnt); - #endif - } - else if (cstate[1] && bchange[1]) - { - //두번째 버튼을 눌렀다면 완료를 의미한다. - clientno = clickcnt; - SaveNo(); //현재 값을 저장 해준다. - - //선택된 번호를 깜박임으로 알려준다. - delay(100); - digitalWrite(pinOut[0], LOW); - digitalWrite(pinOut[1], LOW); - delay(1000); - for (uint8_t i = 1; i <= clientno; i++) - { - digitalWrite(pinOut[0], HIGH); - delay(500); - digitalWrite(pinOut[0], LOW); - delay(500); - } - #ifdef DEBUG - Serial.print("New Client Complete No="); - Serial.println(clientno); - #endif - offmode = 0; //다시 처음상태로 이동 - } - - } - else if (offmode == 3) //off mode - { - if (bchange[0] || bchange[1]) - { - Serial1.begin(9600); //re open port - #ifdef DEBUG - Serial.println("OFF MODE DISABLE -> NORMAL MODE"); - #endif - offmode = 0; //일반상태로 전환 - } - } - else if (offmode == 1) //mod select - { - if (bchange[0] && cstate[0]) //0번버튼이 ON 되었다면 번호편집모드로 전환 - { - #ifdef DEBUG - Serial.println("NO. SET MODE"); - #endif - clickcnt = 0; //클릭횟수를 초기화 - offmode = 2; - } - else if (bchange[1] && cstate[1]) //1번버튼이 ON 되었다면 OFF 모드로 전환 - { - Serial1.end(); - #ifdef DEBUG - Serial.println("OFF MODE : Disable Serial for xbee"); - #endif - offmode = 3; - } - } - else if (offmode == 0) { //일반 모드일때 하나만 눌렸다면 해당 버튼 명령을 전송한다. - - //uint8_t clientascii = (uint8_t)(clientno + 30); - - if (bchange[0] && cstate[0]) - { - - #ifndef DEBUG - digitalWrite(13,HIGH); - delay(200); - digitalWrite(13,LOW); - #endif - - Serial1.clearWriteError(); - Serial1.write(0x02); - Serial1.print(clientno); - Serial1.print('1'); //call - Serial1.write(0x03); - Serial1.flush(); - - #ifdef DEBUG - Serial.print("SEND CALL #"); - Serial.println(clientno); - #endif - } - else if (bchange[1] && cstate[1]) - { - - #ifndef DEBUG - digitalWrite(13,HIGH); - delay(200); - digitalWrite(13,LOW); - #endif - - Serial1.clearWriteError(); - Serial1.write(0x02); - Serial1.print(clientno); - Serial1.print('0'); //call - Serial1.write(0x03); - Serial1.flush(); -#ifdef DEBUG - Serial.print("SEND CANCEL#"); - Serial.println(clientno); - #endif - } - else if (bchange[2] && cstate[2]) //QA진행 버튼이 눌렸을때 - { - - #ifndef DEBUG - digitalWrite(13,HIGH); - delay(200); - digitalWrite(13,LOW); - #endif - - Serial1.clearWriteError(); - Serial1.write(0x02); - Serial1.print(clientno); - Serial1.print('2'); //go qa - Serial1.write(0x03); - Serial1.flush(); -#ifdef DEBUG - Serial.print("SEND QA#"); - Serial.println(clientno); - #endif - } - } - } - - //Serial.print("mode="); - //Serial.println(offmode); - //LED상태 조정 - switch (offmode) - { - case 0: //일반 상태값(버튼을 누르면 해당 버튼의 LED를 조정한다) - digitalWrite(pinOut[0], cstate[0]); - digitalWrite(pinOut[1], cstate[1]); - digitalWrite(pinOut[2], cstate[2]); - //Serial.print("led 3 stat="); - //Serial.println(cstate[2]); - break; - case 1: //모드 선택 상태( 이때 OK를 누르면 번호셋, CANCEL을 누르면 OFF 상태로) - if (digitalRead(pinOut[0]) == true) - { - digitalWrite(pinOut[1], HIGH); - digitalWrite(pinOut[0], LOW); - } - else { - digitalWrite(pinOut[0], HIGH); - digitalWrite(pinOut[1], LOW); - } - delay(100); - break; - case 2: //클라이언트 번호 설정 모드 - 적색만 깜박이고 녹색의 클릭횟수로 번호를 설정한다. - if (digitalRead(pinOut[1]) == true) - digitalWrite(pinOut[1], LOW); - else - digitalWrite(pinOut[1], HIGH); - break; - delay(100); - case 3: //OFF 상태일때에는 LED를 서로 ON/OFF 한다. - if (digitalRead(pinOut[0]) == true) - { - digitalWrite(pinOut[1], LOW); - digitalWrite(pinOut[0], LOW); - } - else { - digitalWrite(pinOut[0], HIGH); - digitalWrite(pinOut[1], HIGH); - } - delay(100); - } - - - //상태변환 여부를 초기화 - if (bchange[0]) pstate[0] = cstate[0]; - if (bchange[1]) pstate[1] = cstate[1]; - if (bchange[2]) pstate[2] = cstate[2]; - bchange[0] = false; - bchange[1] = false; - bchange[2] = false; - - //일반모드일때 처리 내역 - if (offmode == 0) - { - unsigned long runtime = millis() - ontime; - - //CALL가능하면 3번 LED를 ON 한다 230119 - if(bEnbCall) - { - digitalWrite(pinOut[2],HIGH); - } else{ - if(cstate[2]) - digitalWrite(pinOut[2],HIGH); - else - digitalWrite(pinOut[2],LOW); - } - - //현재 개체가 AGV선택개체라면 LED를 깜박거려서 표시를 해준다.(녹색버튼기준) - if (bHWError) - { - //하드웨어 오류 발생시에는 적색을 깜박거린다.(녹색:OFF) - digitalWrite(pinOut[0], LOW); //녹색은 끈다. - - //적색을 깜박인다.(1초주기로 ON/OFF 한다) - bool state = digitalRead(pinOut[1]); - if (runtime >= 250) //190319 - { - if (state) digitalWrite(pinOut[1], LOW); - else digitalWrite(pinOut[1], HIGH); - ontime = millis(); - } - } - else if (bSelected) - { - digitalWrite(pinOut[1], HIGH); //적색은 일단 켜둔다. - - //선택된 개체일때에는 적색은 켜고 녹색은 끔박인다. - bool state = digitalRead(pinOut[0]); - - //500ms 단위로 깜박인다. - if (runtime >= 500) //190319 - { - if (state) digitalWrite(pinOut[0], LOW); - else digitalWrite(pinOut[0], HIGH); - ontime = millis(); - } - } - else { - //선택개체가 아니라면 LED를 모두 OFF해준다. - for (int i = 0; i < 2; i++) - { - if (digitalRead(pinIn[0]) != digitalRead(pinOut[0])) - cstate[i] = !cstate[i]; //이전상태값을 반전시켜줌으로 써 다음 루프때 LED가 꺼지게 한다. - } - } - } - - //외부디버그 명령을 처리한다. - #ifdef DEBUG - CheckRemoteDebugCommand(); - #endif - CheckReceiveXbee(); - delay(100); -} - -void CheckRemoteDebugCommand() -{ - if (Serial.available() > 0) - { - int recv = Serial.read(); - if (recv == 0x0A || recv == 0x0D) - { - RunCommand(); - recvbuffer = ""; - } - else { - recvbuffer += (char)recv; - } - } -} - -String buffer = ""; -int kitNo = 0; -int incomingByte = 0; -void CheckReceiveXbee() -{ - //수신된 자료가 잇는지 체크한다. -#ifndef DEBUG - digitalWrite(13,HIGH); -#endif - - while (Serial1.available() > 0) { - incomingByte = Serial1.read(); - -#ifdef DEBUG - Serial.print("[RX]"); - Serial.println(incomingByte, HEX); - -#endif - - //stx ,etx 는 hex 처리하고 번호와 값을 ascii처리함 - if (incomingByte == 0x02) - { - buffer = ""; - } - else if (incomingByte == 0x03) { - - //ETX값이나 전체 길이가 4가아니라면 추가해야함 - byte clientno = (byte)(buffer.substring(0, 1).toInt()); - char clientval = buffer[1];// .substring(1, 2).toInt()); - char enablecall = '0'; //콜가능여부 추가 230119 - - //데이터가 3바이트라면 콜 가능상태로 전송된 경우이다 230119 - if(buffer.length() > 2) - { - enablecall = buffer[2]; - } - - NewMsgEvent(clientno, clientval,enablecall); - break; - } - else{ - buffer += (char)incomingByte; //문자를 누적시킨다. - } - } - - #ifndef DEBUG - digitalWrite(13,LOW); - #endif -} - -/* 190319 */ -void NewMsgEvent(uint8_t no, char value,char canCall) -{ - if (no == 1) return; //충전기관련 코드는 처리 하지 않는다. 190417 - else if (no == 8) //AGV가 HW에러 발생시 이 값을 전송한다. - { - if (bHWError == false) bHWError = true; - #ifdef DEBUG - if (value == '1')//system error - { - Serial.println("FLAG ON : H/W ERROR"); - } - else { - Serial.println("FLAG ON : AGV MANUAL MODE"); - } - #endif - return; - } - - //그외 나머지 상태에는 오류사항을 해제 해준다. - if (bHWError == true) - { - bHWError = false; - #ifdef DEBUG - Serial.println("FLAG OFF : H/W ERROR OFF"); - #endif - } - - bEnbCall = (canCall == '1'); - - //누군가가 지정되어있다. - if (value == '1') - { - if (no != clientno) //해당 번호가 내 번호와 일치하지 않는다면 내가 지정된 경우가 아니다. - { - //서버로부터 어떠한 개체가 켜졌는데. 그게 내가 아니라면 나는 OFF 한다. - if (bSelected) bSelected = false; - #ifdef DEBUG - Serial.print("Selected Off by Another ON No="); - Serial.println(no); - #endif - } - else { - bSelected = true; //내 번호가 켜졌으므로 선택됨으로 한다. - #ifdef DEBUG - Serial.print("Selected On No="); - Serial.println(no); - #endif - } - } - else if (value == '0') //누군가가 OFF 되어있다. - { - if (no == clientno) - { - //내가 꺼졋음을 보내왔다. - bSelected = false; - #ifdef DEBUG - Serial.println("Selected Off"); - #endif - } - } -} - -void RunCommand() -{ - - Serial.print("Remote Control : "); - Serial.println(recvbuffer); - - if (recvbuffer == "on") - { - Serial.print("on clientno = "); - Serial.println(clientno); - NewMsgEvent(clientno, '1','1'); - } - else if (recvbuffer == "callon") - { - Serial.print("on clientno = "); - Serial.println(clientno); - NewMsgEvent(clientno, '0','1'); - } - else if (recvbuffer == "calloff") - { - Serial.print("on clientno = "); - Serial.println(clientno); - NewMsgEvent(clientno, '0','0'); - } - else if (recvbuffer == "off") { - Serial.print("off clientno = "); - Serial.println(clientno); - NewMsgEvent(clientno, '0','0'); - } - else if (recvbuffer == "hw") { - - bHWError = !bHWError; - Serial.print("bHWError="); - Serial.println(bHWError); - } - else if (recvbuffer == "set") { - Serial1.print("+++"); - Serial1.write(0x0D); - Serial1.flush(); - } - else if (recvbuffer == "h") - { - Serial.println("AGV Caller"); - Serial.print("v"); - Serial.println(version); - Serial.println("=============="); - Serial.println("h : help"); - Serial.println("on : selected on"); - Serial.println("off : selected off"); - Serial.println("#1~6 : set client no"); - Serial.println("? : get client no"); - Serial.println("=============="); - } - else if (recvbuffer == "?") - { - Serial.print("Get Client No : #"); - Serial.println(clientno); - } - else if (recvbuffer.startsWith("#")) - { - String strNo = recvbuffer.substring(1); - clientno = (byte)(strNo.toInt()); - SaveNo(); // EEPROM.write(0, clientno); - } -} -void SaveNo() -{ - EEPROM.write(0, clientno); - #ifdef DEBUG - Serial.print("Save Client No : #"); - Serial.println(clientno); - #endif -} diff --git a/Arduino_CallButton/ReadMe.txt b/Arduino_CallButton/ReadMe.txt deleted file mode 100644 index e21a18c..0000000 --- a/Arduino_CallButton/ReadMe.txt +++ /dev/null @@ -1 +0,0 @@ -221118 c-line 소스 복제 (B line 은 3버튼 기본으로 설정한다) \ No newline at end of file diff --git a/Arduino_PLC/Arduino_PLC.ino b/Arduino_PLC/Arduino_PLC.ino deleted file mode 100644 index 380e348..0000000 --- a/Arduino_PLC/Arduino_PLC.ino +++ /dev/null @@ -1,105 +0,0 @@ -/* - Name: B_FVI_AGV.ino - Created: 2022-11-16 오전 13:32:00 - Author: KIMCHK - */ - -#include "motor.h" -#include "IO.h" -#include "HmiClass.h" -#include "UtilClass.h" -#include "VarClass.h" -#include "VarClass.h" -#include - -int debugportvalue = 0; -String version = "22.11.16.1716"; -String debugmessage = ""; -void(*resetFunc)(void) = 0; -unsigned long timesyncvalue = 0; -unsigned long startTime = 0; -void setup() -{ - Serial.begin(57600); //디버그 및 업로드 포트 - Serial1.begin(57600); //통신 포트 - - /*while (!Serial) - true; - - while (!Serial1) - true;*/ - - pinMode(13,OUTPUT); - - var.eeprom_load(); //플래그 우선 복원 - - io.Setup(); - hmi.Setup(); //HMI 초기화 - var.Setup(); - mot.Setup(); - - hmi.SendMessage(F("##:SETUP:OK"),false); - hmi.SendMessage(String("##:VERSION:") + String(version), false); - - //TCCR1B = TCCR1B & B11111000 | B00000001; // set timer 1 divisor to 1 for PWM frequency of 31372.55 Hz - TCCR1B = TCCR1B & B11111000 | B00000010; // set timer 1 divisor to 8 for PWM frequency of 3921.16 Hz - TCNT1 = 0x0000; - //TCCR1B = TCCR1B & B11111000 | B00000011; // set timer 1 divisor to 64 for PWM frequency of 490.20 Hz - - PrintDebugCommand(); -} - -void loop() -{ - io.Update(); //DIO 상태 학인; - var.Update(); //가변변수 업데이트 - mot.Update(); // 모터제어 - hmi.Update(); //HMI Events - - //초기화 - if (var.runReset) - { - Serial.println("** RESET **"); - var.eeprom_incResetCount(); - var.runReset = false; - resetFunc(); - delay(2000); - } - - //경과시간 - unsigned long runtime = millis() - startTime; - if (runtime > 60000) var.runtime = 60000; - else var.runtime = (uint16_t)runtime; - startTime = millis(); - - if(startTime % 500 == 0) - { - if(digitalRead(13)==HIGH) - digitalWrite(13,LOW); - else - digitalWrite(13,HIGH); - } - -} -void UpdateTime() -{ - //시간정보를 조회한다. 190319 - timesyncvalue = millis(); -} -void PrintDebugCommand() -{ - String data = ""; - data += String("====================================\n"); - data += String("## AGV Z-Motor Controller\n"); - data += String("## Version "+ version + "\n" ); - data += String("## Created by ATK4-EET-1P\n"); - data += String("====================================\n"); - data += String(">> ZUP (z-axis move up)\n"); - data += String(">> ZUP (z-axis move up)\n"); - data += String(">> ZUP (z-axis move up)\n"); - data += String(">> ZUP (z-axis move up)\n"); - data += String(">> ZUP (z-axis move up)\n"); - data += String(">> ZUP (z-axis move up)\n"); - data += String("====================================\n"); - Serial.println(data); -} diff --git a/Arduino_PLC/FontList.txt b/Arduino_PLC/FontList.txt deleted file mode 100644 index 3a6017f..0000000 --- a/Arduino_PLC/FontList.txt +++ /dev/null @@ -1,120 +0,0 @@ -//16 -ġ˻ظϰ±ػ뿬ἭӰӵȣðĿƷѹӵ͸кϷʱȭ(#%).-:/><_¸ͽýۼڵI/Oʱȭ01234456789SNOVRDCNSTLIMITHOMECHRGALIGNPAUSEMAGFMAGBXBEERFIDABCDEFTIMEȨڵ̵ITEMONTAKEABCDEFGHIJKLMNOPQRSTUVWXYZvӰ谪Ѱ谨ms= -//80 -QCA0123456789Hڵ -//40 -ưپȣQCAzZ%ø-=_MHPACKINGQCQARFIDXBEEġã߿ϷǾϴʿմϴۻڼʿεڷ¼յŲ()[#]յ¿CW0123456789.vLOADINGĿ÷ּġãġ˻غ˼̵̵Ȩ - -if(va0.val==0) -{ - msg.txt=" " - tbco.val=63846 -}else if(va3.val==0) -{ - msg.txt="RFID " - tbco.val=63846 -}else if(va4.val==0) -{ - msg.txt="XBEE " - tbco.val=63846 -}else if(va6.val==0) -{ - msg.txt="ڷ¼() " - tbco.val=63846 -}else if(va7.val==0) -{ - msg.txt="ڷ¼() " - tbco.val=63846 -}else if(va8.val>0) -{ - msg.txt=" " - tbco.val=63846 -}else if(va1.val>0) -{ - msg.txt=" " - tbco.val=63846 -}else if(va5.val>0) -{ - msg.txt="(Z) ε" - tbco.val=63846 -}else if(va2.val==0) -{ - tbco.val=64520 - if(varmc.val==0) - { - msg.txt="() " - }else if(varmc.val==1) - { - msg.txt="() " - }else if(varmc.val==2) - { - msg.txt="() " - }else if(varmc.val==3) - { - msg.txt="() " - }else if(varmc.val==4) - { - msg.txt="() " - }else if(varmc.val==5) - { - msg.txt="() ̵(Ȩ)" - }else if(varmc.val==6) - { - msg.txt="() ̵()" - }else if(varmc.val==16) - { - msg.txt="() " - }else - { - msg.txt="() ˼ " - } -}else -{ - //autorun mode : parse message - tbco.val=1048 - if(varmc.val==0) - { - msg.txt="[#1] Ŀ ÷ ּ" //mcodevalue - }else if(varmc.val==1) - { - msg.txt="[#2] ̵()" //mcodevalue - }else if(varmc.val==2) - { - msg.txt="[#3] ʿմϴ" //mcodevalue - }else if(varmc.val==3) - { - msg.txt="[#4] ̵(Ȩ)" //mcodevalue - }else if(varmc.val==4) - { - msg.txt="[#5] ̵ ()" //mcodevalue - }else if(varmc.val==5) - { - msg.txt="[#6] ̵ ()" //mcodevalue - }else if(varmc.val==6) - { - msg.txt="[#7] " //mcodevalue - }else if(varmc.val==7) - { - msg.txt="[#8] Ŀ ּ" //mcodevalue - }else if(varmc.val==8) - { - msg.txt="[#9] ġ ã " //mcodevalue - }else if(varmc.val==9) - { - msg.txt="[#10] ġ ã " //mcodevalue - }else if(varmc.val==10) - { - msg.txt="[#11] غ" //mcodevalue - }else if(varmc.val==11) - { - msg.txt="[#12] " //mcodevalue - }else - { - msg.txt="[#99] ˼ " - } -} -if(tbmsg.txt!=msg.txt) -{ - tbmsg.txt=msg.txt - tbmsg.bco=tbco.val -} diff --git a/Arduino_PLC/HmiClass.cpp b/Arduino_PLC/HmiClass.cpp deleted file mode 100644 index dc0a2c6..0000000 --- a/Arduino_PLC/HmiClass.cpp +++ /dev/null @@ -1,569 +0,0 @@ -#include "IO.h" -#include "VarClass.h" -#include "HmiClass.h" -#include "UtilClass.h" -#include "motor.h" -#include "arduino.h" - -unsigned long errtime = 0; -unsigned long eruntime = 0; - -void HmiClass::Setup() -{ - hmi.SendMessage("##:HMI:SETUP", false); - updatetime = millis(); - ClearTempBuffer0(); - ClearTempBuffer1(); -} - -void HmiClass::Update() -{ - //데이터는 일정 주기로 전송한다. - unsigned long runtime = millis() - updatetime; - uint8_t loopterm = var._eep_iosendinterval; - - loopterm = 500; - - //설정 중에는 통신속도를 초당 10번으로 고정한다 - if (var.getFlag(FLAG_SETUP) == true) loopterm = 100; - if (runtime > loopterm) - { - //IO상태전송 - SendIOStatus(); - - //설정모드에서는 계속 전송 한다 - if (var.getFlag(FLAG_SETUP) == true) - { - //EEP정보 전송 - SendSetupInfo(); - } - updatetime = millis(); - } - - //입력값 감지 190319 - CheckReceiveS0(); - CheckReceiveS1(); -} - -void HmiClass::SendIOStatus() -{ - //전송데이터처리 - byte payload[29]; //IO4바이트(uint32), A0~A3 A는 각 2바이트(uint16) - byte payidx = 0; - - payload[payidx++] = '@'; //@ - payload[payidx++] = '@'; //@ - payload[payidx++] = 10; //데이터 길이 - payload[payidx++] = 'I'; //49=I(IO) - payload[payidx++] = (byte)(var.IOData >> 0); //INPUT(16) - payload[payidx++] = (byte)(var.IOData >> 8); //OUTPUT(16) - payload[payidx++] = (byte)(var.IOData >> 16); - payload[payidx++] = (byte)(var.IOData >> 24); - - uint32_t flagValue = var.getFlagValue(); - payload[payidx++] = (byte)(flagValue >> 0); //FLAG (0~31) - payload[payidx++] = (byte)(flagValue >> 8); - payload[payidx++] = (byte)(flagValue >> 16); - payload[payidx++] = (byte)(flagValue >> 24); - - //쓰레드진행시간 - payload[payidx++] = (byte)var.runtime; - - //checksum - byte checksum = 0; - for (int i = 3; i < payidx; i++) - checksum = checksum ^ payload[i]; - - payload[payidx++] = checksum; - payload[payidx++] = 0x0D; - payload[payidx++] = 0x0A; - - //Serial.print("Send Payload len="); - //Serial.println(payidx); - - hmiSerial.write(payload, payidx); - hmiSerial.flush(); - - //20190325 - 1번포트로 미러링 - //dbgSerial.write(payload, sizeof(payload)); - //dbgSerial.flush(); -} - -void HmiClass::SendSetupInfo() -{ - //전송데이터처리 - byte payload[19]; //IO4바이트(uint32), A0~A3 A는 각 2바이트(uint16) - byte payidx = 0; - - payload[payidx++] = '@'; //@ - payload[payidx++] = '@'; //@ - payload[payidx++] = 5; //데이터 길이 - payload[payidx++] = 'S'; //49=I(IO),T=TEXT,S=SETUP - payload[payidx++] = var._eep_iosendinterval; - payload[payidx++] = var._eep_resetcount; - payload[payidx++] = var._eep_pindir_iH; - payload[payidx++] = var._eep_pindir_iL; - - //checksum - byte checksum = 0; - for (int i = 3; i < payidx; i++) - checksum = checksum ^ payload[i]; - - payload[payidx++] = checksum; - payload[payidx++] = 0x0D; - payload[payidx++] = 0x0A; - - //Serial.print("Send Payload len="); - //Serial.println(sizeof(payload)); - - hmiSerial.write(payload, sizeof(payload)); - hmiSerial.flush(); - - //20190325 - 1번포트로 미러링 - //dbgSerial.write(payload, sizeof(payload)); - //dbgSerial.flush(); -} - -void HmiClass::CheckReceiveS0() -{ - //수신데이터가 있는경우에만 처리함 - //bool newdata = hmiSerial.available() > 0; - //if (newdata) sprint(F("HMI Received Data [")); - while (hmiSerial.available() > 0) { - incomingByte0 = (char)(hmiSerial.read()); - - if (STX1S0 == false) - { - if (incomingByte0 != '@') - { - STX2S0 = false; - ETX1S0 = false; - SendMessage(F("ERROR:STX1"), true); - continue; - } - else - { - STX1S0 = true; - ClearTempBuffer0(); - Tempbuffer1[bufferIndex0++] = incomingByte0; //Tempbuffer1 += incomingByte; - } - } - else if (STX2S0 == false) - { - if (bufferIndex0 != 1 || bufferIndex0 < 1 || Tempbuffer1[0] != '@' || incomingByte0 != '@') - { - STX1S0 = false; - ETX1S0 = false; - SendMessage(F("ERROR:STX2"), true); - continue; - } - else - { - STX2S0 = true; - Tempbuffer1[bufferIndex0++] = incomingByte0; //Tempbuffer1 += incomingByte; - } - } - else - { - Tempbuffer1[bufferIndex0++] = incomingByte0; //Tempbuffer1 += incomingByte; - - //여기서부터는무조건 누적한다. - if (bufferIndex0 == 3) - { - if (Tempbuffer1[0] != 0x40 || Tempbuffer1[1] != '@') - { - STX1S0 = false; - STX2S0 = false; - ETX1S0 = false; - - bufferIndex0 = 0; // = ""; - } - else LEN1 = incomingByte0; //데이터 길이가온다 - } - else if (bufferIndex0 == LEN1 + 2 + 1 + 1) //체크섬이 왔다 - { - CHK1 = incomingByte0; - } - else if (bufferIndex0 == LEN1 + 2 + 1 + 1 + 1) //ETX1 - { - if (incomingByte0 != 0x0D) - { - //ETX가 와야하는데 다른데이터가 왔다 - STX1S0 = false; - STX2S0 = false; - ETX1S0 = false; - bufferIndex0 = 0;// - SendMessage(F("ERROR:STX3"), true); - } - } - else if (bufferIndex0 == LEN1 + 2 + 1 + 1 + 1 + 1) - { - //전체길이를 만족햇다. - if (incomingByte0 != 0x0A) - { - //ETX가 와야하는데 다른데이터가 왔다 - STX1S0 = false; - STX2S0 = false; - ETX1S0 = false; - //Console.WriteLine("에러 모두 파기"); - bufferIndex0 = 0;// == "";//.Clear(); - SendMessage(F("ERROR:STX4"), true); - } - else - { - STX1S0 = false; - STX2S0 = false; - ETX1S0 = false; - - //임시버퍼의 데이터를 수신데이터 변수에 넣는다 - //memcpy(buffer.c_str(), Tempbuffer1.c_str(), sizeof(Tempbuffer1)); - //Tempbuffer1.toCharArray() - //buffer = Tempbuffer1; - Parser(bufferIndex0); - bufferIndex0 = 0; - //Tempbuffer1[0] = 0; //첫비트에 nullstring 을 넣는다 - //var.runCommand( parser(buffer1, addMsg1, 0); - } - } - } - - ////stx ,etx 는 hex 처리하고 번호와 값을 ascii처리함 - //if (incomingByte == 0x02) buffer = ""; - //else if (incomingByte == 0x03) - //{ - // //ETX값이나 전체 길이가 4가아니라면 추가해야함 - // uint8_t butNo = (uint8_t)(buffer.substring(0, 3).toInt()); - // uint8_t butValue = (uint8_t)(buffer.substring(3, 4).toInt()); - // //remote 명령과 공유하기 위해서 util로 이동 - // var.runCommand((eCommand)butNo, butValue,0); //NewMsgEvent(butNo, butValue); - // break; - //} - //else{ - // buffer += (char)incomingByte; //문자를 누적시킨다. - // if (buffer.length() > 10) { - // sprintln(F("HMI buffer Over error")); - // buffer = ""; - // } - //} - } - //if (newdata) sprintln("]"); -} - -void HmiClass::CheckReceiveS1() -{ - //수신데이터가 있는경우에만 처리함 - //bool newdata = dbgSerial.available() > 0; - //if (newdata) sprint(F("HMI Received Data [")); - while (dbgSerial.available() > 0) { - incomingByte1 = (char)(dbgSerial.read()); - - if(incomingByte1 == 0x0A) //if newline - { - String cmd = ""; - for(int i = 0 ; i < bufferIndex1;i++) - { - cmd += String((char)Tempbuffer1[i]); - } - - if(cmd.equals("UP")||cmd.equals("up")) - { - Serial.println("User command : z-up"); - mot.SetZRun(ZRUN_UP); - } - else if(cmd.equals("DN")||cmd.equals("dn")) - { - Serial.println("User command : z-down"); - mot.SetZRun(ZRUN_DN); - } - else if(cmd.equals("STOP")||cmd.equals("stop")) - { - Serial.println("User command : z-stop"); - mot.SetZRun(ZRUN_STOP); - } - else{ - Serial.print("Unknown Command : "); - Serial.println(cmd); - } - - bufferIndex1 = 0; - } - else if(bufferIndex1 > 99) - { - Serial.println(F("recv1 length error(>99")); - bufferIndex1 = 0; - } - else { - Tempbuffer1[bufferIndex1++] = incomingByte1; //Tempbuffer1 += incomingByte; - } - } - //if (newdata) sprintln("]"); -} -/* -void HmiClass::CheckReceiveS1_Backup_221117() -{ - //수신데이터가 있는경우에만 처리함 - bool newdata = dbgSerial.available() > 0; - //if (newdata) sprint(F("HMI Received Data [")); - while (dbgSerial.available() > 0) { - incomingByte1 = (char)(dbgSerial.read()); - - if (STX1S1 == false) - { - if (incomingByte1 != '@') - { - STX2S1 = false; - ETX1S1 = false; - SendMessage(F("ERROR:STX1"), true); - continue; - } - else - { - STX1S1 = true; - ClearTempBuffer1(); - Tempbuffer1[bufferIndex1++] = incomingByte1; //Tempbuffer1 += incomingByte; - } - } - else if (STX2S1 == false) - { - if (bufferIndex1 != 1 || bufferIndex1 < 1 || Tempbuffer1[0] != '@' || incomingByte1 != '@') - { - STX1S1 = false; - ETX1S1 = false; - SendMessage(F("ERROR:STX2"), true); - continue; - } - else - { - STX2S1 = true; - Tempbuffer1[bufferIndex1++] = incomingByte1; //Tempbuffer1 += incomingByte; - } - } - else - { - Tempbuffer1[bufferIndex1++] = incomingByte1; //Tempbuffer1 += incomingByte; - - //여기서부터는무조건 누적한다. - if (bufferIndex1 == 3) - { - if (Tempbuffer1[0] != 0x40 || Tempbuffer1[1] != '@') - { - STX1S1 = false; - STX2S1 = false; - ETX1S1 = false; - - bufferIndex1 = 0; // = ""; - } - else LEN1 = incomingByte1; //데이터 길이가온다 - } - else if (bufferIndex1 == LEN1 + 2 + 1 + 1) //체크섬이 왔다 - { - CHK1 = incomingByte1; - } - else if (bufferIndex1 == LEN1 + 2 + 1 + 1 + 1) //ETX1 - { - if (incomingByte1 != 0x0D) - { - //ETX가 와야하는데 다른데이터가 왔다 - STX1S1 = false; - STX2S1 = false; - ETX1S1 = false; - bufferIndex1 = 0;// - SendMessage(F("ERROR:STX3"), true); - } - } - else if (bufferIndex1 == LEN1 + 2 + 1 + 1 + 1 + 1) - { - //전체길이를 만족햇다. - if (incomingByte1 != 0x0A) - { - //ETX가 와야하는데 다른데이터가 왔다 - STX1S1 = false; - STX2S1 = false; - ETX1S1 = false; - //Console.WriteLine("에러 모두 파기"); - bufferIndex1 = 0;// == "";//.Clear(); - SendMessage(F("ERROR:STX4"), true); - } - else - { - STX1S1 = false; - STX2S1 = false; - ETX1S1 = false; - - //임시버퍼의 데이터를 수신데이터 변수에 넣는다 - //memcpy(buffer.c_str(), Tempbuffer1.c_str(), sizeof(Tempbuffer1)); - //Tempbuffer1.toCharArray() - //buffer = Tempbuffer1; - Parser(bufferIndex1); - bufferIndex1 = 0; - //Tempbuffer1[0] = 0; //첫비트에 nullstring 을 넣는다 - //var.runCommand( parser(buffer1, addMsg1, 0); - } - } - } - - ////stx ,etx 는 hex 처리하고 번호와 값을 ascii처리함 - //if (incomingByte == 0x02) buffer = ""; - //else if (incomingByte == 0x03) - //{ - // //ETX값이나 전체 길이가 4가아니라면 추가해야함 - // uint8_t butNo = (uint8_t)(buffer.substring(0, 3).toInt()); - // uint8_t butValue = (uint8_t)(buffer.substring(3, 4).toInt()); - // //remote 명령과 공유하기 위해서 util로 이동 - // var.runCommand((eCommand)butNo, butValue,0); //NewMsgEvent(butNo, butValue); - // break; - //} - //else{ - // buffer += (char)incomingByte; //문자를 누적시킨다. - // if (buffer.length() > 10) { - // sprintln(F("HMI buffer Over error")); - // buffer = ""; - // } - //} - } - //if (newdata) sprintln("]"); -} -*/ - -void HmiClass::Parser(byte bufferIndex) -{ - Serial.println("Remote Command Parse"); - - //데이터를 분석해야 함 - if (Tempbuffer1[0] == '@' && Tempbuffer1[1] == '@' && - Tempbuffer1[bufferIndex - 2] == 0x0D && Tempbuffer1[bufferIndex - 1] == 0x0A) - { - byte len = Tempbuffer1[2]; - byte chk = Tempbuffer1[len + 3]; - if (bufferIndex != len + 6) - { - String msg = ("===>Frame length error len="); - msg += String(bufferIndex); - msg += (",receive="); - msg += String(len + 6); - SendMessage(msg, true); - } - else { - //체크섬확인 - byte cs = 0; - for (int i = 3; i < (3 + len); i++) - cs = cs ^ Tempbuffer1[i]; - if (chk != cs) - { - String msg = ("===>checksum error calc="); - msg.concat( String(cs)); - msg.concat("receive="); - msg.concat(String(chk)); - SendMessage(msg, true); - } - else { - //체크섬일치 - byte command = Tempbuffer1[3]; - byte param1 = Tempbuffer1[4]; - byte param2 = Tempbuffer1[5]; - var.runCommand((eCommand)command, param1, param2); - } - } - } - else { - //프레임이 이상하다. - //sprintln("===>Frame error stx, etx"); - SendMessage("==>Frame error no stx,etx", true); - } -} -void HmiClass::ClearTempBuffer0() -{ - LEN0 = 0; - bufferIndex0 = 0; - memcpy(Tempbuffer0, 0, sizeof(Tempbuffer0)); -} -void HmiClass::ClearTempBuffer1() -{ - LEN1 = 0; - bufferIndex1 = 0; - memcpy(Tempbuffer1, 0, sizeof(Tempbuffer1)); -} - -void HmiClass::SendMessage(String message, bool isError) -{ - if(message.equals(hmimessage)) - { - //동일메세지가 왓다면 1초이내로 다시 전송하지 못하게 한다. - if(hmimessagerepeat == 0 || hmimessagerepeat > millis()) - hmimessagerepeat = millis(); - - hmimessagetime = millis()-hmimessagerepeat; - if(hmimessagetime < 999) return; - - } else{ - hmimessagerepeat = millis(); - hmimessage = message; - } - // test = len 4 , totals 4+4=8 - // @ @ 6 T 0 t e s t chk \r \n - byte totalLength = message.length() + 8; - byte payload[100]; //IO4바이트(uint32), A0~A3 A는 각 2바이트(uint16) - byte payidx = 0; - - payload[payidx++] = '@'; //@ - payload[payidx++] = '@'; //@ - payload[payidx++] = message.length() + 2; //데이터 길이 - payload[payidx++] = 'T'; - payload[payidx++] = isError; //오류여부 - for (int i = 0; i < message.length(); i++) - { - payload[payidx++] = message[i]; - } - - //checksum - byte checksum = 0; - for (int i = 3; i < (3 + message.length() + 2); i++) - checksum = checksum ^ payload[i]; - - payload[payidx++] = checksum; - payload[payidx++] = 0x0D; - payload[payidx++] = 0x0A; - - hmiSerial.write(payload, totalLength); - hmiSerial.flush(); - - //20190325 - 1번포트로 미러링 - dbgSerial.println(message); - //dbgSerial.write(message, message.length); - //dbgSerial.flush(); - -} -bool HmiClass::SendValue(char msg, uint32_t value) -{ - byte totalLength = 11; - byte payload[100]; //IO4바이트(uint32), A0~A3 A는 각 2바이트(uint16) - byte payidx = 0; - - payload[payidx++] = '@'; //@ - payload[payidx++] = '@'; //@ - payload[payidx++] = 6; //데이터 길이 - payload[payidx++] = 'V'; - payload[payidx++] = msg; //값종류 - payload[payidx++] = (byte)(value >> 0); - payload[payidx++] = (byte)(value >> 8); - payload[payidx++] = (byte)(value >> 16); - payload[payidx++] = (byte)(value >> 24); - - //checksum - byte checksum = 0; - for (int i = 3; i < (3 + 4 + 2); i++) - checksum = checksum ^ payload[i]; - - payload[payidx++] = checksum; - payload[payidx++] = 0x0D; - payload[payidx++] = 0x0C; - - hmiSerial.write(payload, totalLength); - hmiSerial.flush(); - - //20190325 - 1번포트로 미러링 - dbgSerial.write(payload, totalLength); - dbgSerial.flush(); -} - -HmiClass hmi; diff --git a/Arduino_PLC/HmiClass.h b/Arduino_PLC/HmiClass.h deleted file mode 100644 index 01b76ec..0000000 --- a/Arduino_PLC/HmiClass.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef _HMICLASS_H_ -#define _HMICLASS_H_ -#include "arduino.h" - -#define hmiSerial Serial1 -#define dbgSerial Serial - -class HmiClass -{ -public: - - void Setup(); - void Update(); - void SendIOStatus(); - void SendSetupInfo(); - void SendMessage(String message, bool isError); - bool SendValue(char msg, uint32_t value); - bool showDebug = false; - -private: - - void ClearTempBuffer0(); - void ClearTempBuffer1(); - byte Tempbuffer0[100]; - byte Tempbuffer1[100]; - byte bufferIndex0 = 0; - byte bufferIndex1 = 0; - - unsigned long updatetime = 100; //데이터 전송 간격 측정을 위한 변수 - - void CheckReceiveS0(); //Serial0 - void CheckReceiveS1(); //Serial1 - - char incomingByte0; //수신버퍼에서 읽은 데이터를 임시 저장 - char incomingByte1; //수신버퍼에서 읽은 데이터를 임시 저장 - - //String buffer = ""; //수신버퍼 임시 저장 공간 - //String Tempbuffer1 = ""; - bool STX1S0 = false; - bool STX2S0 = false; - bool ETX1S0 = false; - - bool STX1S1 = false; - bool STX2S1 = false; - bool ETX1S1 = false; - - byte LEN1; - byte CHK1; - - byte LEN0; - byte CHK0; - - unsigned long hmimessagerepeat=0; - unsigned long hmimessagetime =0; - String hmimessage=""; - void Parser(byte bufferIndex); -}; -extern HmiClass hmi; -#endif diff --git a/Arduino_PLC/IO.cpp b/Arduino_PLC/IO.cpp deleted file mode 100644 index 2e75223..0000000 --- a/Arduino_PLC/IO.cpp +++ /dev/null @@ -1,386 +0,0 @@ -#include "IO.h" -#include "VarClass.h" -#include "motor.h" -#include "HmiClass.h" -#include "UtilClass.h" - -void IoClass::Setup() -{ - hmi.SendMessage("##:IO:SETUP", false); - - byte DIPins[] = { 30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45 }; - byte DOPins[] = { 22,23,24,25,26,27,28,29 }; - - //입력포트 설정 - for (int i = 0; i < sizeof(DIPins); i++) - pinMode(DIPins[i], INPUT); - - //출력포트설정 - for (int i = 0; i < sizeof(DOPins); i++) - pinMode(DOPins[i], OUTPUT); - - //MAF 초기화 - for (int i = 0; i < MAF_SIZE; i++) - { - bufferF[i] = 0; - bufferB[i] = 0; - } - -} -void IoClass::Update() -{ - - //Read DigitalInput - - bool diValue[16]; int idx = 0; - diValue[idx++] = digitalRead(PINI_EMG); //B접이다 - diValue[idx++] = digitalRead(PINI_BTN_1); - diValue[idx++] = digitalRead(PINI_BTN_2); - diValue[idx++] = digitalRead(PINI_BTN_3); - diValue[idx++] = digitalRead(PINI_BTN_4); - diValue[idx++] = digitalRead(PINI_OVERLOADL1); - diValue[idx++] = digitalRead(PINI_OVERLOADL2); - diValue[idx++] = digitalRead(PINI_OVERLOADR1); - diValue[idx++] = digitalRead(PINI_OVERLOADR2); - diValue[idx++] = digitalRead(PINI_EMPTY_38); - diValue[idx++] = digitalRead(PINI_BTN_ZUP); - diValue[idx++] = digitalRead(PINI_BTN_ZDN); - diValue[idx++] = digitalRead(PINI_LIMIT_LU); - diValue[idx++] = digitalRead(PINI_LIMIT_LD); - diValue[idx++] = digitalRead(PINI_LIMIT_RU); - diValue[idx++] = digitalRead(PINI_LIMIT_RD); - diValue[idx++] = digitalRead(PINI_STOP); - - - //비상정지 반전 - diValue[IDXI_EMG] = !diValue[IDXI_EMG]; - - //오버로드센서 반전 - diValue[IDXI_OVERLOADL] = !diValue[IDXI_OVERLOADL]; - diValue[IDXI_OVERLOADR] = !diValue[IDXI_OVERLOADR]; - diValue[IDXI_EMPTY7] = !diValue[IDXI_EMPTY7]; - diValue[IDXI_EMPTY8] = !diValue[IDXI_EMPTY8]; - - //오버로드센서를 합친다 5+6=>5, 7+8=>6 - diValue[IDXI_OVERLOADL] = diValue[IDXI_OVERLOADL] || diValue[IDXI_OVERLOADR]; - diValue[IDXI_OVERLOADR] = diValue[IDXI_EMPTY7] || diValue[IDXI_EMPTY8]; - diValue[IDXI_EMPTY7]= false; - diValue[IDXI_EMPTY8]= false; - - //리밋센서도 반전 - diValue[IDXI_LIMIT_LU] = !diValue[IDXI_LIMIT_LU]; - diValue[IDXI_LIMIT_LD] = !diValue[IDXI_LIMIT_LD]; - diValue[IDXI_LIMIT_RU] = !diValue[IDXI_LIMIT_RU]; - diValue[IDXI_LIMIT_RD] = !diValue[IDXI_LIMIT_RD]; - - //리버스 체크 200325 - //입력값은 Reverse 하지 않는다 - /* - var._eep_pindir_iL = 0; - var._eep_pindir_iH = 0; - - for (int i = 0; i < 16; i++) - { - if (i < 8) - { - if (bitRead(var._eep_pindir_iL, i) == true) - diValue[i] = !diValue[i]; - } - else { - if (bitRead(var._eep_pindir_iH, i - 8) == true) - diValue[i] = !diValue[i]; - } - }*/ - - - for (int i = 0; i < idx; i++) - { - //이 값의 변화를 체크한다. - bool oldValue = bitRead(var.IOData, i); - bool isNewValue = false; - if (oldValue != diValue[i]) isNewValue = true; - bitWrite(var.IOData, i, diValue[i]);//0번부터 기록한다 - - //값이 변화했따 - if (isNewValue) IOValueChanged(false, i, diValue[i]); - } - - //read output - bool doValue[8]; idx = 0; - doValue[idx++] = digitalRead(PINO_GUIDEMOTOR_LDIR); - doValue[idx++] = digitalRead(PINO_GUIDEMOTOR_LRUN); - doValue[idx++] = digitalRead(PINO_GUIDEMOTOR_RDIR); - doValue[idx++] = digitalRead(PINO_GUIDEMOTOR_RRUN); - doValue[idx++] = digitalRead(PINO_EMPTY_26); - doValue[idx++] = digitalRead(PINO_EMPTY_27); - doValue[idx++] = digitalRead(PINO_EMPTY_28); - doValue[idx++] = digitalRead(PINO_EMPTY_29); - - for (int i = 0; i < idx; i++) - { - bool oldValue = bitRead(var.IOData, i + 16); - bool isNewValue = false; - if (oldValue != doValue[i]) isNewValue = true; - bitWrite(var.IOData, i + 16, doValue[i]);//0번부터 기록한다 - - //값이 변화했따 - if (isNewValue) IOValueChanged(true, i, !oldValue); - } - - //Read Analog (마그넷 센서 값만 확인한다) - idx = 0; - - //원본값은 그대로 저장한다 - var.ANData[idx++] = analogRead(PINAI_0); - var.ANData[idx++] = analogRead(PINAI_1); - var.ANData[idx++] = analogRead(PINAI_2); - var.ANData[idx++] = analogRead(PINAI_3); - - idx = 0; - var.AOData[idx++] = 0; - var.AOData[idx++] = 0; - var.AOData[idx++] = 0; - var.AOData[idx++] = 0; - - //파워체크 - if (IsPowerLoss() == true) var.setFlag(FLAG_POWERLOSS, true, "IOUpdate"); - else var.setFlag(FLAG_POWERLOSS, false, "IOUpdate"); -} - -//메인전원이 OFF되어있는지 확인합니다.(리밋센서의OFF여부로 체크함) -bool IoClass::IsPowerLoss() -{ - //얘들은 B접점이라서. 항상 ON 이 되어있는 애들이다. - //전원이 OFF되면 모든 센서가 LOW 상태가 된다 - //하지만 신호를 반전(!) 시켜두었으므로 모두 켜진다면 OFF 된 경우이다) - bool b1 = bitRead(var.IOData, IDXI_LIMIT_LD); - bool b2 = bitRead(var.IOData, IDXI_LIMIT_LU); - bool b3 = bitRead(var.IOData, IDXI_LIMIT_RU); - bool b4 = bitRead(var.IOData, IDXI_LIMIT_RD); - if (b1 == true && b2 == true && b3 == true && b4 == true) return true; - return false; -} - -//IO상태값이 변화되었을때 동작한다 -void IoClass::IOValueChanged(bool isout, uint8_t index, bool newValue) -{ - if (isout == false) //입력포트 - { - - if (index == IDXI_BTN_1) - { - if (newValue == true) - { - hmi.SendMessage("button 1 pressed", false); - } - } - if (index == IDXI_BTN_2) - { - if (newValue == true) - { - hmi.SendMessage("button 2 pressed", false); - } - } - if (index == IDXI_BTN_3) - { - if (newValue == true) - { - hmi.SendMessage("button 3 pressed", false); - } - } - if (index == IDXI_BTN_4) - { - if (newValue == true) - { - hmi.SendMessage("button 4 pressed", false); - } - } - - //양쪽면의 z축 UP/DN 버튼 할당 - if (index == IDXI_BTN_ZUP) - { - if (newValue == true) - { - if (mot.GetZDirL() == ZDIR_CW && mot.IsMoveZ() == true) - { - hmi.SendMessage("z-stop by h/w button", false); - mot.SetZRun(ZRUN_STOP); - } - if (mot.GetZDirL() == ZDIR_CCW && mot.IsMoveZ() == true) - { - hmi.SendMessage("z-stop by h/w button", false); - mot.SetZRun(ZRUN_STOP); - } - else { - mot.SetZRun(ZRUN_UP); - hmi.SendMessage("Z-Up by H/W Button", false); - } - - } - } - else if (index == IDXI_BTN_ZDN) - { - if (newValue == true) - { - if (mot.GetZDirL() == ZDIR_CCW && mot.IsMoveZ() == true) - { - hmi.SendMessage("z-stop by h/w button", false); - mot.SetZRun(ZRUN_STOP); - } - if (mot.GetZDirL() == ZDIR_CW && mot.IsMoveZ() == true) - { - hmi.SendMessage("z-stop by h/w button", false); - mot.SetZRun(ZRUN_STOP); - } - else { - mot.SetZRun(ZRUN_DN); - hmi.SendMessage("Z-Dn by H/W Button", false); - } - } - } - else if (index == IDXI_EMG) //비상정지 혹은 범퍼센서가 감지된경우 - { - if (newValue == true) - { - hmi.SendMessage("EMG Stop Detected", false); - mot.SetZRun(ZRUN_STOP); - } - } - - //일반적으로 Rising 상태일때에만 동작시킨다. - if (newValue == true) - { - //하단센서2개가 들어왔다면 FLAG를 설정한다 - if (index == IDXI_LIMIT_LD || index == IDXI_LIMIT_RD) - { - if (index == IDXI_LIMIT_LD ) - { - if (var.getFlag(FLAG_LIMITLOWL) == false) - { - var.setFlag(FLAG_LIMITLOWL, true, "IO:Limit Sensor(LD) Changed"); - hmi.SendMessage(F("SET:FLAG:LOW_LIMITL:1"), false); - } - } - else if (index == IDXI_LIMIT_RD ) - { - if (var.getFlag(FLAG_LIMITLOWR) == false) - { - var.setFlag(FLAG_LIMITLOWR, true, "IO:Limit Sensor(RD) Changed"); - hmi.SendMessage(F("SET:FLAG:LOW_LIMITR:1"), false); - } - } - else { - bool b1 = bitRead(var.IOData, IDXI_LIMIT_LD); - bool b2 = bitRead(var.IOData, IDXI_LIMIT_RD); - if (b1 == false && var.getFlag(FLAG_LIMITLOWL) == true) - { - var.setFlag(FLAG_LIMITLOWL, false, "IO:Limit Sensor(LD) Changed"); - hmi.SendMessage(F("SET:FLAG:LOW_LIMITL:0"), false); - } - if (b2 == false && var.getFlag(FLAG_LIMITLOWR) == true) - { - var.setFlag(FLAG_LIMITLOWR, false, "IO:Limit Sensor(RD) Changed"); - hmi.SendMessage(F("SET:FLAG:LOW_LIMITR:0"), false); - } - } - } - - if (index == IDXI_LIMIT_LU || index == IDXI_LIMIT_RU) - { - - - if (index == IDXI_LIMIT_LU || var.getFlag(FLAG_LIMITHIGHL) == false) - { - var.setFlag(FLAG_LIMITHIGHL, true, "IO:Limit Sensor(LU) Changed"); - hmi.SendMessage(F("SET:FLAG:HIGH_LIMITL:1"), false); - } - else if (index == IDXI_LIMIT_RU || var.getFlag(FLAG_LIMITHIGHR) == false) - { - var.setFlag(FLAG_LIMITHIGHR, true, "IO:Limit Sensor(RU) Changed"); - hmi.SendMessage(F("SET:FLAG:HIGH_LIMITR:1"), false); - } - else { - bool b1 = bitRead(var.IOData, IDXI_LIMIT_LU); - bool b2 = bitRead(var.IOData, IDXI_LIMIT_RU); - if (b1 == false && var.getFlag(FLAG_LIMITHIGHL) == true) - { - var.setFlag(FLAG_LIMITHIGHL, false, "IO:Limit Sensor(LU) Changed"); - hmi.SendMessage(F("SET:FLAG:HIGH_LIMITL:0"), false); - } - if (b2 == false && var.getFlag(FLAG_LIMITHIGHR) == true) - { - var.setFlag(FLAG_LIMITHIGHR, false, "IO:Limit Sensor(RU) Changed"); - hmi.SendMessage(F("SET:FLAG:HIGH_LIMITR:0"), false); - } - } - - } - - //오버로드 플래그 활성화 - if (index == IDXI_OVERLOADL) - { - mot.SetZRun(ZRUN_STOP); - hmi.SendMessage(F("All Mot Stop by OverloadL"), false); - } - else if (index == IDXI_OVERLOADR) - { - mot.SetZRun(ZRUN_STOP); - hmi.SendMessage(F("All Mot Stop by OverloadR"), false); - } - - } - else //해당값이 OFF 되었다 - { - - //대상이 리밋센서라면 플래그를 설정 해준다 - if (index == IDXI_LIMIT_LD) - { - - hmi.SendMessage("Limit Sensor(LD) Change " + String(index) + "=" + String(newValue), false); - if (var.getFlag(FLAG_LIMITLOWL) == true) - { - var.setFlag(FLAG_LIMITLOWL, false, "IO:Limit Sensor Changed(LD)"); - hmi.SendMessage(F("SET:FLAG:LOW_LIMIT:0"), false); - } - } - else if (index == IDXI_LIMIT_RD) - { - - hmi.SendMessage("Limit Sensor(RD) Change " + String(index) + "=" + String(newValue), false); - if (var.getFlag(FLAG_LIMITLOWR) == true) - { - var.setFlag(FLAG_LIMITLOWR, false, "IO:Limit Sensor Changed(RD)"); - hmi.SendMessage(F("SET:FLAG:LOW_LIMIT:0"), false); - } - } - else if (index == IDXI_LIMIT_LU ) - { - hmi.SendMessage("Limit Sensor(LU) Change " + String(index) + "=" + String(newValue), false); - if (var.getFlag(FLAG_LIMITHIGHL) == true) - { - var.setFlag(FLAG_LIMITHIGHL, false, "IO:Limit Sensor Changed(LU)"); - hmi.SendMessage(F("SET:FLAG:HIGH_LIMIT:0"), false); - } - } - else if (index == IDXI_LIMIT_RU) - { - hmi.SendMessage("Limit Sensor(RU) Change " + String(index) + "=" + String(newValue), false); - if (var.getFlag(FLAG_LIMITHIGHR) == true) - { - var.setFlag(FLAG_LIMITHIGHR, false, "IO:Limit Sensor Changed(RU)"); - hmi.SendMessage(F("SET:FLAG:HIGH_LIMIT:0"), false); - } - } - } - } - else //출력포트 - { - //일반적으로 Rising 상태일때에만 동작시킨다. - if (newValue == true) - { - - } - } -} - -IoClass io; diff --git a/Arduino_PLC/IO.h b/Arduino_PLC/IO.h deleted file mode 100644 index a3a3755..0000000 --- a/Arduino_PLC/IO.h +++ /dev/null @@ -1,136 +0,0 @@ -#ifndef _IO_H_ -#define _IO_H_ -#include "Arduino.h" - -class IoClass -{ -public: - -//input pin -#define PINI_EMG 30 -#define PINI_BTN_1 31 -#define PINI_BTN_2 32 -#define PINI_BTN_3 33 -#define PINI_BTN_4 34 - -#define PINI_OVERLOADL1 35 -#define PINI_OVERLOADL2 36 - -#define PINI_OVERLOADR1 37 -#define PINI_OVERLOADR2 38 - -#define PINI_EMPTY_38 39 - -#define PINI_BTN_ZUP 40 -#define PINI_BTN_ZDN 41 -#define PINI_LIMIT_LU 42 -#define PINI_LIMIT_LD 43 -#define PINI_LIMIT_RU 44 -#define PINI_LIMIT_RD 45 -#define PINI_STOP 46 - -//send data index -#define IDXI_EMG 0 -#define IDXI_BTN_1 1 -#define IDXI_BTN_2 2 -#define IDXI_BTN_3 3 -#define IDXI_BTN_4 4 -#define IDXI_OVERLOADL 5 -#define IDXI_OVERLOADR 6 -#define IDXI_EMPTY7 7 -#define IDXI_EMPTY8 8 -#define IDXI_BTN_ZUP 9 -#define IDXI_BTN_ZDN 10 -#define IDXI_LIMIT_LU 11 -#define IDXI_LIMIT_LD 12 -#define IDXI_LIMIT_RU 13 -#define IDXI_LIMIT_RD 14 -#define IDXI_STOP 15 - -//output -#define PINO_GUIDEMOTOR_LDIR 22 //Guide Motor Direction -#define PINO_GUIDEMOTOR_LRUN 23 //Guide Motor Start -#define PINO_GUIDEMOTOR_RDIR 24 // -#define PINO_GUIDEMOTOR_RRUN 25 //Guide Motor Run(STA�� ����ȭ�� [IO.cpp:Update()] ) -#define PINO_EMPTY_26 26 -#define PINO_EMPTY_27 27 -#define PINO_EMPTY_28 28 -#define PINO_EMPTY_29 29 - - -#define IDXO_GUIDEMOTOR_LDIR 0 //Guide Motor Direction -#define IDXO_GUIDEMOTOR_LRUN 1 //Guide Motor Start -#define IDXO_GUIDEMOTOR_RDIR 2 // -#define IDXO_GUIDEMOTOR_RRUN 3 //Guide Motor Run(STA�� ����ȭ�� [IO.cpp:Update()] ) -#define IDXO_EMPTY_04 4 -#define IDXO_EMPTY_05 5 -#define IDXO_EMPTY_06 6 -#define IDXO_EMPTY_07 7 -#define IDXO_EMPTY_08 8 -#define IDXO_CHARGE_ON 9 -#define IDXO_MOT_POWER_L 10 -#define IDXO_MOT_POWER_R 11 -#define IDXO_EMPTY_42 12 -#define IDXO_EMPTY_43 13 -#define IDXO_EMPTY_44 14 -#define IDXO_EMPTY_45 15 - -//�Ƴ��α��Է�(�ɹ�ȣ) -#define PINAI_0 A0 //���׳ݼ���(FRONT) ��ġ �� -#define PINAI_1 A1 //���׳ݼ���(REAR) ��ġ �� -#define PINAI_2 A2 //�������� -#define PINAI_3 A3 //���͸� ���� �б� - -//�Ƴ��α� �Է�(�������ε���) -#define IDXAI_0 0 -#define IDXAI_1 1 -#define IDXAI_2 2 -#define IDXAI_3 3 - -//�Ƴ��α����(PWM) -#define PINAO_4 A4 //Z�� ���� �ӵ� -#define PINAO_5 A5 //���ʸ��� �ӵ� -#define PINAO_6 A6 //���ʸ��� �ӵ� -#define PINAO_7 A7 //�����ʸ��� �ӵ� - -//�Ƴ��α����(������ �ε���) -#define IDXAO_0 0 //Z�� ���� �ӵ� -#define IDXAO_1 1 //(��+��) ���� -#define IDXAO_2 2 //���ʸ��� �ӵ� -#define IDXAO_3 3 //�����ʸ��� �ӵ� - -#define MAF_SIZE 30 - - void Setup(); - void Update(); - bool IsPowerLoss(); -private: - - int bufferF[MAF_SIZE]; - int indexF = 0; - int countF = 0; - int iF; - int sumF = 0; - int tempF; - float avgF; - - int bufferB[MAF_SIZE]; - int indexB = 0; - int countB = 0; - int iB; - int sumB = 0; - int tempB; - float avgB; - - long tm_gateoutOn = 0; - long tm_gateoutOf = 0; - long tm_markOn = 0; - long tm_markOff = 0; - - unsigned long runtime = 0; - void IOValueChanged(bool isout, uint8_t index, bool newValue); - -}; - -extern IoClass io; -#endif diff --git a/Arduino_PLC/ReadMe.txt b/Arduino_PLC/ReadMe.txt deleted file mode 100644 index e183e16..0000000 --- a/Arduino_PLC/ReadMe.txt +++ /dev/null @@ -1 +0,0 @@ -221116 B라인용 소스 정리 작업 진행 \ No newline at end of file diff --git a/Arduino_PLC/StructInfo.txt b/Arduino_PLC/StructInfo.txt deleted file mode 100644 index e69de29..0000000 diff --git a/Arduino_PLC/UtilClass.cpp b/Arduino_PLC/UtilClass.cpp deleted file mode 100644 index 954c8c7..0000000 --- a/Arduino_PLC/UtilClass.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "UtilClass.h" -#include "VarClass.h" -#include "arduino.h" - -uint32_t UtilClass::b2i(bool Value) -{ - if (Value == true) return 1; - else return 0; -} - -uint8_t UtilClass::spdConvPercToValue(uint8_t perc) -{ - uint8_t retval = map(perc, 0, 100, 0, 255); // perc / 100 * 255; - return retval; //,0,255,0,100)); -} - -void UtilClass::copy(byte* src, byte* dst, byte len) { - memcpy(dst, src, sizeof(src[0])*len); -} - -UtilClass util; \ No newline at end of file diff --git a/Arduino_PLC/UtilClass.h b/Arduino_PLC/UtilClass.h deleted file mode 100644 index e49b89d..0000000 --- a/Arduino_PLC/UtilClass.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef _UTILCLASS_H_ -#define _UTILCLASS_H_ -#include "arduino.h" - -class UtilClass -{ - -public: - - void copy(byte* src, byte* dst, byte len); - uint32_t b2i(bool Value); - uint8_t spdConvPercToValue(uint8_t perc); - - //void debug(char *str, ...); -}; -extern UtilClass util; -#endif diff --git a/Arduino_PLC/VarClass.cpp b/Arduino_PLC/VarClass.cpp deleted file mode 100644 index c5463f1..0000000 --- a/Arduino_PLC/VarClass.cpp +++ /dev/null @@ -1,271 +0,0 @@ -#include "VarClass.h" -#include "motor.h" -#include "IO.h" -#include "HmiClass.h" - - -void VarClass::Setup() -{ - hmi.SendMessage("##:VAR:SETUP", false); - - for(int i = 0 ; i < 4;i++) - { - ANData[i] = 0; - AOData[i] = 0; - } -} -void VarClass::Update() -{ - /* - if (var.getFlag(FLAG_CHARGEONM) == true) - { - //���� �����̶�� �ڵ� �����¸� �����Ѵ� - if (var.getFlag(FLAG_AUTORUN) == true) - var.setFlag(FLAG_AUTORUN, false, "Manual Charge Mode"); - } - */ -} - - -/* �ܺθ���� �����մϴ�. HMI�� ���� ����̳� RS232�� REMOTE ��ɿ� ���� */ -void VarClass::runCommand(eCommand cmd, uint8_t p1, uint8_t p2) -{ - /*String msg = ("RunCommand "); - msg += String(cmd); - msg += (":"); - msg += String(p1); - msg += (":"); - msg += String(p2); - hmi.SendMessage(msg, false);*/ - - //display data - var.pingtime = millis(); - bool newValue = false; - - if (cmd == LOAD) - { - var.eeprom_load(); - } - else if (cmd == SAVE) - { - var.eeprom_save(); - } - else if (cmd == RESET) - { - var.runReset = true; - } - else if (cmd == SET_PINMODE) - { - pinMode(p1, p2); //�ش����� IO��带 �����Ѵ� - } - else if (cmd == SET_DOUTPUT) - { - String msg = ("Remote:Output:"); - msg += String(p1); - msg += ','; - msg += String(p2); - hmi.SendMessage(msg, false); - digitalWrite(p1, p2); - } - else if (cmd == SET_AOUTPUT) - { - if (p1 == 11) var.AOData[0] = p2; - else if (p1 == 12) var.AOData[1] = p2; - - analogWrite(p1, p2); - - String msg = ("Set PWM Out:"); - msg += String(p1); - msg += ','; - msg += String(p2); - hmi.SendMessage(msg, false); - } - else if (cmd == SET_FLAG) - { - String msg = ("@FLAG|"); - msg += String(p1); - msg += ','; - msg += String(p2); - hmi.SendMessage(msg, false); - - if (p2 == 1) var.setFlag(p1, true, "Remote"); - else var.setFlag(p1, false, "Remote"); - - if (p2 == 1 && p1 == FLAG_SETUP) - { - hmi.SendMessage("Entering Setup Mode", false); - } - } - else if (cmd == SET_EEPROM) - { - if (p1 == EEP_IOINTERVAL) { - var._eep_iosendinterval = p2; - hmi.SendMessage("(EEP) I/O Interval = " + String(p2), false); - } - else if (p1 == EEP_RESETCOUNT) { - hmi.SendMessage("(EEP) EEP_RESETCOUNT = " + String(p2), false); - } - else hmi.SendMessage("Set_ErrpRom p1 error", false); - //var.eeprom_save(); - } - else if (cmd == GET_SETTING) - { - //���� �������� �����Ѵ� - //�̰DZ����ؾ��� - } - - else if (cmd == GUIDE_MOT) - { - if (p1 == 'L') //left - { - if (p2 == 'P') - { - mot.SetZDir(ZDIR_CW); - mot.SetZRunL(true); - } - else if (p2 == 'N') - { - mot.SetZDir(ZDIR_CCW); - mot.SetZRunL(true); - } - else if (p2 == 'S') - { - mot.SetZRunL(false); - } - } - else if (p1 == 'R') //right - { - if (p2 == 'P') - { - mot.SetZDir(ZDIR_CW); - mot.SetZRunR(true); - } - else if (p2 == 'N') - { - mot.SetZDir(ZDIR_CCW); - mot.SetZRunR(true); - } - else if (p2 == 'S') - { - mot.SetZRunR(false); - } - } - else if (p1 == 'A') //all - { - if (p2 == 'P') - { - mot.SetZRun(ZRUN_UP); - } - else if (p2 == 'N') - { - mot.SetZRun(ZRUN_DN); - } - else if (p2 == 'S') - { - mot.SetZRun(ZRUN_STOP); - } - } - } - else if (cmd == PINGCHK) - { - //�ƹ��͵� ó������ �ʴ´�. - } - else { - hmi.SendMessage(F("Unknown Command"), true); - } -} - -void VarClass::eeprom_save() -{ - //param - EEPROM.write(EEP_IOINTERVAL, var._eep_iosendinterval); - EEPROM.write(EEP_RESETCOUNT, var._eep_resetcount); - EEPROM.write(EEP_DIREVH, var._eep_pindir_iH); - EEPROM.write(EEP_DIREVL, var._eep_pindir_iL); - - //�ɼǰ� ���� - bool opt1 = var.getFlag(FLAG_ENABLE_AD4INVERT); - bool opt2 = var.getFlag(FLAG_ENABLE_LOG_SPEED); - //bool opt3 = var.getFlag(FLAG_ENABLE_BALANCE); - //bool opt4 = var.getFlag(FLAG_ENABLE_LIDARSTOP); - //bool opt5 = var.getFlag(FLAG_ENABLE_GATEOUT); - - bitWrite(var._eep_option, FLAG_ENABLE_AD4INVERT - 24, opt1); - bitWrite(var._eep_option, FLAG_ENABLE_LOG_SPEED - 24, opt2); - //bitWrite(var._eep_option, FLAG_ENABLE_BALANCE - 24, opt3); - //bitWrite(var._eep_option, FLAG_ENABLE_LIDARSTOP - 24, opt4); - //bitWrite(var._eep_option, FLAG_ENABLE_GATEOUT - 24, opt5); - - //hmi.SendMessage("Option Store Value=" + String(var._eep_option), false); - EEPROM.write(EEP_OPTION, var._eep_option); //���� 200402 - hmi.SendMessage("@SET|SAVE:" + String(var._eep_option), false); -} - -void VarClass::eeprom_load() -{ - //hmi.SendMessage("##:EEPROM:LOAD:BEGIN", false); - var._eep_iosendinterval = EEPROM.read(EEP_IOINTERVAL); - var._eep_resetcount = EEPROM.read(EEP_RESETCOUNT); - var._eep_pindir_iH = EEPROM.read(EEP_DIREVH); - var._eep_pindir_iL = EEPROM.read(EEP_DIREVL); - var._eep_option = EEPROM.read(EEP_OPTION); //�ɼǰ��� �����س��� ����Ѵ� - - //�ɼǰ� ���� - bool opt1 = bitRead(var._eep_option, FLAG_ENABLE_AD4INVERT - 24); - bool opt2 = bitRead(var._eep_option, FLAG_ENABLE_LOG_SPEED - 24); - - - if (var._eep_iosendinterval == 0 || var._eep_iosendinterval == 0xFF) - var._eep_iosendinterval = 50; - - - - hmi.SendMessage("@SET|LOAD:" + String(var._eep_option), false); -} - -void VarClass::eeprom_incResetCount() -{ - EEPROM.write(EEP_RESETCOUNT, _eep_resetcount); - hmi.SendMessage(F("Increase Reset Count"), false); -} - -/* - system flag - */ -void VarClass::setFlag(uint8_t pos, bool value, String Readson) -{ - //������Ȯ�� - bool oldValue = bitRead(var.flag, pos); - - //##################################### - // 값이 변경된 경우에 처리 - //##################################### - if (oldValue != value) - { - bitWrite(var.flag, pos, value); - - if (pos == FLAG_AUTORUN) - { - if (value == true) - { - - } - } - else if (pos == FLAG_STOPZ) - { - hmi.SendMessage("Z-Stop Condition => " + String(value) + ": " + Readson, false); - } - - } -} - -bool VarClass::getFlag(uint8_t pos) -{ - return bitRead(var.flag, pos); -} -uint32_t VarClass::getFlagValue() -{ - return var.flag; -} - -VarClass var; diff --git a/Arduino_PLC/VarClass.h b/Arduino_PLC/VarClass.h deleted file mode 100644 index 73d270e..0000000 --- a/Arduino_PLC/VarClass.h +++ /dev/null @@ -1,119 +0,0 @@ -#ifndef _VAR_H_ -#define _VAR_H_ - -#define DEBUG -#define sprint(...) Serial1.print(__VA_ARGS__) -#define sprintln(...) Serial1.println(__VA_ARGS__) -#ifdef DEBUG -#define dprint(...) Serial1.print(__VA_ARGS__) -#define dprintln(...) Serial1.println(__VA_ARGS__) -#else -#define dprint(...) -#define dprint(...) -#endif - - -#include "arduino.h" -#include -#include "UtilClass.h" - -//모든 사용가능한 커맨드를 넣는다(이 파일은 서브PLC파일) -enum eCommand -{ - LOAD = 0, //EEPROM 불러오기 - SAVE, //EEPROM 저장 - RESET, //초기화 - PINGCHK, - SET_PINMODE, //PINMODE 설정 - SET_DOUTPUT, //디지털출력설정(포트번호,값[1,0]) - SET_AOUTPUT, //아날로그출력설정(포트GET_SETTING = 50, //셋팅값 요청 - SET_FLAG, - SET_EEPROM, - SET_MANUALSPEED, - GET_SETTING = 50, - GUIDE_MOT= 90, //가이드커버(양쪽) 0=멈춤,1=UP,2=DN 아스키코드표 90=Z - SET_EEP_DIREV, -}; - -//asci 0=48,1=49,2=50 - -enum eEEPAddress -{ - EEP_IOINTERVAL = 0, - EEP_RESETCOUNT, - EEP_DIREVH, - EEP_DIREVL, - EEP_OPTION, - EEP_UPTIME, -}; - -//플래그 총 32개 모두 다씀 -enum eFlag -{ - FLAG_STOPZ= 0, - FLAG_SETUP, - FLAG_WAIT, - FLAG_AUTORUN, - FLAG_MANUALRUN, - FLAG_LIMITHIGHL, - FLAG_LIMITHIGHR, - FLAG_LIMITLOWL, - FLAG_LIMITLOWR, - FLAG_POWERLOSS, - FLAG_DIR, - FLAG_LEFT_RUN, - FLAG_RIGHT_RUN, - FLAG_RUN_CMD, - FLAG_GO_CHAGER = 26, - FLAG_ENABLE_AD4INVERT=27, - FLAG_ENABLE_LOG_SPEED = 28, -}; - -class VarClass -{ - -public: - - unsigned long serialprinttime = 0; - uint16_t runtime = 0; - long pingtime = 0; - - //SUB - - uint32_t IOData = 0; //IO데이터가 있으며 DI : Low 16bit, DO : High 16bit - uint8_t ANData[4]; //A0 ~ A3 - uint8_t AOData[4]; //A4 ~ A6 - - void Setup(); - void Update(); - void runCommand(eCommand cmd, uint8_t p1, uint8_t p2); - - uint8_t _eep_resetcount = 0; //장치초기화 횟수 - uint8_t _eep_iosendinterval = 0; - - uint8_t _eep_option = 0; //옵션값(이 값은 FLAG와 연결됨) - - uint8_t _eep_pindir_iH = 0; //Input High - uint8_t _eep_pindir_iL = 0; //Input Low - - uint8_t manual_speed = 0; //속도고정값 - - void eeprom_save(); //EEPROM 쓰기 - void eeprom_load(); //EEPROM 읽기 - void eeprom_incResetCount(); //초기화횟수증가 및 저장 - - void setFlag(uint8_t pos, bool value, String Readson); //플래그쓰기 - bool getFlag(uint8_t pos); //플래그읽기 - uint32_t getFlagValue(); //플래그값확인 - - bool runReset = false; //이값을 설정하면 Project.Ino 에서 초기화를 수행함 - -private: - - uint32_t flag = 0; //시스템플래그 - uint32_t flag_ = 0; - //void FlagValueChanged(uint8_t index, bool newValue); -}; - -extern VarClass var; -#endif diff --git a/Arduino_PLC/motor.cpp b/Arduino_PLC/motor.cpp deleted file mode 100644 index c76ac65..0000000 --- a/Arduino_PLC/motor.cpp +++ /dev/null @@ -1,256 +0,0 @@ -#include "motor.h" -#include "IO.h" -#include "VarClass.h" -#include "UtilClass.h" -#include "HmiClass.h" - -void motor::Setup() -{ - hmi.SendMessage("##:MOT:SETUP", false); - - //Z축 멈춤 - SetZRun(ZRUN_STOP); -} -void motor::Update() -{ - //########################## - // 사용자추가코드 - //########################## - - if (var.pingtime == 0 || var.pingtime > millis()) var.pingtime = millis(); - long runtime = millis() - var.pingtime; - - //중지조건 체크 - //(충전중, 비상정지, 오버로드, 설정화면) - bool bStop1 = var.getFlag(FLAG_SETUP); - bool bStop2L = bitRead(var.IOData, IDXI_OVERLOADL); - bool bStop2R = bitRead(var.IOData, IDXI_OVERLOADR); - bool bStop3 = bitRead(var.IOData, IDXI_EMG); - bool bStop4 = bitRead(var.IOData, IDXI_STOP); - - //중지조건이 활성화되었다면 처리 - String stpReason = ""; - - //Z축 중지는 오버로드만 확읺ㄴ다. - if (bStop3== true) - { - if (var.getFlag(FLAG_STOPZ) == false) - { - dbgSerial.println("Set Flag On: flag_stopz by EMG"); - var.setFlag(FLAG_STOPZ, true, "MotUpdate"); - } - } - else if (bStop2L == true) - { - if (var.getFlag(FLAG_STOPZ) == false) - { - dbgSerial.println("Set Flag On: flag_stopz by OverloadL"); - var.setFlag(FLAG_STOPZ, true, "MotUpdate_OVLL"); - } - } - else if (bStop2R == true) - { - if (var.getFlag(FLAG_STOPZ) == false) - { - dbgSerial.println("Set Flag On: flag_stopz by OverloadR"); - var.setFlag(FLAG_STOPZ, true, "MotUpdate_OVLR"); - } - } - else if (var.getFlag(FLAG_STOPZ) == true) - { - dbgSerial.println("Set Flag Off"); - var.setFlag(FLAG_STOPZ, false, "MotUpdate"); - } - - //가이드 모터 동작시 Limit 센서 체크 - ZLimit_AutoStop(); - - if (var.getFlag(FLAG_STOPZ) == true) - { - if (IsMoveZ() == true) - { - Serial.println("Z-Axis Auto Stop by 'STOP-Z' Condition"); - mot.SetZRun(ZRUN_STOP); - } - } - - //Serial.println("motor update"); -} - - -//Z축이 동작죽이라면 리밋센서값을 보고 자동으로 멈춥니다 -void motor::ZLimit_AutoStop() -{ - if (mot.IsMoveZ() == true) - { - //정방향이동시(올라간다) - if (mot.GetZDirL() == ZDIR_CW) - { - if (bitRead(var.IOData, IDXI_OVERLOADL) == true ) //오버로드 활성화시 멈춤 - { - mot.SetZRun(ZRUN_STOP); - if (var.getFlag(FLAG_SETUP) == false) hmi.SendMessage("Z-Axis Auto Stop by OverloadL", false); - } - else if (bitRead(var.IOData, IDXI_OVERLOADR) == true ) //오버로드 활성화시 멈춤 - { - mot.SetZRun(ZRUN_STOP); - if (var.getFlag(FLAG_SETUP) == false) hmi.SendMessage("Z-Axis Auto Stop by OverloadR", false); - } - else { - //상단센서가 하나라도 동작하면 멈춘다 - if (mot.IsMoveZL() == true && bitRead(var.IOData, IDXI_LIMIT_LU) == true) - { - mot.SetZRunL(false); - if (var.getFlag(FLAG_SETUP) == false) hmi.SendMessage("Z-Axis (Left) Auto Stop by Upper Limit", false); - } - if (mot.IsMoveZR() == true && bitRead(var.IOData, IDXI_LIMIT_RU) == true) - { - mot.SetZRunR(false); - if (var.getFlag(FLAG_SETUP) == false)hmi.SendMessage("Z-Axis (Right) Auto Stop by Upper Limit", false); - } - } - } - else //역방향이동(내려간다) - { - //하단센서가 하나라도 동작하면 멈춘다 - if (mot.IsMoveZL() == true && bitRead(var.IOData, IDXI_LIMIT_LD) == true) - { - mot.SetZRunL(false); - if (var.getFlag(FLAG_SETUP) == false)hmi.SendMessage("Z-Axis (Left) Auto Stop by Lower Limit", false); - } - if (mot.IsMoveZR() == true && bitRead(var.IOData, IDXI_LIMIT_RD) == true) - { - mot.SetZRunR(false); - if (var.getFlag(FLAG_SETUP) == false)hmi.SendMessage("Z-Axis (Right) Auto Stop by Lower Limit", false); - } - } - } -} - - - -//가이드 모터 진행방향을 반환(CW:Up, CCW:Down) -ZDirection motor::GetZDirL() -{ - bool value = bitRead(var.IOData, IDXO_GUIDEMOTOR_LDIR + 16); - if (value == false) return ZDIR_CW; - else return ZDIR_CCW; -} -ZDirection motor::GetZDirR() -{ - bool value = bitRead(var.IOData, IDXO_GUIDEMOTOR_RDIR + 16); - if (value == false) return ZDIR_CW; - else return ZDIR_CCW; -} - -//가이드 모터(좌+우) 동작 여부 -bool motor::IsMoveZ() -{ - if (IsMoveZL() == true) return true; - else if (IsMoveZR() == true) return true; - else return false; -} - -//가이드 모터(좌) 동작 여부 -bool motor::IsMoveZL() -{ - bool v1 = bitRead(var.IOData, IDXO_GUIDEMOTOR_LRUN + 16); - //bool v2 = bitRead(var.IOData, IDXO_GUIDEMOTOR_LEFT + 16); - return v1 ; -} - -//가이드 모터(우) 동작 여부 -bool motor::IsMoveZR() -{ - bool v1 = bitRead(var.IOData, IDXO_GUIDEMOTOR_RRUN + 16); - //bool v2 = bitRead(var.IOData, IDXO_GUIDEMOTOR_RIGHT + 16); - return v1 ; -} - -//가이드모터 진행방향 결정(True:정방향, False:역방향) -void motor::SetZDir(ZDirection direction) -{ - if (direction == ZDIR_CW) { - digitalWrite(PINO_GUIDEMOTOR_LDIR, LOW); - digitalWrite(PINO_GUIDEMOTOR_RDIR, LOW); - } - else { - digitalWrite(PINO_GUIDEMOTOR_LDIR, HIGH); - digitalWrite(PINO_GUIDEMOTOR_RDIR, HIGH); - } -} - -void motor::SetZRun(ZRunMode runMode) { - - bool bEmg = var.getFlag(FLAG_STOPZ); //Z축이 움직이면 안되는 조건이므로 처리하지 않는다. - - if (runMode == ZRUN_UP) - { - if (bEmg) { - hmi.SendMessage("[Ignore] Z-Run by Stop-Z Flag", true); - return; - } - SetZDir(ZDIR_CW); - SetZRunL(true); - SetZRunR(true); - if (var.getFlag(FLAG_SETUP) == false) hmi.SendMessage("Guide Up", false); - } - else if (runMode == ZRUN_DN) - { - if (bEmg) { - hmi.SendMessage("[Ignore] Run by Stop-Z Flag", true); - return; - } - SetZDir(ZDIR_CCW); - SetZRunL(true); - SetZRunR(true); - if (var.getFlag(FLAG_SETUP) == false) hmi.SendMessage("Guide Dn", false); - } - else if (runMode == ZRUN_STOP) - { - SetZRunL(false); - SetZRunR(false); - if (var.getFlag(FLAG_SETUP) == false) hmi.SendMessage("Guid Stop", false); - //digitalWrite(PINO_GUIDEMOTOR_RUN, LOW); - } -} - -void motor::SetZRunL(bool run) { - if (run == true) - { - //if (var.getFlag(FLAG_SETUP) == false) hmi.SendMessage("Z-Axis Left Run", false); - digitalWrite(PINO_GUIDEMOTOR_LRUN, HIGH); - //digitalWrite(PINO_GUIDEMOTOR_RUN, HIGH); - } - else { - digitalWrite(PINO_GUIDEMOTOR_LRUN, LOW); - //L,R둘다 꺼져있다면 STA도 끈다 - //if (bitRead(var.IOData, IDXO_GUIDEMOTOR_RIGHT + 16) == false) - //{ - // if (var.getFlag(FLAG_SETUP) == false)hmi.SendMessage("Z-Axis Sta Off by Right", false); - // digitalWrite(PINO_GUIDEMOTOR_RUN, LOW); - //} - } - -} - -void motor::SetZRunR(bool run) { - if (run == true) - { - //if (var.getFlag(FLAG_SETUP) == false) hmi.SendMessage("Z-Axis Right Run", false); - digitalWrite(PINO_GUIDEMOTOR_RRUN, HIGH); - //digitalWrite(PINO_GUIDEMOTOR_RUN, HIGH); - } - else { - digitalWrite(PINO_GUIDEMOTOR_RRUN, LOW); - //L,R둘다 꺼져있다면 STA도 끈다 - //if (bitRead(var.IOData, IDXO_GUIDEMOTOR_LEFT + 16) == false) - //{ - // if (var.getFlag(FLAG_SETUP) == false) hmi.SendMessage("Z-Axis Sta Off by Right", false); - // digitalWrite(PINO_GUIDEMOTOR_RUN, LOW); - //} - } -} - - -motor mot; diff --git a/Arduino_PLC/motor.h b/Arduino_PLC/motor.h deleted file mode 100644 index 8a2ce92..0000000 --- a/Arduino_PLC/motor.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef _MOTOR_H_ -#define _MOTOR_H_ -#include "arduino.h" -#include "VarClass.h" - -enum ZRunMode -{ - ZRUN_STOP = 0, - ZRUN_UP, - ZRUN_DN -}; -enum ZDirection -{ - ZDIR_CW = 0, - ZDIR_CCW -}; - -class motor { - -public: - - void Setup(); - void Update(); - - void SetSpeedZ(uint8_t value); - - ZDirection GetZDirL(); //Z축 진행방향을 표시합니다. True 일경우, 정방향(위로), False일경우 역방향(아래로) - ZDirection GetZDirR(); //Z축 진행방향을 표시합니다. True 일경우, 정방향(위로), False일경우 역방향(아래로) - void SetZDir(ZDirection direction); //1=정방향, 0=역방향 - - void SetZRun(ZRunMode run); - void SetZRunL(bool run); - void SetZRunR(bool run); - - - bool IsMoveZ(); //현재 이동중인가? - -private: - - void SetPowerL(bool on); - void SetPowerR(bool on); - - bool IsMoveZL(); - bool IsMoveZR(); - - void ZLimit_AutoStop(); //Z축 리밋센서에 의한 동작 정지 - -}; - -extern motor mot; - -#endif diff --git a/Cs_HMI/AGVCSharp.sln b/Cs_HMI/AGVCSharp.sln index 11bc2c9..758792a 100644 --- a/Cs_HMI/AGVCSharp.sln +++ b/Cs_HMI/AGVCSharp.sln @@ -41,6 +41,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MSSQLCommand", "SubProject\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "arCommUtil", "SubProject\CommUtil\arCommUtil.csproj", "{14E8C9A5-013E-49BA-B435-FFFFFF7DD623}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ENIGProtocol", "..\..\Protocol\enigprotocol\ENIGProtocol.csproj", "{16BD025D-CB0F-4A4B-A452-8FE629F02F0C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -248,6 +250,18 @@ Global {14E8C9A5-013E-49BA-B435-FFFFFF7DD623}.Release|x64.Build.0 = Release|Any CPU {14E8C9A5-013E-49BA-B435-FFFFFF7DD623}.Release|x86.ActiveCfg = Release|x86 {14E8C9A5-013E-49BA-B435-FFFFFF7DD623}.Release|x86.Build.0 = Release|x86 + {16BD025D-CB0F-4A4B-A452-8FE629F02F0C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {16BD025D-CB0F-4A4B-A452-8FE629F02F0C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {16BD025D-CB0F-4A4B-A452-8FE629F02F0C}.Debug|x64.ActiveCfg = Debug|Any CPU + {16BD025D-CB0F-4A4B-A452-8FE629F02F0C}.Debug|x64.Build.0 = Debug|Any CPU + {16BD025D-CB0F-4A4B-A452-8FE629F02F0C}.Debug|x86.ActiveCfg = Debug|Any CPU + {16BD025D-CB0F-4A4B-A452-8FE629F02F0C}.Debug|x86.Build.0 = Debug|Any CPU + {16BD025D-CB0F-4A4B-A452-8FE629F02F0C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {16BD025D-CB0F-4A4B-A452-8FE629F02F0C}.Release|Any CPU.Build.0 = Release|Any CPU + {16BD025D-CB0F-4A4B-A452-8FE629F02F0C}.Release|x64.ActiveCfg = Release|Any CPU + {16BD025D-CB0F-4A4B-A452-8FE629F02F0C}.Release|x64.Build.0 = Release|Any CPU + {16BD025D-CB0F-4A4B-A452-8FE629F02F0C}.Release|x86.ActiveCfg = Release|Any CPU + {16BD025D-CB0F-4A4B-A452-8FE629F02F0C}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -267,6 +281,7 @@ Global {EB77976F-4DE4-46A5-8B25-D07226204C32} = {7AF32085-E7A6-4D06-BA6E-C6B1EBAEA99A} {AAF68D20-4590-4AB0-BB91-E0DD04C91DEC} = {C423C39A-44E7-4F09-B2F7-7943975FF948} {14E8C9A5-013E-49BA-B435-FFFFFF7DD623} = {C423C39A-44E7-4F09-B2F7-7943975FF948} + {16BD025D-CB0F-4A4B-A452-8FE629F02F0C} = {C423C39A-44E7-4F09-B2F7-7943975FF948} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {B5B1FD72-356F-4840-83E8-B070AC21C8D9} diff --git a/Cs_HMI/Project/AGV4.csproj b/Cs_HMI/Project/AGV4.csproj index 9abdb03..34cda61 100644 --- a/Cs_HMI/Project/AGV4.csproj +++ b/Cs_HMI/Project/AGV4.csproj @@ -158,7 +158,10 @@ DataSet1.xsd - + + + Component + Form @@ -492,6 +495,10 @@ + + {16bd025d-cb0f-4a4b-a452-8fe629f02f0c} + ENIGProtocol + {8cb883c0-99c3-4dd4-b017-f9b92010a806} agvControl diff --git a/Cs_HMI/Project/CSetting.cs b/Cs_HMI/Project/CSetting.cs index 9889d3b..d0e4f0d 100644 --- a/Cs_HMI/Project/CSetting.cs +++ b/Cs_HMI/Project/CSetting.cs @@ -92,8 +92,8 @@ namespace Project [Category("Commnunication Setting"), DisplayName("RFID PortName"), Editor(typeof(MyUITypeEditor), typeof(UITypeEditor))] public string Port_AGV { get; set; } - [Category("Commnunication Setting"), DisplayName("PLC #1 PortName"), Editor(typeof(MyUITypeEditor), typeof(UITypeEditor))] - public string Port_PLC { get; set; } + [Category("Commnunication Setting"), DisplayName("Xbee ID"), Editor(typeof(MyUITypeEditor), typeof(UITypeEditor))] + public byte XBE_ID { get; set; } [Category("Commnunication Setting"), DisplayName("BMS PortName"), Editor(typeof(MyUITypeEditor), typeof(UITypeEditor))] @@ -103,7 +103,7 @@ namespace Project public int Baud_AGV { get; set; } public int Baud_BAT { get; set; } - public int Baud_PLC { get; set; } + //public int Baud_PLC { get; set; } public int Baud_XBE { get; set; } //public int QueryInterval_BAT { get; set; } @@ -284,7 +284,7 @@ namespace Project //public Single interval_bms { get; set; } public Single interval_xbe { get; set; } public int interval_bms { get; set; } - public byte interval_iostate { get; set; } + //public byte interval_iostate { get; set; } //public Boolean Enable_AutoZDnUp { get; set; } public int doorSoundTerm { get; set; } public int musicvol { get; set; } @@ -378,7 +378,7 @@ namespace Project if (ChargeSearchTime == 0) ChargeSearchTime = 25; //최대 충전진행 시간(기본 1시간) if (ChargeMaxTime == 0) ChargeMaxTime = 3600; - if (interval_iostate == 0 || interval_iostate == 255) interval_iostate = 100; + // if (interval_iostate == 0 || interval_iostate == 255) interval_iostate = 100; if (ZSpeed == 0) ZSpeed = 20; if (interval_xbe == 0) interval_xbe = 5.0f; if (HomePositionValue == 0) HomePositionValue = 4; @@ -418,12 +418,12 @@ namespace Project if (string.IsNullOrEmpty(Port_AGV)) Port_AGV = "COM1"; - if (string.IsNullOrEmpty(Port_PLC)) Port_PLC = "COM2"; + // if (string.IsNullOrEmpty(Port_PLC)) Port_PLC = "COM2"; if (string.IsNullOrEmpty(Port_XBE)) Port_XBE = "COM4"; if (string.IsNullOrEmpty(Port_BAT)) Port_BAT = "COM7"; if (Baud_AGV == 0) Baud_AGV = 57600; - if (Baud_PLC == 0) Baud_PLC = 19200; + //if (Baud_PLC == 0) Baud_PLC = 19200; if (Baud_XBE == 0) Baud_XBE = 9600; if (Baud_BAT == 0) Baud_BAT = 9600; diff --git a/Cs_HMI/Project/CtlAuto.cs b/Cs_HMI/Project/CtlAuto.cs index 19a215d..427b0e6 100644 --- a/Cs_HMI/Project/CtlAuto.cs +++ b/Cs_HMI/Project/CtlAuto.cs @@ -9,6 +9,7 @@ using System.Text; using System.Windows.Forms; using COMM; using System.Diagnostics; +using AR; namespace Project { @@ -42,7 +43,7 @@ namespace Project #endregion public arDev.BMS dev_bms { private get; set; } = null; - public arDev.FakePLC dev_plc { private get; set; } = null; + // public arDev.FakePLC dev_plc { private get; set; } = null; public arDev.Narumi dev_agv { private get; set; } = null; public Device.Xbee dev_xbe { private get; set; } = null; @@ -124,7 +125,6 @@ namespace Project this.Invalidate(); } } - public Color BorderColor { get; set; } private int _itemgap = 0; public int ItemGap { get { return _itemgap; } set { _itemgap = value; Invalidate(); } } @@ -138,8 +138,8 @@ namespace Project { get { - if (COMM.VAR.BOOL == null) return true; - else return COMM.VAR.BOOL[eVarBool.FLAG_AUTORUN]; + if (VAR.BOOL == null) return true; + else return VAR.BOOL[eVarBool.FLAG_AUTORUN]; } } @@ -488,7 +488,7 @@ namespace Project //상태메세지표시 string stmsg = string.Empty; - if (COMM.VAR.STR != null && COMM.VAR.STR[eVarString.StatusMessage].isEmpty() == false) stmsg = VAR.STR[eVarString.StatusMessage]; + if (VAR.STR != null && VAR.STR[eVarString.StatusMessage].isEmpty() == false) stmsg = VAR.STR[eVarString.StatusMessage]; else stmsg = "STATUS MESSAGE DEMO"; if (nextstop) stmsg += "|MARK-STOP"; @@ -665,39 +665,39 @@ namespace Project } - public bool LimitLU - { - get - { - if (dev_plc == null) return true; - return dev_plc.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_LU); - } + //public bool LimitLU + //{ + // get + // { + // if (dev_plc == null) return true; + // return dev_plc.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_LU); + // } - } - public bool LimitLD - { - get - { - if (dev_plc == null) return false; - return dev_plc.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_LD); - } - } - public bool LimitRU - { - get - { - if (dev_plc == null) return false; - return dev_plc.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_RU); - } - } - public bool LimitRD - { - get - { - if (dev_plc == null) return true; - return dev_plc.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_RD); - } - } + //} + //public bool LimitLD + //{ + // get + // { + // if (dev_plc == null) return false; + // return dev_plc.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_LD); + // } + //} + //public bool LimitRU + //{ + // get + // { + // if (dev_plc == null) return false; + // return dev_plc.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_RU); + // } + //} + //public bool LimitRD + //{ + // get + // { + // if (dev_plc == null) return true; + // return dev_plc.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_RD); + // } + //} void DrawMC(Graphics g) { @@ -794,11 +794,11 @@ namespace Project var coverLYOffset = 0; var coverRYOffset = 0; - if (LimitRD == true) coverRYOffset = 20; - else if (LimitRU == true) coverRYOffset = coverYOffset; + //if (LimitRD == true) coverRYOffset = 20; + //else if (LimitRU == true) coverRYOffset = coverYOffset; - if (LimitLD == true) coverLYOffset = 20; - else if (LimitLU == true) coverLYOffset = coverYOffset; + //if (LimitLD == true) coverLYOffset = 20; + //else if (LimitLU == true) coverLYOffset = coverYOffset; var PtsCoverBack = new PointF[] { new PointF( PtsBack[0].X+coverPadding, PtsBack[0].Y+coverLYOffset ), @@ -814,17 +814,17 @@ namespace Project new PointF( PtsFront[3].X+coverPadding, PtsFront[3].Y+coverRYOffset ) }; - if (LimitLU == true) - { - g.FillPolygon(new SolidBrush(Color.FromArgb(100, Color.Red)), PtsCoverBack); - g.DrawPolygon(new Pen(Color.DarkRed, 2), PtsCoverBack); - } - else if (LimitLD == true) - { - g.FillPolygon(new SolidBrush(Color.FromArgb(100, Color.Blue)), PtsCoverBack); - g.DrawPolygon(new Pen(Color.DarkBlue, 2), PtsCoverBack); - } - else + //if (LimitLU == true) + //{ + // g.FillPolygon(new SolidBrush(Color.FromArgb(100, Color.Red)), PtsCoverBack); + // g.DrawPolygon(new Pen(Color.DarkRed, 2), PtsCoverBack); + //} + //else if (LimitLD == true) + //{ + // g.FillPolygon(new SolidBrush(Color.FromArgb(100, Color.Blue)), PtsCoverBack); + // g.DrawPolygon(new Pen(Color.DarkBlue, 2), PtsCoverBack); + //} + //else { g.FillPolygon(new SolidBrush(Color.FromArgb(100, Color.Gray)), PtsCoverBack); g.DrawPolygon(Pens.DimGray, PtsCoverBack); @@ -835,17 +835,17 @@ namespace Project g.FillPolygon(new SolidBrush(Color.FromArgb(50, Color.White)), PtsFront); // g.DrawPolygon(Pens.Black, PtsFront); - if (LimitRU == true) - { - g.FillPolygon(new SolidBrush(Color.FromArgb(150, Color.Red)), PtsCoverFront); - g.DrawPolygon(new Pen(Color.DarkRed, 2), PtsCoverFront); - } - else if (LimitRD == true) - { - g.FillPolygon(new SolidBrush(Color.FromArgb(150, Color.Blue)), PtsCoverFront); - g.DrawPolygon(new Pen(Color.DarkBlue, 2), PtsCoverFront); - } - else + //if (LimitRU == true) + //{ + // g.FillPolygon(new SolidBrush(Color.FromArgb(150, Color.Red)), PtsCoverFront); + // g.DrawPolygon(new Pen(Color.DarkRed, 2), PtsCoverFront); + //} + //else if (LimitRD == true) + //{ + // g.FillPolygon(new SolidBrush(Color.FromArgb(150, Color.Blue)), PtsCoverFront); + // g.DrawPolygon(new Pen(Color.DarkBlue, 2), PtsCoverFront); + //} + //else { g.FillPolygon(new SolidBrush(Color.FromArgb(150, Color.Gray)), PtsCoverFront); g.DrawPolygon(Pens.DimGray, PtsCoverFront); diff --git a/Cs_HMI/Project/Device/Xbee _OLD.cs b/Cs_HMI/Project/Device/Xbee _OLD.cs new file mode 100644 index 0000000..51e3384 --- /dev/null +++ b/Cs_HMI/Project/Device/Xbee _OLD.cs @@ -0,0 +1,402 @@ +//using System; +//using System.Collections.Generic; +//using System.Linq; +//using System.Text; +//using System.ComponentModel; +//using System.Threading; +//using COMM; +//using System.Runtime.Remoting.Messaging; +//using AR; + +//namespace Project.Device +//{ +// public class Xbee_OLD : arDev.arRS232 +// { +// public Xbee_OLD() +// { + +// } + +// public string buffer = string.Empty; +// public System.Text.StringBuilder newbuffer = new StringBuilder(); +// protected override bool CustomParser(byte[] buf, out byte[] remainBuffer) +// { +// //일반 kit 명령은 0x02 kit번호, kit값 0x03 +// //상태 명령은 0x04 메세지데이터 0x05 + +// Console.WriteLine("custom parse len=" + buf.Length.ToString()); + +// List sparebuffer = new List(); +// Boolean bComplete = false; +// for (int i = 0; i < buf.Length; i++) +// { +// var incomByte = buf[i]; +// if (bComplete == true) sparebuffer.Add(incomByte); +// else +// { +// if (findSTX == false) +// { +// if (incomByte != 0x02) +// { +// //버리는데이터 +// } +// else +// { +// findSTX = true; +// tempBuffer.Clear(); +// tempBuffer.Add(incomByte); +// } +// } +// else +// { +// tempBuffer.Add(incomByte); + +// if (incomByte == 0x03) +// { +// //데이터가 맞게 수신됨 +// LastReceiveBuffer = tempBuffer.ToArray(); +// bComplete = true; +// findSTX = false; +// } +// else if (tempBuffer.Count > 30) +// { +// tempBuffer.Clear(); +// findSTX = false; +// } +// } +// } +// } +// remainBuffer = sparebuffer.ToArray(); +// return bComplete; +// } + + +// public override bool ProcessRecvData(byte[] data) +// { +// var kitno = (char)(data[1]); +// var kitval = (char)(data[2]); +// NewMsgEvent(kitno, kitval); +// return true; +// } + +// public void NewMsgEvent(char kitNo, char kitVal) +// { +// //대상위치 확인 +// ePosition kitPos = ePosition.NONE; +// if (kitNo == '9') kitPos = ePosition.QC; +// else if (kitNo == '1') kitPos = ePosition.F1; +// else if (kitNo == '2') kitPos = ePosition.F2; +// else if (kitNo == '3') kitPos = ePosition.F3; +// else if (kitNo == '4') kitPos = ePosition.F4; +// else +// { +// if (kitNo == '0') return; +// PUB.log.Add($"비허가 키트번호 무시 번호={kitNo},값={kitVal}"); +// return; +// } + +// //if (kitNo= 'F') +// //{ +// // PUB.Speak("알 수 없는 키트번호 입니다"); +// // PUB.logsys.Add($"키트번호별위치확인실패 값={kitNo}"); +// // return; +// //} + +// //(ePosition)int.Parse(kitNo.ToString()); +// PUB.logxbee.Add(string.Format("Xbee:newMsgEvent:{0},{1}=>{2}", kitNo, kitVal, kitPos)); +// if (PUB.CheckManualChargeMode() == false) +// { +// PUB.log.Add($"수동 충전 중이라 콜 기능을 취소 합니다"); +// return; +// } + +// bool FixButton = kitPos == ePosition.NONE; +// if (kitPos == ePosition.NONE) +// { +// if (kitVal == '1') kitPos = ePosition.QC; +// else if (kitVal == '2') kitPos = ePosition.CHARGE; +// else if (kitVal == '4') kitPos = ePosition.QC; +// //else if (kitVal == '3') kitPos = ePosition.QA; +// else +// { +// PUB.log.Add($"AGV버튼 이벤트 실행 값:{kitVal} 취소"); +// return; +// } +// kitVal = '1'; //버튼은 무조건 ON상태로 한다 +// } + +// //자동상태가 아니라면 오류처리 +// if (VAR.BOOL[eVarBool.FLAG_AUTORUN] == false || PUB.sm.Step != StateMachine.eSMStep.RUN) +// { +// PUB.log.AddE("'자동실행' 상태가 아니므로 콜/취소 작업을 할 수 없습니다 콜:" + kitPos.ToString() + ",값=" + kitVal.ToString()); +// PUB.Speak(Lang.자동운전상태가아닙니다); +// return; +// } + +// //충전기를 제외하고 '1'의 값은 호출을 원하는값이다.('0'=취소) +// if (kitVal == '1') +// { +// //qA혹은 Pack 에서 해당 버튼을 눌렀을때의 처리방법 +// //if (PUB.Result.CurrentPos == ePosition.QA && kitPos == ePosition.QA) +// //{ +// // PUB.logsys.AddE("QA위치에서 QA버튼을 눌렀음 명령 취소함"); +// // PUB.Speak("현재 위치는 QA 입니다."); +// // return; +// //} + +// //상/하차 작업중이 아니라면 콜을 받는다 +// if (PUB.sm.RunStep != StateMachine.ERunStep.GOUP && PUB.sm.RunStep != StateMachine.ERunStep.GODOWN) +// { +// //call을 받으려면 대상위 (2=QC,3,4,5,6,7) +// //콜을 요청하는 곳 (2=QC,3=FVI-1,4,5,6,7==FVI-5) +// //1번은 충전기 + +// //콜버튼으로 대상위치를 다시 결정한다. +// //대상번호는 콜번호에서 +2을 하면 된다. +// //대상번호 PK=1,QA2=2,QA1=3,QC=4 +// //QC의경우 콜Kit번호는 2이므로, 이동대상은 +2인 4가 되어야 함 +// //콜번호와 RFID대상번호는 2의 오차가 발생함, 현재 설치된 RFID를 모두 변경할 수 없어서 이렇게 운용함 + + +// RaiseMessage(MessageType.Normal, string.Format("CALL확정 Kit={0},대상위치={1}", kitNo, kitPos)); + +// PUB.AGV.data.CallNo = int.Parse(kitNo.ToString()); +// PUB.AGV.data.CallString = kitNo.ToString(); + +// PUB.Result.CommandKit = kitNo; +// PUB.Result.TargetPos = kitPos; +// SendToKit(kitNo, '1', (PUB.IsCanCALL() ? '1' : '0')); //콜확정을 클라이언트에 알림 + +// PUB.Speak(kitPos.ToString() + Lang.위치로이동합니다); + +// //상태머신을 변경한다 (충전 OFF상태로 간다, 충전상태가 아니면 바로 이동하게됨) +// //Pub.sm.ResetRunStep(); +// //Pub.sm.setNewStep(StateMachine.eSMStep.RUN); + +// //qa, pack 은 하차 전용이다 +// PUB.sm.ClearRunStep(); +// PUB.sm.SetNewRunStep(StateMachine.ERunStep.GOUP); +// PUB.sm.SetNewStep(StateMachine.eSMStep.RUN); +// } +// else if (PUB.sm.RunStep == StateMachine.ERunStep.GODOWN && VAR.BOOL[eVarBool.WAIT_COVER_DOWN] == false && VAR.BOOL[eVarBool.WAIT_COVER_UP] == false) +// { +// //하차중에 받을 수 있게하자 (단 FVi1 이하일때에는 무시하자) 230710 - 김수곤 +// if (PUB.Result.TargetPos == ePosition.QC && PUB.Result.CurrentPos < ePosition.F1) +// { +// PUB.log.Add($"하차중이지만 FVI #1 아래에 있으니 콜을 취소 합니다"); +// SendToKit(kitNo, '0', '0'); +// RaiseMessage(MessageType.Normal, $"QC 추가 콜이지만 위치가 #1번 이하이므로 취소 됩니다. Kit={kitNo},현재={PUB.Result.CurrentPos},대상={PUB.Result.TargetPos}"); +// } +// else +// { +// RaiseMessage(MessageType.Normal, string.Format("CALL확정(추가) Kit={0},대상위치={1}", kitNo, kitPos)); + +// PUB.AGV.data.CallNo = int.Parse(kitNo.ToString()); +// PUB.AGV.data.CallString = kitNo.ToString(); + +// PUB.Result.CommandKit = kitNo; +// PUB.Result.TargetPos = kitPos; + +// SendToKit(kitNo, '1', (PUB.IsCanCALL() ? '1' : '0')); //콜확정을 클라이언트에 알림 + +// PUB.Speak(kitPos.ToString() + Lang.위치로이동합니다); + +// //상태머신을 변경한다 (충전 OFF상태로 간다, 충전상태가 아니면 바로 이동하게됨) +// //Pub.sm.ResetRunStep(); +// //Pub.sm.setNewStep(StateMachine.eSMStep.RUN); + +// //qa, pack 은 하차 전용이다 +// PUB.sm.ClearRunStep(); +// PUB.sm.SetNewRunStep(StateMachine.ERunStep.GOUP); +// PUB.sm.SetNewStep(StateMachine.eSMStep.RUN); +// } + +// } +// //else if (PUB.sm.RunStep == StateMachine.ERunStep.GODOWN && PUB.Result.CurrentPos == ePosition.QA) +// //{ +// // RaiseMessage(MessageType.Normal, string.Format("CALL확정 Kit={0},대상위치={1}", kitNo, kitPos)); + +// // PUB.Result.CommandKit = kitNo; +// // PUB.Result.TargetPos = kitPos; +// // SendToKit(kitNo, '1'); //콜확정을 클라이언트에 알림 + +// // PUB.Speak(kitPos.ToString() + "위치로 이동 합니다"); + +// // //상태머신을 변경한다 (충전 OFF상태로 간다, 충전상태가 아니면 바로 이동하게됨) +// // // Pub.sm.ResetRunStep(); +// // // Pub.sm.setNewStep(StateMachine.eSMStep.RUN); + +// // //qa => pack 은 하차 전용이다 +// // //QA에서 PACK이동시에는 바로 N극 멈춤 기능을 사용해도도된다.(자재가 있으며, 커버가 내려가 있으므로 느리게 동작해야함) +// // PUB.sm.ClearRunStep(); +// // PUB.sm.SetNewRunStep(StateMachine.ERunStep.GODOWN); +// // PUB.sm.SetNewStep(StateMachine.ESMStep.RUN); + +// // PUB.AGV.AGVMoveStop("xbee_newmsgevent", arDev.Narumi.eStopOpt.MarkStop);// (arDev.Narumi.eAgvCmd.MoveStop,.SetNextStop_Mark(true, "xbee godn,qa,pack"); +// // PUB.PLC.ZMot(arDev.FakePLC.ZMotDirection.Up); +// //} +// else if (PUB.Result.TargetPos == kitPos) ////현재 지정된 클라이언트가 또 눌렀다 +// { +// PUB.Result.TargetPos = kitPos; +// PUB.AGV.data.CallNo = int.Parse(kitNo.ToString()); +// PUB.AGV.data.CallString = kitNo.ToString(); + +// //상차 대기 중이라면 커버를 자동 올려준다 +// //이것은 QC만 가능하다 +// //QC가 QA혹은 PACK으로 보낼때 사용함 +// if (kitPos == ePosition.QC && +// VAR.BOOL[eVarBool.FLAG_LIMITLOW] == true) +// { +// RaiseMessage(MessageType.Normal, "QC위치에서 자동으로 커버를 올립니다"); +// //PUB.PLC.ZMot(arDev.FakePLC.ZMotDirection.Up); +// PUB.AGV.LiftControl(arDev.Narumi.LiftCommand.UP); +// } +// else +// { +// //커버대기상태라면 커버를 자동으로 처리해준다. +// if (PUB.sm.Step == StateMachine.eSMStep.RUN && (PUB.sm.RunStep == StateMachine.ERunStep.GOUP || PUB.sm.RunStep == StateMachine.ERunStep.GODOWN)) +// { + +// if (VAR.BOOL[eVarBool.WAIT_COVER_DOWN] == true) +// { +// //var ld = PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_LD); +// //var rd = PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_RD); +// //if (ld == false || rd == false) +// //{ +// // PUB.log.Add("사용자 콜버튼 추가 동작 - Z내림"); +// // PUB.PLC.ZMot(arDev.FakePLC.ZMotDirection.Down); +// // PUB.Speak(Lang.커버를내립니다); +// //} +// } +// else if (VAR.BOOL[eVarBool.WAIT_COVER_UP] == true) +// { +// //var lu = PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_LU); +// //var ru = PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_RU); + +// //if (lu == false || ru == false) +// //{ +// // PUB.PLC.ZMot(arDev.FakePLC.ZMotDirection.Up); +// // PUB.log.Add("사용자 콜버튼 추가 동작 - Z올림"); +// // PUB.Speak(Lang.커버를올립니다); +// //} +// } +// else RaiseMessage(MessageType.Normal, string.Format("이미 CALL이 확정되었습니다 No={0},Pos={1}", kitNo, kitPos)); +// } +// else RaiseMessage(MessageType.Normal, string.Format("이미 CALL이 확정되었습니다 No={0},Pos={1}", kitNo, kitPos)); +// } +// SendToKit(kitNo, '1', (PUB.IsCanCALL() ? '1' : '0')); //콜확정을 클라이언트에 알림 +// } +// else +// { +// //다른대상이 이미 선택된 상태이므로 CANCEL 한다. +// SendToKit(kitNo, '0', (PUB.IsCanCALL() ? '1' : '0')); +// RaiseMessage(MessageType.Normal, string.Format("다른 CALL이 확정된 상태입니다. 요청KIT={2},확정KIT={0},위치={1}", PUB.Result.TargetPos - 2, PUB.Result.TargetPos, kitNo)); +// } +// } +// else if (kitVal == '0') //캔슬버튼을 눌렀다 +// { +// //목표번호가 캔슬버튼을 눌렀다 +// if (PUB.Result.TargetPos == kitPos) +// { +// //상차가 완료되면 TargetPos 가 변경되어 ,더이상 해당 버튼으로는 취소하지 못한다 +// PUB.AGV.data.CallNo = 0; +// PUB.AGV.data.CallString = "--"; + +// SendToKit(kitNo, '0', (PUB.IsCanCALL() ? '1' : '0')); +// RaiseMessage(MessageType.Normal, string.Format("콜 취소 Kit={0}", kitNo)); +// if (PUB.sm.RunStep != StateMachine.ERunStep.GOHOME) +// { +// PUB.Result.CommandKit = kitNo; +// PUB.Result.TargetPos = ePosition.QC; +// PUB.sm.ClearRunStep(); +// PUB.sm.SetNewRunStep(StateMachine.ERunStep.GOHOME); +// PUB.sm.SetNewStep(StateMachine.eSMStep.RUN); +// RaiseMessage(MessageType.Normal, string.Format("콜 취소로 인해 홈으로 이동합니다 Kit={0}", kitNo)); +// } + +// } +// else +// { +// //다른놈이 취소 버튼을 눌렀다. ㅋㅋ +// //아무~ 의미 없다. +// SendToKit(kitNo, '0', (PUB.IsCanCALL() ? '1' : '0')); +// RaiseMessage(MessageType.Normal, string.Format("해당 콜취소는 유효하지 않습니다 요청KIT={0},확정KIT={1}", kitNo, PUB.Result.TargetPos - 2)); +// } +// } +// else if (kitVal == '2') //BACKWORK시에만 이 값이 전송되게 한다 +// { +// //QA 이동 명령 +// //발동조건 1. QC 위치에서 GOUP(대기 혹은 상차완료)상태일때 (일반적인경우) +// //발동조건 2. QC 위치에서 IDLE 상태일때 (GOUP상태로 하지 않고 바로 싫어버린경우) +// //발동조건 3. 충전중일때 + +// //if (kitPos != ePosition.QC) +// //{ +// // RaiseMessage(MessageType.Error, $"back 버튼은 QC버튼만 사용 가능 합니다"); +// // return; +// //} + +// //if (kitPos == ePosition.QC && PUB.Result.CurrentPos != ePosition.QC) +// //{ +// // RaiseMessage(MessageType.Error, string.Format("QC의 QA버튼은 홈위치에 있어야 사용이 가능 합니다")); +// // return; +// //} + +// ////명령송신은 QC로 고정한다 +// //PUB.Result.CommandKit = '2'; +// //PUB.Result.TargetPos = ePosition.QA; +// //PUB.sm.ClearRunStep(); +// //PUB.sm.SetNewRunStep(StateMachine.ERunStep.GODOWN); +// //PUB.sm.SetNewStep(StateMachine.ESMStep.RUN); +// //RaiseMessage(MessageType.Normal, string.Format("후진하차 모드 대상위치={0}", ePosition.QA)); +// //PUB.logsys.AddI("QC의 QA리모콘 버튼 작업 입니다"); +// } +// } + + +// public void SendToKit(char kitNo, char Value, char enbcall) +// { +// List buffer = new List +// { +// 0x02, +// (byte)kitNo, +// (byte)Value, +// (byte)enbcall, +// 0x03 +// }; +// WriteData(buffer.ToArray()); +// //RaiseMessage(MessageType.Normal, $"지그비전송 {kitNo}:{Value}:{enbcall}"); +// } + +// public string GetStatusString() +// { +// return DateTime.Now.ToString(); +// } + +// public void SendStatus(String StatusString) +// { + +// ////IO + +// char kitno = '0'; +// char kitval = '1'; +// if (PUB.Result.TargetPos == ePosition.F1) kitno = '1'; +// else if (PUB.Result.TargetPos == ePosition.F2) kitno = '2'; +// else if (PUB.Result.TargetPos == ePosition.F3) kitno = '3'; +// else if (PUB.Result.TargetPos == ePosition.F4) kitno = '4'; +// else if (PUB.Result.TargetPos == ePosition.QC) kitno = '9'; +// else +// { +// //충전기 충전하는 것으로한다 +// if (VAR.BOOL[eVarBool.FLAG_CHARGEONA] == false && VAR.BOOL[eVarBool.FLAG_CHARGEONM] == false) +// kitval = '0'; +// } + +// //콜가능여부도 전송한다 +// var enbcall = PUB.IsCanCALL() ? '1' : '0'; +// SendToKit(kitno, kitval, enbcall); + + +// } +// } +//} diff --git a/Cs_HMI/Project/Device/Xbee.cs b/Cs_HMI/Project/Device/Xbee.cs index eaab4c6..4369354 100644 --- a/Cs_HMI/Project/Device/Xbee.cs +++ b/Cs_HMI/Project/Device/Xbee.cs @@ -6,395 +6,173 @@ using System.ComponentModel; using System.Threading; using COMM; using System.Runtime.Remoting.Messaging; +using ENIG; +using System.Security.Cryptography; +using AR; +using System.Web.Compilation; namespace Project.Device { - public class Xbee : arDev.arRS232 + public class Xbee : System.IO.Ports.SerialPort { - public Xbee() - { - - } - public string buffer = string.Empty; public System.Text.StringBuilder newbuffer = new StringBuilder(); - protected override bool CustomParser(byte[] buf, out byte[] remainBuffer) + public string errorMessage = string.Empty; + public DateTime LastStatusSendTime = DateTime.Now; + private EEProtocol proto; + + public Xbee() { - //일반 kit 명령은 0x02 kit번호, kit값 0x03 - //상태 명령은 0x04 메세지데이터 0x05 + this.DataReceived += Xbee_DataReceived; + proto = new EEProtocol(); + proto.OnDataReceived += Proto_OnDataReceived; + proto.OnMessage += Proto_OnMessage; + } + ~Xbee() + { + this.DataReceived -= Xbee_DataReceived; + proto.OnDataReceived -= Proto_OnDataReceived; + proto.OnMessage -= Proto_OnMessage; + } - Console.WriteLine("custom parse len=" + buf.Length.ToString()); - - List sparebuffer = new List(); - Boolean bComplete = false; - for (int i = 0; i < buf.Length; i++) + /// + /// AGV상태를 Xbee 로 전송한다 + /// + public void SendStatus() + { + /* + Mode[1] : 0=manual, 1=auto + RunSt[1] : 0=stop, 1=run, 2=error + Diection[1] : 0=straight, 1=left, 2=right, 3=markstop + Inposition[1] : 0=off, 1=on : 목적위치에 도달완료 시 설정 이동 이동시 OFF됨 + ChargeSt[1] : 0=off, 1=on + CartSt[1] : 0=off, 1=on, 2=unknown + LiftSt[1] : 0=down , 1=up, 2=unknown + LastTag[6] : "000000" + */ + try { - var incomByte = buf[i]; - if (bComplete == true) sparebuffer.Add(incomByte); + byte[] data = new byte[13]; // 총 13바이트 데이터 + + // Mode + data[0] = (byte)(VAR.BOOL[eVarBool.FLAG_AUTORUN] ? 1 : 0); + + // RunSt + if (PUB.AGV.error.Emergency) + data[1] = 2; // error + else if (PUB.AGV.system1.agv_run) + data[1] = 1; // run else - { - if (findSTX == false) - { - if (incomByte != 0x02) - { - //버리는데이터 - } - else - { - findSTX = true; - tempBuffer.Clear(); - tempBuffer.Add(incomByte); - } - } - else - { - tempBuffer.Add(incomByte); + data[1] = 0; // stop - if (incomByte == 0x03) - { - //데이터가 맞게 수신됨 - LastReceiveBuffer = tempBuffer.ToArray(); - bComplete = true; - findSTX = false; - } - else if (tempBuffer.Count > 30) - { - tempBuffer.Clear(); - findSTX = false; - } - } - } - } - remainBuffer = sparebuffer.ToArray(); - return bComplete; - } - - - public override bool ProcessRecvData(byte[] data) - { - var kitno = (char)(data[1]); - var kitval = (char)(data[2]); - NewMsgEvent(kitno, kitval); - return true; - } - - public void NewMsgEvent(char kitNo, char kitVal) - { - //대상위치 확인 - ePosition kitPos = ePosition.NONE; - if (kitNo == '9') kitPos = ePosition.QC; - else if (kitNo == '1') kitPos = ePosition.F1; - else if (kitNo == '2') kitPos = ePosition.F2; - else if (kitNo == '3') kitPos = ePosition.F3; - else if (kitNo == '4') kitPos = ePosition.F4; - else - { - if (kitNo == '0') return; - PUB.log.Add($"비허가 키트번호 무시 번호={kitNo},값={kitVal}"); - return; - } - - //if (kitNo= 'F') - //{ - // PUB.Speak("알 수 없는 키트번호 입니다"); - // PUB.logsys.Add($"키트번호별위치확인실패 값={kitNo}"); - // return; - //} - - //(ePosition)int.Parse(kitNo.ToString()); - PUB.logcal.Add(string.Format("Xbee:newMsgEvent:{0},{1}=>{2}", kitNo, kitVal, kitPos)); - if (PUB.CheckManualChargeMode() == false) - { - PUB.log.Add($"수동 충전 중이라 콜 기능을 취소 합니다"); - return; - } - - bool FixButton = kitPos == ePosition.NONE; - if (kitPos == ePosition.NONE) - { - if (kitVal == '1') kitPos = ePosition.QC; - else if (kitVal == '2') kitPos = ePosition.CHARGE; - else if (kitVal == '4') kitPos = ePosition.QC; - //else if (kitVal == '3') kitPos = ePosition.QA; + // Direction + if (PUB.AGV.system1.stop_by_front_detect) + data[2] = 3; // markstop + else if (VAR.BOOL[eVarBool.FLAG_LEFT_RUN]) + data[2] = 1; // left + else if (VAR.BOOL[eVarBool.FLAG_RIGHT_RUN]) + data[2] = 2; // right else - { - PUB.log.Add($"AGV버튼 이벤트 실행 값:{kitVal} 취소"); - return; - } - kitVal = '1'; //버튼은 무조건 ON상태로 한다 - } + data[2] = 0; // straight - //자동상태가 아니라면 오류처리 - if (VAR.BOOL[eVarBool.FLAG_AUTORUN] == false || PUB.sm.Step != StateMachine.eSMStep.RUN) - { - PUB.log.AddE("'자동실행' 상태가 아니므로 콜/취소 작업을 할 수 없습니다 콜:" + kitPos.ToString() + ",값=" + kitVal.ToString()); - PUB.Speak(Lang.자동운전상태가아닙니다); - return; - } + // Inposition + data[3] = (byte)(PUB.AGV.system1.agv_stop ? 1 : 0); - //충전기를 제외하고 '1'의 값은 호출을 원하는값이다.('0'=취소) - if (kitVal == '1') - { - //qA혹은 Pack 에서 해당 버튼을 눌렀을때의 처리방법 - //if (PUB.Result.CurrentPos == ePosition.QA && kitPos == ePosition.QA) - //{ - // PUB.logsys.AddE("QA위치에서 QA버튼을 눌렀음 명령 취소함"); - // PUB.Speak("현재 위치는 QA 입니다."); - // return; - //} + // ChargeSt + data[4] = (byte)((VAR.BOOL[eVarBool.FLAG_CHARGEONA] || VAR.BOOL[eVarBool.FLAG_CHARGEONM]) ? 1 : 0); - //상/하차 작업중이 아니라면 콜을 받는다 - if (PUB.sm.RunStep != StateMachine.ERunStep.GOUP && PUB.sm.RunStep != StateMachine.ERunStep.GODOWN) - { - //call을 받으려면 대상위 (2=QC,3,4,5,6,7) - //콜을 요청하는 곳 (2=QC,3=FVI-1,4,5,6,7==FVI-5) - //1번은 충전기 - - //콜버튼으로 대상위치를 다시 결정한다. - //대상번호는 콜번호에서 +2을 하면 된다. - //대상번호 PK=1,QA2=2,QA1=3,QC=4 - //QC의경우 콜Kit번호는 2이므로, 이동대상은 +2인 4가 되어야 함 - //콜번호와 RFID대상번호는 2의 오차가 발생함, 현재 설치된 RFID를 모두 변경할 수 없어서 이렇게 운용함 - - - RaiseMessage(MessageType.Normal, string.Format("CALL확정 Kit={0},대상위치={1}", kitNo, kitPos)); - - PUB.AGV.data.CallNo = int.Parse(kitNo.ToString()); - PUB.AGV.data.CallString = kitNo.ToString(); - - PUB.Result.CommandKit = kitNo; - PUB.Result.TargetPos = kitPos; - SendToKit(kitNo, '1', (PUB.IsCanCALL() ? '1' : '0')); //콜확정을 클라이언트에 알림 - - PUB.Speak(kitPos.ToString() + Lang.위치로이동합니다); - - //상태머신을 변경한다 (충전 OFF상태로 간다, 충전상태가 아니면 바로 이동하게됨) - //Pub.sm.ResetRunStep(); - //Pub.sm.setNewStep(StateMachine.eSMStep.RUN); - - //qa, pack 은 하차 전용이다 - PUB.sm.ClearRunStep(); - PUB.sm.SetNewRunStep(StateMachine.ERunStep.GOUP); - PUB.sm.SetNewStep(StateMachine.eSMStep.RUN); - } - else if (PUB.sm.RunStep == StateMachine.ERunStep.GODOWN && VAR.BOOL[eVarBool.WAIT_COVER_DOWN] == false && VAR.BOOL[eVarBool.WAIT_COVER_UP] == false) - { - //하차중에 받을 수 있게하자 (단 FVi1 이하일때에는 무시하자) 230710 - 김수곤 - if (PUB.Result.TargetPos == ePosition.QC && PUB.Result.CurrentPos < ePosition.F1) - { - PUB.log.Add($"하차중이지만 FVI #1 아래에 있으니 콜을 취소 합니다"); - SendToKit(kitNo, '0', '0'); - RaiseMessage(MessageType.Normal, $"QC 추가 콜이지만 위치가 #1번 이하이므로 취소 됩니다. Kit={kitNo},현재={PUB.Result.CurrentPos},대상={PUB.Result.TargetPos}"); - } - else - { - RaiseMessage(MessageType.Normal, string.Format("CALL확정(추가) Kit={0},대상위치={1}", kitNo, kitPos)); - - PUB.AGV.data.CallNo = int.Parse(kitNo.ToString()); - PUB.AGV.data.CallString = kitNo.ToString(); - - PUB.Result.CommandKit = kitNo; - PUB.Result.TargetPos = kitPos; - - SendToKit(kitNo, '1', (PUB.IsCanCALL() ? '1' : '0')); //콜확정을 클라이언트에 알림 - - PUB.Speak(kitPos.ToString() + Lang.위치로이동합니다); - - //상태머신을 변경한다 (충전 OFF상태로 간다, 충전상태가 아니면 바로 이동하게됨) - //Pub.sm.ResetRunStep(); - //Pub.sm.setNewStep(StateMachine.eSMStep.RUN); - - //qa, pack 은 하차 전용이다 - PUB.sm.ClearRunStep(); - PUB.sm.SetNewRunStep(StateMachine.ERunStep.GOUP); - PUB.sm.SetNewStep(StateMachine.eSMStep.RUN); - } - - } - //else if (PUB.sm.RunStep == StateMachine.ERunStep.GODOWN && PUB.Result.CurrentPos == ePosition.QA) - //{ - // RaiseMessage(MessageType.Normal, string.Format("CALL확정 Kit={0},대상위치={1}", kitNo, kitPos)); - - // PUB.Result.CommandKit = kitNo; - // PUB.Result.TargetPos = kitPos; - // SendToKit(kitNo, '1'); //콜확정을 클라이언트에 알림 - - // PUB.Speak(kitPos.ToString() + "위치로 이동 합니다"); - - // //상태머신을 변경한다 (충전 OFF상태로 간다, 충전상태가 아니면 바로 이동하게됨) - // // Pub.sm.ResetRunStep(); - // // Pub.sm.setNewStep(StateMachine.eSMStep.RUN); - - // //qa => pack 은 하차 전용이다 - // //QA에서 PACK이동시에는 바로 N극 멈춤 기능을 사용해도도된다.(자재가 있으며, 커버가 내려가 있으므로 느리게 동작해야함) - // PUB.sm.ClearRunStep(); - // PUB.sm.SetNewRunStep(StateMachine.ERunStep.GODOWN); - // PUB.sm.SetNewStep(StateMachine.ESMStep.RUN); - - // PUB.AGV.AGVMoveStop("xbee_newmsgevent", arDev.Narumi.eStopOpt.MarkStop);// (arDev.Narumi.eAgvCmd.MoveStop,.SetNextStop_Mark(true, "xbee godn,qa,pack"); - // PUB.PLC.ZMot(arDev.FakePLC.ZMotDirection.Up); - //} - else if (PUB.Result.TargetPos == kitPos) ////현재 지정된 클라이언트가 또 눌렀다 - { - PUB.Result.TargetPos = kitPos; - PUB.AGV.data.CallNo = int.Parse(kitNo.ToString()); - PUB.AGV.data.CallString = kitNo.ToString(); - - //상차 대기 중이라면 커버를 자동 올려준다 - //이것은 QC만 가능하다 - //QC가 QA혹은 PACK으로 보낼때 사용함 - if (kitPos == ePosition.QC && - VAR.BOOL[eVarBool.FLAG_LIMITLOW] == true) - { - RaiseMessage(MessageType.Normal, "QC위치에서 자동으로 커버를 올립니다"); - PUB.PLC.ZMot(arDev.FakePLC.ZMotDirection.Up); - } - else - { - //커버대기상태라면 커버를 자동으로 처리해준다. - if (PUB.sm.Step == StateMachine.eSMStep.RUN && (PUB.sm.RunStep == StateMachine.ERunStep.GOUP || PUB.sm.RunStep == StateMachine.ERunStep.GODOWN)) - { - - if (VAR.BOOL[eVarBool.WAIT_COVER_DOWN] == true) - { - var ld = PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_LD); - var rd = PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_RD); - if (ld == false || rd == false) - { - PUB.log.Add("사용자 콜버튼 추가 동작 - Z내림"); - PUB.PLC.ZMot(arDev.FakePLC.ZMotDirection.Down); - PUB.Speak(Lang.커버를내립니다); - } - } - else if (VAR.BOOL[eVarBool.WAIT_COVER_UP] == true) - { - var lu = PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_LU); - var ru = PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_RU); - - if (lu == false || ru == false) - { - PUB.PLC.ZMot(arDev.FakePLC.ZMotDirection.Up); - PUB.log.Add("사용자 콜버튼 추가 동작 - Z올림"); - PUB.Speak(Lang.커버를올립니다); - } - } - else RaiseMessage(MessageType.Normal, string.Format("이미 CALL이 확정되었습니다 No={0},Pos={1}", kitNo, kitPos)); - } - else RaiseMessage(MessageType.Normal, string.Format("이미 CALL이 확정되었습니다 No={0},Pos={1}", kitNo, kitPos)); - } - SendToKit(kitNo, '1', (PUB.IsCanCALL() ? '1' : '0')); //콜확정을 클라이언트에 알림 - } + // CartSt + if(PUB.AGV.signal.cart_detect1 && PUB.AGV.signal.cart_detect2) + data[5] = 1; // 센서두개가 모두 감지되는 경우 + else if(PUB.AGV.signal.cart_detect1==false && PUB.AGV.signal.cart_detect2==false) + data[5] = 0; // 센서두개가 모두 감지되지 않는 경우 else - { - //다른대상이 이미 선택된 상태이므로 CANCEL 한다. - SendToKit(kitNo, '0', (PUB.IsCanCALL() ? '1' : '0')); - RaiseMessage(MessageType.Normal, string.Format("다른 CALL이 확정된 상태입니다. 요청KIT={2},확정KIT={0},위치={1}", PUB.Result.TargetPos - 2, PUB.Result.TargetPos, kitNo)); - } - } - else if (kitVal == '0') //캔슬버튼을 눌렀다 - { - //목표번호가 캔슬버튼을 눌렀다 - if (PUB.Result.TargetPos == kitPos) - { - //상차가 완료되면 TargetPos 가 변경되어 ,더이상 해당 버튼으로는 취소하지 못한다 - PUB.AGV.data.CallNo = 0; - PUB.AGV.data.CallString = "--"; + data[5] = 2; // 센서하나만 감지되는 경우 - SendToKit(kitNo, '0', (PUB.IsCanCALL() ? '1' : '0')); - RaiseMessage(MessageType.Normal, string.Format("콜 취소 Kit={0}", kitNo)); - if (PUB.sm.RunStep != StateMachine.ERunStep.GOHOME) - { - PUB.Result.CommandKit = kitNo; - PUB.Result.TargetPos = ePosition.QC; - PUB.sm.ClearRunStep(); - PUB.sm.SetNewRunStep(StateMachine.ERunStep.GOHOME); - PUB.sm.SetNewStep(StateMachine.eSMStep.RUN); - RaiseMessage(MessageType.Normal, string.Format("콜 취소로 인해 홈으로 이동합니다 Kit={0}", kitNo)); - } - - } + // LiftSt + if(PUB.AGV.signal.lift_up) + data[6] = 1; // 위로 올라가는 경우 + else if(PUB.AGV.signal.lift_down) + data[6] = 0; // 아래로 내려가는 경우 else - { - //다른놈이 취소 버튼을 눌렀다. ㅋㅋ - //아무~ 의미 없다. - SendToKit(kitNo, '0', (PUB.IsCanCALL() ? '1' : '0')); - RaiseMessage(MessageType.Normal, string.Format("해당 콜취소는 유효하지 않습니다 요청KIT={0},확정KIT={1}", kitNo, PUB.Result.TargetPos - 2)); - } + data[6] = 2; // unknown (기본값) + + // LastTag + string lastTag = PUB.AGV.data.TagNo.ToString("000000") ?? "000000"; + byte[] tagBytes = Encoding.ASCII.GetBytes(lastTag.PadRight(6, '0')); + Array.Copy(tagBytes, 0, data, 7, 6); + + // 데이터 전송 + var packet = proto.CreatePacket(PUB.setting.XBE_ID, 9, data); + Send(packet); + LastStatusSendTime = DateTime.Now; } - else if (kitVal == '2') //BACKWORK시에만 이 값이 전송되게 한다 + catch (Exception ex) { - //QA 이동 명령 - //발동조건 1. QC 위치에서 GOUP(대기 혹은 상차완료)상태일때 (일반적인경우) - //발동조건 2. QC 위치에서 IDLE 상태일때 (GOUP상태로 하지 않고 바로 싫어버린경우) - //발동조건 3. 충전중일때 - - //if (kitPos != ePosition.QC) - //{ - // RaiseMessage(MessageType.Error, $"back 버튼은 QC버튼만 사용 가능 합니다"); - // return; - //} - - //if (kitPos == ePosition.QC && PUB.Result.CurrentPos != ePosition.QC) - //{ - // RaiseMessage(MessageType.Error, string.Format("QC의 QA버튼은 홈위치에 있어야 사용이 가능 합니다")); - // return; - //} - - ////명령송신은 QC로 고정한다 - //PUB.Result.CommandKit = '2'; - //PUB.Result.TargetPos = ePosition.QA; - //PUB.sm.ClearRunStep(); - //PUB.sm.SetNewRunStep(StateMachine.ERunStep.GODOWN); - //PUB.sm.SetNewStep(StateMachine.ESMStep.RUN); - //RaiseMessage(MessageType.Normal, string.Format("후진하차 모드 대상위치={0}", ePosition.QA)); - //PUB.logsys.AddI("QC의 QA리모콘 버튼 작업 입니다"); + errorMessage = ex.Message; + PUB.logxbee.AddE(errorMessage); } } - - public void SendToKit(char kitNo, char Value, char enbcall) + /// + /// 지그비장치에 데이터를 전송합니다 + /// + /// + /// + public bool Send(byte[] data) { - List buffer = new List + try { - 0x02, - (byte)kitNo, - (byte)Value, - (byte)enbcall, - 0x03 - }; - WriteData(buffer.ToArray()); - //RaiseMessage(MessageType.Normal, $"지그비전송 {kitNo}:{Value}:{enbcall}"); - } - - public string GetStatusString() - { - return DateTime.Now.ToString(); - } - - public void SendStatus(String StatusString) - { - - ////IO - - char kitno = '0'; - char kitval = '1'; - if (PUB.Result.TargetPos == ePosition.F1) kitno = '1'; - else if (PUB.Result.TargetPos == ePosition.F2) kitno = '2'; - else if (PUB.Result.TargetPos == ePosition.F3) kitno = '3'; - else if (PUB.Result.TargetPos == ePosition.F4) kitno = '4'; - else if (PUB.Result.TargetPos == ePosition.QC) kitno = '9'; - else + this.Write(data, 0, data.Length); + return true; + }catch (Exception ex) { - //충전기 충전하는 것으로한다 - if (VAR.BOOL[eVarBool.FLAG_CHARGEONA] == false && VAR.BOOL[eVarBool.FLAG_CHARGEONM] == false) - kitval = '0'; + errorMessage = ex.Message; + return false; } + } - //콜가능여부도 전송한다 - var enbcall = PUB.IsCanCALL() ? '1' : '0'; - SendToKit(kitno, kitval, enbcall); + public new bool Open() + { + try{ + this.Open(); + return true; + }catch (Exception ex) + { + errorMessage = ex.Message; + PUB.logxbee.AddE(errorMessage); + return false; + } + } + private void Proto_OnDataReceived(object sender, EEProtocol.DataEventArgs e) + { + var hexstrRaw = e.ReceivedPacket.RawData.HexString(); + var hexstr = e.ReceivedPacket.Data.HexString(); + var cmd = e.ReceivedPacket.Command.ToString("X2"); + var id = e.ReceivedPacket.ID.ToString("X2"); + PUB.logxbee.Add("RX", $"{hexstrRaw}\nID:{id},CMD:{cmd},DATA:{hexstr}"); + + //TODO : 기능 처리필요 (XBee 메세지 데이터처리) + //PUB.CheckManualChargeMode() : 수동충전확인 + //VAR.BOOL[eVarBool.FLAG_AUTORUN] : 자동실행 + //PUB.Speak("현재 위치는 QA 입니다.") : 음성출력 } + private void Proto_OnMessage(object sender, EEProtocol.MessageEventArgs e) + { + if (e.IsError) PUB.log.AddE(e.Message); + else PUB.log.Add(e.Message); + } + + + private void Xbee_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) + { + var dev = sender as System.IO.Ports.SerialPort; + var buffer = new byte[dev.BytesToRead]; + dev.Read(buffer, 0, buffer.Length); + proto.ProcessReceivedData(buffer); + } + } } diff --git a/Cs_HMI/Project/Dialog/fLog.cs b/Cs_HMI/Project/Dialog/fLog.cs index be655ad..eda41b2 100644 --- a/Cs_HMI/Project/Dialog/fLog.cs +++ b/Cs_HMI/Project/Dialog/fLog.cs @@ -24,7 +24,7 @@ namespace Project.Dialog PUB.logagv.RaiseMsg -= Log_RaiseMsgagv; PUB.logplc.RaiseMsg -= Log_RaiseMsgplc; PUB.logbms.RaiseMsg -= Log_RaiseMsgbms; - PUB.logcal.RaiseMsg -= Log_RaiseMsgcal; + PUB.logxbee.RaiseMsg -= Log_RaiseMsgcal; } private void fLog_Load(object sender, EventArgs e) @@ -49,7 +49,7 @@ namespace Project.Dialog PUB.logagv.RaiseMsg += Log_RaiseMsgagv; PUB.logplc.RaiseMsg += Log_RaiseMsgplc; PUB.logbms.RaiseMsg += Log_RaiseMsgbms; - PUB.logcal.RaiseMsg += Log_RaiseMsgcal; + PUB.logxbee.RaiseMsg += Log_RaiseMsgcal; } private void Log_RaiseMsg(DateTime LogTime, string TypeStr, string Message) diff --git a/Cs_HMI/Project/PUB.cs b/Cs_HMI/Project/PUB.cs index eec8d39..aa87b4b 100644 --- a/Cs_HMI/Project/PUB.cs +++ b/Cs_HMI/Project/PUB.cs @@ -12,6 +12,7 @@ using System.Net; using System.Management; using System.Data.SqlClient; using System.Data; +using AR; namespace Project { @@ -28,7 +29,7 @@ namespace Project /// /// 읽기/쓰기용이며 구동모터 와 비상정지가 연결됨(USB-ATMEGA 2560) /// - public static arDev.FakePLC PLC; + //public static arDev.FakePLC PLC; ///// ///// 읽기전용이며 Z축 모터와 외부 버튼이 연결됨(USB-ATMEGA 2560) @@ -122,7 +123,7 @@ namespace Project /// /// 시스템로그 /// - public static arUtil.Log log, logagv, logplc, logbms, logcal; + public static arUtil.Log log, logagv, logplc, logbms, logxbee; public static Boolean bPlayMusic = false; @@ -158,12 +159,12 @@ namespace Project logagv = new arUtil.Log(); logplc = new arUtil.Log(); logbms = new arUtil.Log(); - logcal = new arUtil.Log(); + logxbee = new arUtil.Log(); logagv.FileNameFormat = "{yyyyMMdd}_agv"; logplc.FileNameFormat = "{yyyyMMdd}_plc"; logbms.FileNameFormat = "{yyyyMMdd}_bms"; - logcal.FileNameFormat = "{yyyyMMdd}_cal"; + logxbee.FileNameFormat = "{yyyyMMdd}_cal"; //popupmessage popup = new MessageWindow(); @@ -255,7 +256,7 @@ namespace Project /// public static Boolean HasHWError() { - if (PUB.PLC.IsValid == false) return true; + //if (PUB.PLC.IsValid == false) return true; if (PUB.AGV.IsOpen == false) return true; if (PUB.XBE.IsOpen == false) return true; return false; diff --git a/Cs_HMI/Project/StateMachine/AGVPosition.cs b/Cs_HMI/Project/StateMachine/AGVPosition.cs new file mode 100644 index 0000000..df66c25 --- /dev/null +++ b/Cs_HMI/Project/StateMachine/AGVPosition.cs @@ -0,0 +1,145 @@ +using System; +using System.Collections.Generic; + +namespace Project.StateMachine +{ + public class AGVPosition + { + public enum PositionType + { + None, + Tops1, + Sstron1, + Sstron2, + Path + } + + public class Position + { + public int RFID { get; set; } + public PositionType Type { get; set; } + public string Name { get; set; } + public string Direction { get; set; } + public List ConnectedPositions { get; set; } + + public Position(int rfid, PositionType type, string name, string direction) + { + RFID = rfid; + Type = type; + Name = name; + Direction = direction; + ConnectedPositions = new List(); + } + } + + private Dictionary positionMap; + private static AGVPosition instance; + + private AGVPosition() + { + positionMap = new Dictionary(); + InitializePositions(); + } + + public static AGVPosition Instance + { + get + { + if (instance == null) + { + instance = new AGVPosition(); + } + return instance; + } + } + + private void InitializePositions() + { + // Tops 1 관련 위치 + AddPosition(100, PositionType.Tops1, "Tops 1", "0"); + AddPosition(101, PositionType.Path, "Tops1-Sstron1 Path 1", "0"); + AddPosition(102, PositionType.Path, "Tops1-Sstron1 Path 2", "0"); + + // Sstron 1 관련 위치 + AddPosition(200, PositionType.Sstron1, "Sstron 1", "0"); + AddPosition(201, PositionType.Path, "Sstron1-Sstron2 Path 1", "0"); + AddPosition(202, PositionType.Path, "Sstron1-Sstron2 Path 2", "0"); + + // Sstron 2 관련 위치 + AddPosition(300, PositionType.Sstron2, "Sstron 2", "0"); + + // 경로 연결 설정 + ConnectPositions(100, 101); + ConnectPositions(101, 102); + ConnectPositions(102, 200); + ConnectPositions(200, 201); + ConnectPositions(201, 202); + ConnectPositions(202, 300); + } + + private void AddPosition(int rfid, PositionType type, string name, string direction) + { + positionMap[rfid] = new Position(rfid, type, name, direction); + } + + private void ConnectPositions(int pos1, int pos2) + { + if (positionMap.ContainsKey(pos1) && positionMap.ContainsKey(pos2)) + { + positionMap[pos1].ConnectedPositions.Add(pos2); + positionMap[pos2].ConnectedPositions.Add(pos1); + } + } + + public Position GetPosition(int rfid) + { + if (positionMap.ContainsKey(rfid)) + { + return positionMap[rfid]; + } + return null; + } + + public List FindPath(int startRfid, int endRfid) + { + if (!positionMap.ContainsKey(startRfid) || !positionMap.ContainsKey(endRfid)) + { + return null; + } + + var visited = new HashSet(); + var path = new List(); + if (FindPathDFS(startRfid, endRfid, visited, path)) + { + return path; + } + return null; + } + + private bool FindPathDFS(int current, int end, HashSet visited, List path) + { + if (current == end) + { + path.Add(current); + return true; + } + + visited.Add(current); + path.Add(current); + + foreach (var next in positionMap[current].ConnectedPositions) + { + if (!visited.Contains(next)) + { + if (FindPathDFS(next, end, visited, path)) + { + return true; + } + } + } + + path.RemoveAt(path.Count - 1); + return false; + } + } +} \ No newline at end of file diff --git a/Cs_HMI/Project/StateMachine/AGVProtocolHandler.cs b/Cs_HMI/Project/StateMachine/AGVProtocolHandler.cs new file mode 100644 index 0000000..bf1d650 --- /dev/null +++ b/Cs_HMI/Project/StateMachine/AGVProtocolHandler.cs @@ -0,0 +1,107 @@ +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; + +namespace Project.StateMachine +{ + public class AGVProtocolHandler + { + private static AGVProtocolHandler instance; + private AGVStateManager stateManager; + + private AGVProtocolHandler() + { + stateManager = AGVStateManager.Instance; + } + + public static AGVProtocolHandler Instance + { + get + { + if (instance == null) + { + instance = new AGVProtocolHandler(); + } + return instance; + } + } + + public bool ProcessProtocol(string protocol) + { + try + { + // 프로토콜 형식: COMMAND:DESTINATION + var parts = protocol.Split(':'); + if (parts.Length != 2) + { + return false; + } + + var command = parts[0].ToUpper(); + var destination = parts[1].ToUpper(); + + switch (command) + { + case "MOVE_TO": + return HandleMoveToCommand(destination); + case "PICKUP": + return HandlePickupCommand(destination); + case "DROPOFF": + return HandleDropoffCommand(destination); + case "EMERGENCY_STOP": + return HandleEmergencyStopCommand(); + default: + return false; + } + } + catch (Exception) + { + return false; + } + } + + private bool HandleMoveToCommand(string destination) + { + switch (destination) + { + case "T1": + return stateManager.ProcessCommand(AGVStateManager.AGVCommand.MoveToTops1); + case "S1": + return stateManager.ProcessCommand(AGVStateManager.AGVCommand.MoveToSstron1); + case "S2": + return stateManager.ProcessCommand(AGVStateManager.AGVCommand.MoveToSstron2); + default: + return false; + } + } + + private bool HandlePickupCommand(string destination) + { + if (destination != "T1") + { + return false; + } + return stateManager.ProcessCommand(AGVStateManager.AGVCommand.PickupCart); + } + + private bool HandleDropoffCommand(string destination) + { + if (destination != "S1" && destination != "S2") + { + return false; + } + return stateManager.ProcessCommand(AGVStateManager.AGVCommand.DropoffCart); + } + + private bool HandleEmergencyStopCommand() + { + return stateManager.ProcessCommand(AGVStateManager.AGVCommand.EmergencyStop); + } + + public string GetCurrentStatus() + { + var state = stateManager.CurrentState; + return $"Current State: {state}"; + } + } +} \ No newline at end of file diff --git a/Cs_HMI/Project/StateMachine/AGVStateManager.cs b/Cs_HMI/Project/StateMachine/AGVStateManager.cs new file mode 100644 index 0000000..bf57c23 --- /dev/null +++ b/Cs_HMI/Project/StateMachine/AGVStateManager.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; + +namespace Project.StateMachine +{ + public class AGVStateManager + { + public enum AGVState + { + Idle, + Moving, + Loading, + Unloading, + Error + } + + public enum AGVCommand + { + MoveToTops1, + MoveToSstron1, + MoveToSstron2, + PickupCart, + DropoffCart, + EmergencyStop + } + + private AGVState currentState; + private static AGVStateManager instance; + private AGVPosition positionManager; + + private AGVStateManager() + { + currentState = AGVState.Idle; + positionManager = AGVPosition.Instance; + } + + public static AGVStateManager Instance + { + get + { + if (instance == null) + { + instance = new AGVStateManager(); + } + return instance; + } + } + + public AGVState CurrentState + { + get { return currentState; } + } + + public bool ProcessCommand(AGVCommand command) + { + switch (command) + { + case AGVCommand.MoveToTops1: + return HandleMoveCommand(100); // Tops 1 RFID + case AGVCommand.MoveToSstron1: + return HandleMoveCommand(200); // Sstron 1 RFID + case AGVCommand.MoveToSstron2: + return HandleMoveCommand(300); // Sstron 2 RFID + case AGVCommand.PickupCart: + return HandlePickupCommand(); + case AGVCommand.DropoffCart: + return HandleDropoffCommand(); + case AGVCommand.EmergencyStop: + return HandleEmergencyStop(); + default: + return false; + } + } + + private bool HandleMoveCommand(int targetRfid) + { + if (currentState != AGVState.Idle && currentState != AGVState.Moving) + { + return false; + } + + // 현재 위치에서 목표 위치까지의 경로를 찾음 + var currentRfid = GetCurrentRfid(); // 실제 구현에서는 현재 RFID 값을 가져와야 함 + var path = positionManager.FindPath(currentRfid, targetRfid); + + if (path == null) + { + return false; + } + + currentState = AGVState.Moving; + // 경로를 따라 이동하는 로직 구현 + return true; + } + + private bool HandlePickupCommand() + { + if (currentState != AGVState.Moving) + { + return false; + } + + // 현재 위치가 Tops 1인지 확인 + var currentRfid = GetCurrentRfid(); + var position = positionManager.GetPosition(currentRfid); + + if (position == null || position.Type != AGVPosition.PositionType.Tops1) + { + return false; + } + + currentState = AGVState.Loading; + // 카트 적재 로직 구현 + return true; + } + + private bool HandleDropoffCommand() + { + if (currentState != AGVState.Moving) + { + return false; + } + + // 현재 위치가 Sstron 1 또는 Sstron 2인지 확인 + var currentRfid = GetCurrentRfid(); + var position = positionManager.GetPosition(currentRfid); + + if (position == null || + (position.Type != AGVPosition.PositionType.Sstron1 && + position.Type != AGVPosition.PositionType.Sstron2)) + { + return false; + } + + currentState = AGVState.Unloading; + // 카트 하역 로직 구현 + return true; + } + + private bool HandleEmergencyStop() + { + currentState = AGVState.Error; + // 비상 정지 로직 구현 + return true; + } + + private int GetCurrentRfid() + { + // 실제 구현에서는 AGV의 현재 RFID 값을 반환해야 함 + // 예시로 100(Tops 1)을 반환 + return 100; + } + + public void UpdateState(AGVState newState) + { + currentState = newState; + } + } +} \ No newline at end of file diff --git a/Cs_HMI/Project/StateMachine/Step/_SM_RUN.cs b/Cs_HMI/Project/StateMachine/Step/_SM_RUN.cs index c3f07e0..3450670 100644 --- a/Cs_HMI/Project/StateMachine/Step/_SM_RUN.cs +++ b/Cs_HMI/Project/StateMachine/Step/_SM_RUN.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using static Project.StateMachine; using COMM; +using AR; namespace Project { @@ -15,6 +16,7 @@ namespace Project DateTime LastCommandTime = DateTime.Now; DateTime LastCommandTimeNextStop = DateTime.Now; bool runStepisFirst = false; + private void _SM_RUN(Boolean isFirst, TimeSpan stepTime) { //중단기능이 동작이라면 처리하지 않는다. @@ -62,9 +64,9 @@ namespace Project if (isFirst) { if (PUB.sm.RunStep == ERunStep.READY) - VAR.TIME.Set(eVarTime.ReadyStart); + VAR.TIME.Update(eVarTime.ReadyStart); else - VAR.TIME.Set(eVarTime.RunStart); + VAR.TIME.Update(eVarTime.RunStart); } switch (PUB.sm.RunStep) @@ -95,7 +97,7 @@ namespace Project case ERunStep.CHARGECHECK: //충전중 if (runStepisFirst) { - VAR.TIME.Set(eVarTime.ChargeStart); + VAR.TIME.Update(eVarTime.ChargeStart); LastCommandTime = DateTime.Now; } else if (_SM_RUN_GOCHARGECHECK(runStepisFirst, PUB.sm.GetRunSteptime)) @@ -109,7 +111,7 @@ namespace Project case ERunStep.CHARGEOFF: if (runStepisFirst) { - VAR.TIME.Set(eVarTime.ChargeEnd); + VAR.TIME.Update(eVarTime.ChargeEnd); LastCommandTime = DateTime.Now; } else @@ -160,8 +162,8 @@ namespace Project if (_SM_RUN_GODOWN(runStepisFirst, PUB.sm.GetRunSteptime)) { PUB.Speak(Lang.하차작업이완료되었습니다); - VAR.TIME.Set(eVarTime.ChargeTry); - PUB.PLC.ZMot(arDev.FakePLC.ZMotDirection.Down);// (Device.PLC.ZMotDirection.Down); //하차작업이 완료되면 커버를 내려서 바로 작업할 수 있게 한다. + VAR.TIME.Update(eVarTime.ChargeTry); + PUB.AGV.LiftControl(arDev.Narumi.LiftCommand.DN);// (Device.PLC.ZMotDirection.Down); //하차작업이 완료되면 커버를 내려서 바로 작업할 수 있게 한다. //230601 //if (PUB.Result != null && PUB.sm != null) @@ -200,7 +202,7 @@ namespace Project // EEMStatus.AddEEDBSQL(PUB.sm.Step, PUB.sm.RunStep.ToString(), PUB.Result.TargetPos.ToString()); PUB.Speak(Lang.홈이동완료대기상태로전환합니다); - VAR.TIME.Set(eVarTime.ChargeTry); + VAR.TIME.Update(eVarTime.ChargeTry); PUB.sm.SetNewRunStep(ERunStep.READY); //대기상태로 전환한다 return; } @@ -213,6 +215,7 @@ namespace Project return true; } + void CheckAGVMoveTo(eGoDir dir) { //계속내려간다 @@ -233,15 +236,12 @@ namespace Project { PUB.log.Add($"마크정지를 해제하기 위해 장비를 멈춥니다"); } - //이동해야하는데 마크 스탑이 되어있다면 일단 멈춘다 - } else { //움직이지 않으므로 전진하도록 한다 PUB.log.Add($"AGV 기동 방향(DOWN):{dir}"); - PUB.AGV.AGVMoveRun(arDev.Narumi.eRunOpt.Forward);//PUB.PLC.Move(Device.PLC.Rundirection.Backward, "UpdateMotionPosition(" + sender + ")"); - + PUB.AGV.AGVMoveRun(arDev.Narumi.eRunOpt.Forward); } LastCommandTime = DateTime.Now; } @@ -266,8 +266,7 @@ namespace Project else { PUB.log.Add($"AGV 기동 방향(UP):{dir}"); - PUB.AGV.AGVMoveRun(arDev.Narumi.eRunOpt.Backward);//PUB.PLC.Move(Device.PLC.Rundirection.Backward, "UpdateMotionPosition(" + sender + ")"); - + PUB.AGV.AGVMoveRun(arDev.Narumi.eRunOpt.Backward); } LastCommandTime = DateTime.Now; } @@ -546,5 +545,7 @@ namespace Project return false; } + + }//cvass } diff --git a/Cs_HMI/Project/StateMachine/Step/_SM_RUN_CHGOFF.cs b/Cs_HMI/Project/StateMachine/Step/_SM_RUN_CHGOFF.cs index 7e7806b..e9634ae 100644 --- a/Cs_HMI/Project/StateMachine/Step/_SM_RUN_CHGOFF.cs +++ b/Cs_HMI/Project/StateMachine/Step/_SM_RUN_CHGOFF.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using static Project.StateMachine; using COMM; +using AR; namespace Project { @@ -18,7 +19,7 @@ namespace Project { if (isFirst) { - VAR.TIME.Set(eVarTime.ChargeEnd); + VAR.TIME.Update(eVarTime.ChargeEnd); if (VAR.BOOL[eVarBool.FLAG_CHARGEONA]) { PUB.Speak(Lang.충전을해제합니다); @@ -44,7 +45,7 @@ namespace Project { PUB.log.Add("충전 해제 전송"); PUB.AGV.AGVCharge(PUB.setting.ChargerID, false); - VAR.TIME.Set(eVarTime.SendChargeOff); + VAR.TIME.Update(eVarTime.SendChargeOff); } } diff --git a/Cs_HMI/Project/StateMachine/Step/_SM_RUN_GOCHARGE.cs b/Cs_HMI/Project/StateMachine/Step/_SM_RUN_GOCHARGE.cs index ad79f2a..d6d8ac2 100644 --- a/Cs_HMI/Project/StateMachine/Step/_SM_RUN_GOCHARGE.cs +++ b/Cs_HMI/Project/StateMachine/Step/_SM_RUN_GOCHARGE.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using static Project.StateMachine; using COMM; +using AR; namespace Project { @@ -26,11 +27,7 @@ namespace Project PUB.Result.SetResultMessage(eResult.Hardware, eECode.AGVCONN, eNextStep.ERROR); return false; } - else if (PUB.PLC.IsValid == false) - { - PUB.Result.SetResultMessage(eResult.Hardware, eECode.PLCCONN, eNextStep.ERROR); - return false; - } + //충전 상태가 OFF되어야 동작하게한다 if (_SM_RUN_CHGOFF(isFirst, stepTime) == false) @@ -68,7 +65,7 @@ namespace Project { PUB.Speak(Lang.충전을위해홈위치로이동합니다); PUB.Result.TargetPos = ePosition.QC; - VAR.TIME.Set(eVarTime.ChargeSearch); + VAR.TIME.Update(eVarTime.ChargeSearch); PUB.sm.UpdateRunStepSeq(); PUB.log.Add($"충전:대상위치 QC 시작"); return false; @@ -114,7 +111,7 @@ namespace Project }); PUB.AGV.AGVMoveRun(arDev.Narumi.eRunOpt.Forward); //PUB.Result.TargetPos = ePosition.CHARGE; - VAR.TIME.Set(eVarTime.ChargeSearch); + VAR.TIME.Update(eVarTime.ChargeSearch); } else if (PUB.setting.chargerpos == 2) //up search { @@ -129,7 +126,7 @@ namespace Project }); PUB.AGV.AGVMoveRun(arDev.Narumi.eRunOpt.Backward); //PUB.Result.TargetPos = ePosition.CHARGE; - VAR.TIME.Set(eVarTime.ChargeSearch); + VAR.TIME.Update(eVarTime.ChargeSearch); } else { @@ -148,7 +145,7 @@ namespace Project PUB.log.Add($"충전:AGV기동확인으로 마크정지신호설정"); PUB.Speak(Lang.다음마크위치에서정지합니다); PUB.AGV.AGVMoveStop("SM_RUN_GOCHARGE", arDev.Narumi.eStopOpt.MarkStop); - VAR.TIME.Set(eVarTime.ChargeSearch); + VAR.TIME.Update(eVarTime.ChargeSearch); PUB.sm.UpdateRunStepSeq(); } else @@ -163,7 +160,7 @@ namespace Project } else { - VAR.TIME.Set(eVarTime.ChargeSearch); + VAR.TIME.Update(eVarTime.ChargeSearch); PUB.sm.UpdateRunStepSeq(); } diff --git a/Cs_HMI/Project/StateMachine/Step/_SM_RUN_GOCHARGECHECK.cs b/Cs_HMI/Project/StateMachine/Step/_SM_RUN_GOCHARGECHECK.cs index d0a7124..88b5f4f 100644 --- a/Cs_HMI/Project/StateMachine/Step/_SM_RUN_GOCHARGECHECK.cs +++ b/Cs_HMI/Project/StateMachine/Step/_SM_RUN_GOCHARGECHECK.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using static Project.StateMachine; using COMM; +using AR; namespace Project { diff --git a/Cs_HMI/Project/StateMachine/Step/_SM_RUN_GODOWN.cs b/Cs_HMI/Project/StateMachine/Step/_SM_RUN_GODOWN.cs index 06f6121..01c33a4 100644 --- a/Cs_HMI/Project/StateMachine/Step/_SM_RUN_GODOWN.cs +++ b/Cs_HMI/Project/StateMachine/Step/_SM_RUN_GODOWN.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using static Project.StateMachine; using COMM; +using AR; namespace Project { @@ -25,11 +26,7 @@ namespace Project PUB.Result.SetResultMessage(eResult.Hardware, eECode.AGVCONN, eNextStep.ERROR); return false; } - else if (PUB.PLC.IsValid == false) - { - PUB.Result.SetResultMessage(eResult.Hardware, eECode.PLCCONN, eNextStep.ERROR); - return false; - } + //충전 상태가 OFF되어야 동작하게한다 if (_SM_RUN_CHGOFF(isFirst, stepTime) == false) @@ -124,19 +121,19 @@ namespace Project CoverControlTime = DateTime.Now; UpdateProgressStatus(stepTime.TotalSeconds, 5, Lang.안전커버를내립니다); VAR.BOOL[eVarBool.WAIT_COVER_DOWN] = true; - PUB.PLC.ZMot(arDev.FakePLC.ZMotDirection.Down);// + PUB.AGV.LiftControl(arDev.Narumi.LiftCommand.DN);// PUB.sm.UpdateRunStepSeq(); return false; } else if (PUB.sm.RunStepSeq == 7) { //커버 내림이 완료될때까지 기다린다 - if (PUB.PLC.IsLimitDn() == true) - { - VAR.BOOL[eVarBool.WAIT_COVER_DOWN] = false; - PUB.sm.UpdateRunStepSeq(); - } - else + //if (PUB.PLC.IsLimitDn() == true) + //{ + // VAR.BOOL[eVarBool.WAIT_COVER_DOWN] = false; + // PUB.sm.UpdateRunStepSeq(); + //} + //else { //경과시간이 10초가 지나면 5초마다 음성을 출력한다 var tsCover = DateTime.Now - CoverControlTime; @@ -177,39 +174,39 @@ namespace Project PUB.Speak(Lang.안전커버를올려주세요); CoverControlTime = DateTime.Now; - //한쪽이 올라가 있는 상태에.. - if (PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_LU) == true) - { - //모터는 올리는 방향일때에... - if (PUB.PLC.GetValueO(arDev.FakePLC.DOName.PINO_GUIDEMOTOR_LDIR) == true) - { - //모터가 멈춰있을때에.. - if (PUB.PLC.GetValueO(arDev.FakePLC.DOName.PINO_GUIDEMOTOR_LRUN) == false) - { - //자동으로 올려준다 (센서가 간혹 인식이 안되어서 .대기하는 경우가 잇음) + ////한쪽이 올라가 있는 상태에.. + //if (PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_LU) == true) + //{ + // //모터는 올리는 방향일때에... + // if (PUB.PLC.GetValueO(arDev.FakePLC.DOName.PINO_GUIDEMOTOR_LDIR) == true) + // { + // //모터가 멈춰있을때에.. + // if (PUB.PLC.GetValueO(arDev.FakePLC.DOName.PINO_GUIDEMOTOR_LRUN) == false) + // { + // //자동으로 올려준다 (센서가 간혹 인식이 안되어서 .대기하는 경우가 잇음) - //왼쪽이 올라가 있지 않은 경우 - if (PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_LU) == false) - PUB.PLC.ZMot_Left(arDev.FakePLC.ZMotDirection.Up); - } - } - } - if (PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_RU) == true) - { - //모터는 올리는 방향일때에... - if (PUB.PLC.GetValueO(arDev.FakePLC.DOName.PINO_GUIDEMOTOR_RDIR) == true) - { - //모터가 멈춰있을때에.. - if (PUB.PLC.GetValueO(arDev.FakePLC.DOName.PINO_GUIDEMOTOR_RRUN) == false) - { - //자동으로 올려준다 (센서가 간혹 인식이 안되어서 .대기하는 경우가 잇음) + // //왼쪽이 올라가 있지 않은 경우 + // if (PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_LU) == false) + // PUB.PLC.ZMot_Left(arDev.FakePLC.ZMotDirection.Up); + // } + // } + //} + //if (PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_RU) == true) + //{ + // //모터는 올리는 방향일때에... + // if (PUB.PLC.GetValueO(arDev.FakePLC.DOName.PINO_GUIDEMOTOR_RDIR) == true) + // { + // //모터가 멈춰있을때에.. + // if (PUB.PLC.GetValueO(arDev.FakePLC.DOName.PINO_GUIDEMOTOR_RRUN) == false) + // { + // //자동으로 올려준다 (센서가 간혹 인식이 안되어서 .대기하는 경우가 잇음) - //왼쪽이 올라가 있지 않은 경우 - if (PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_RU) == false) - PUB.PLC.ZMot_Right(arDev.FakePLC.ZMotDirection.Up); - } - } - } + // //왼쪽이 올라가 있지 않은 경우 + // if (PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_RU) == false) + // PUB.PLC.ZMot_Right(arDev.FakePLC.ZMotDirection.Up); + // } + // } + //} } diff --git a/Cs_HMI/Project/StateMachine/Step/_SM_RUN_GOHOME.cs b/Cs_HMI/Project/StateMachine/Step/_SM_RUN_GOHOME.cs index bc925c8..82c8f3d 100644 --- a/Cs_HMI/Project/StateMachine/Step/_SM_RUN_GOHOME.cs +++ b/Cs_HMI/Project/StateMachine/Step/_SM_RUN_GOHOME.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using static Project.StateMachine; using COMM; +using AR; namespace Project { @@ -32,11 +33,7 @@ namespace Project PUB.Result.SetResultMessage(eResult.Hardware, eECode.AGVCONN, eNextStep.ERROR); return false; } - else if (PUB.PLC.IsValid == false) - { - PUB.Result.SetResultMessage(eResult.Hardware, eECode.PLCCONN, eNextStep.ERROR); - return false; - } + //충전 상태가 OFF되어야 동작하게한다 if (_SM_RUN_CHGOFF(isFirst, stepTime) == false) diff --git a/Cs_HMI/Project/StateMachine/Step/_SM_RUN_GOUP.cs b/Cs_HMI/Project/StateMachine/Step/_SM_RUN_GOUP.cs index 97669af..cfc98c4 100644 --- a/Cs_HMI/Project/StateMachine/Step/_SM_RUN_GOUP.cs +++ b/Cs_HMI/Project/StateMachine/Step/_SM_RUN_GOUP.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using static Project.StateMachine; using COMM; +using AR; namespace Project { @@ -25,12 +26,6 @@ namespace Project PUB.Result.SetResultMessage(eResult.Hardware, eECode.AGVCONN, eNextStep.ERROR); return false; } - else if (PUB.PLC.IsValid == false) - { - PUB.Result.SetResultMessage(eResult.Hardware, eECode.PLCCONN, eNextStep.ERROR); - return false; - } - //충전 상태가 OFF되어야 동작하게한다 if (_SM_RUN_CHGOFF(isFirst, stepTime) == false) @@ -111,7 +106,7 @@ namespace Project //커버를 자동으로 내려준다 CoverControlTime = DateTime.Now; UpdateProgressStatus(stepTime.TotalSeconds, 5, Lang.안전커버를내립니다); - PUB.PLC.ZMot(arDev.FakePLC.ZMotDirection.Down); + PUB.AGV.LiftControl(arDev.Narumi.LiftCommand.DN); VAR.BOOL[eVarBool.WAIT_COVER_DOWN] = true; PUB.sm.UpdateRunStepSeq(); return false; @@ -130,7 +125,7 @@ namespace Project //커버 내림이 완료될때까지 기다린다 - if (PUB.PLC.IsLimitDn() == true) + if (true) { VAR.BOOL[eVarBool.WAIT_COVER_DOWN] = false; PUB.Result.NextPos = ePosition.NONE; @@ -138,6 +133,8 @@ namespace Project } else { + + //경과시간이 10초가 지나면 5초마다 음성을 출력한다 var tsCover = DateTime.Now - CoverControlTime; if (tsCover.TotalSeconds >= 7) @@ -179,7 +176,7 @@ namespace Project } else if (PUB.sm.RunStepSeq == idx++) { - + //IO업데이트 간격 전송 UpdateProgressStatus(stepTime.TotalSeconds, 5, Lang.안전커버를올려주세요); PUB.Speak(Lang.안전커버를올리면상차가완료됩니다); @@ -219,47 +216,47 @@ namespace Project PUB.Speak(Lang.안전커버를올려주세요); CoverControlTime = DateTime.Now; - //한쪽이 올라가 있는 상태에.. - if (PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_LU) == true) - { - //모터는 올리는 방향일때에... - if (PUB.PLC.GetValueO(arDev.FakePLC.DOName.PINO_GUIDEMOTOR_LDIR) == true) - { - //모터가 멈춰있을때에.. - if (PUB.PLC.GetValueO(arDev.FakePLC.DOName.PINO_GUIDEMOTOR_LRUN) == false) - { - //자동으로 올려준다 (센서가 간혹 인식이 안되어서 .대기하는 경우가 잇음) + ////한쪽이 올라가 있는 상태에.. + //if (PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_LU) == true) + //{ + // //모터는 올리는 방향일때에... + // if (PUB.PLC.GetValueO(arDev.FakePLC.DOName.PINO_GUIDEMOTOR_LDIR) == true) + // { + // //모터가 멈춰있을때에.. + // if (PUB.PLC.GetValueO(arDev.FakePLC.DOName.PINO_GUIDEMOTOR_LRUN) == false) + // { + // //자동으로 올려준다 (센서가 간혹 인식이 안되어서 .대기하는 경우가 잇음) - //왼쪽이 올라가 있지 않은 경우 - if (PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_LU) == false) - PUB.PLC.ZMot_Left(arDev.FakePLC.ZMotDirection.Up); + // //왼쪽이 올라가 있지 않은 경우 + // if (PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_LU) == false) + // PUB.PLC.ZMot_Left(arDev.FakePLC.ZMotDirection.Up); - //오른쪽이 올라가 있지 않은 경우 - if (PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_RU) == false) - PUB.PLC.ZMot_Right(arDev.FakePLC.ZMotDirection.Up); - } - } - } - if (PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_RU) == true) - { - //모터는 올리는 방향일때에... - if (PUB.PLC.GetValueO(arDev.FakePLC.DOName.PINO_GUIDEMOTOR_RDIR) == true) - { - //모터가 멈춰있을때에.. - if (PUB.PLC.GetValueO(arDev.FakePLC.DOName.PINO_GUIDEMOTOR_RRUN) == false) - { - //자동으로 올려준다 (센서가 간혹 인식이 안되어서 .대기하는 경우가 잇음) + // //오른쪽이 올라가 있지 않은 경우 + // if (PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_RU) == false) + // PUB.PLC.ZMot_Right(arDev.FakePLC.ZMotDirection.Up); + // } + // } + //} + //if (PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_RU) == true) + //{ + // //모터는 올리는 방향일때에... + // if (PUB.PLC.GetValueO(arDev.FakePLC.DOName.PINO_GUIDEMOTOR_RDIR) == true) + // { + // //모터가 멈춰있을때에.. + // if (PUB.PLC.GetValueO(arDev.FakePLC.DOName.PINO_GUIDEMOTOR_RRUN) == false) + // { + // //자동으로 올려준다 (센서가 간혹 인식이 안되어서 .대기하는 경우가 잇음) - //왼쪽이 올라가 있지 않은 경우 - if (PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_LU) == false) - PUB.PLC.ZMot_Left(arDev.FakePLC.ZMotDirection.Up); + // //왼쪽이 올라가 있지 않은 경우 + // if (PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_LU) == false) + // PUB.PLC.ZMot_Left(arDev.FakePLC.ZMotDirection.Up); - //오른쪽이 올라가 있지 않은 경우 - if (PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_RU) == false) - PUB.PLC.ZMot_Right(arDev.FakePLC.ZMotDirection.Up); - } - } - } + // //오른쪽이 올라가 있지 않은 경우 + // if (PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_RU) == false) + // PUB.PLC.ZMot_Right(arDev.FakePLC.ZMotDirection.Up); + // } + // } + //} } } return false; diff --git a/Cs_HMI/Project/StateMachine/Step/_SM_RUN_READY.cs b/Cs_HMI/Project/StateMachine/Step/_SM_RUN_READY.cs index 71833d7..7971b78 100644 --- a/Cs_HMI/Project/StateMachine/Step/_SM_RUN_READY.cs +++ b/Cs_HMI/Project/StateMachine/Step/_SM_RUN_READY.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using AR; using COMM; using static Project.StateMachine; @@ -24,7 +25,7 @@ namespace Project if (VAR.BOOL[eVarBool.FLAG_CHARGEONA] == true) { if (VAR.TIME.IsSet(eVarTime.ChargeStart) == false) - VAR.TIME.Set(eVarTime.ChargeStart); + VAR.TIME.Update(eVarTime.ChargeStart); //충전중이라면 최대 충전 시간을 체크한다. var tsChargeRunTime = VAR.TIME.RUN(eVarTime.ChargeStart); @@ -53,7 +54,7 @@ namespace Project else if (VAR.BOOL[eVarBool.FLAG_CHARGEONM] == true) { if (VAR.TIME.IsSet(eVarTime.ChargeStart) == false) - VAR.TIME.Set(eVarTime.ChargeStart); + VAR.TIME.Update(eVarTime.ChargeStart); VAR.STR[eVarString.ChargeCheckMsg] = "수동 충전"; } @@ -133,7 +134,7 @@ namespace Project { PUB.log.Add($"대기상태에서는 정차"); PUB.AGV.AGVMoveStop("대기상태에서는 정차"); - VAR.TIME.Set(eVarTime.IdleStopTime); + VAR.TIME.Update(eVarTime.IdleStopTime); } } diff --git a/Cs_HMI/Project/StateMachine/Step/_SM_RUN_RESET.cs b/Cs_HMI/Project/StateMachine/Step/_SM_RUN_RESET.cs index fed8f2d..c1ef85a 100644 --- a/Cs_HMI/Project/StateMachine/Step/_SM_RUN_RESET.cs +++ b/Cs_HMI/Project/StateMachine/Step/_SM_RUN_RESET.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using static Project.StateMachine; using COMM; +using AR; namespace Project { diff --git a/Cs_HMI/Project/StateMachine/Step/_SM_RUN_SYNC.cs b/Cs_HMI/Project/StateMachine/Step/_SM_RUN_SYNC.cs index baedea2..fa61a2f 100644 --- a/Cs_HMI/Project/StateMachine/Step/_SM_RUN_SYNC.cs +++ b/Cs_HMI/Project/StateMachine/Step/_SM_RUN_SYNC.cs @@ -6,6 +6,7 @@ using System.Text; using static Project.StateMachine; using COMM; using System.Diagnostics; +using AR; namespace Project { diff --git a/Cs_HMI/Project/StateMachine/Step/_STEP_CLOSE.cs b/Cs_HMI/Project/StateMachine/Step/_STEP_CLOSE.cs index d9d4247..2ab5eca 100644 --- a/Cs_HMI/Project/StateMachine/Step/_STEP_CLOSE.cs +++ b/Cs_HMI/Project/StateMachine/Step/_STEP_CLOSE.cs @@ -15,7 +15,7 @@ namespace Project private void _STEP_CLOSING_START(eSMStep step) { PUB.bShutdown = true; - if (PUB.PLC != null) PUB.PLC.Dispose(); + //if (PUB.PLC != null) PUB.PLC.Dispose(); PUB.AddEEDB("프로그램 종료"); PUB.log.Add("Program Close"); @@ -23,7 +23,7 @@ namespace Project PUB.logagv.Flush(); PUB.logplc.Flush(); PUB.logbms.Flush(); - PUB.logcal.Flush(); + PUB.logxbee.Flush(); // PUB.sm.Stop(); } diff --git a/Cs_HMI/Project/StateMachine/_AGV.cs b/Cs_HMI/Project/StateMachine/_AGV.cs index 6649c3e..09ad6c7 100644 --- a/Cs_HMI/Project/StateMachine/_AGV.cs +++ b/Cs_HMI/Project/StateMachine/_AGV.cs @@ -7,6 +7,7 @@ using System.Text; using arCtl; using static Project.StateMachine; using COMM; +using AR; namespace Project { diff --git a/Cs_HMI/Project/StateMachine/_BMS.cs b/Cs_HMI/Project/StateMachine/_BMS.cs index 01189fd..5f548e1 100644 --- a/Cs_HMI/Project/StateMachine/_BMS.cs +++ b/Cs_HMI/Project/StateMachine/_BMS.cs @@ -7,6 +7,7 @@ using System.Text; using arCtl; using static Project.StateMachine; using COMM; +using AR; namespace Project { diff --git a/Cs_HMI/Project/StateMachine/_DIO.cs b/Cs_HMI/Project/StateMachine/_DIO.cs index d0e4947..d279038 100644 --- a/Cs_HMI/Project/StateMachine/_DIO.cs +++ b/Cs_HMI/Project/StateMachine/_DIO.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; +using AR; using arDev; using COMM; @@ -46,7 +47,7 @@ namespace Project if (VAR.BOOL[eVarBool.WAIT_COVER_UP]) { PUB.log.Add($"버튼({diName}) 눌림"); - PUB.PLC.ZMot(FakePLC.ZMotDirection.Up); + PUB.AGV.LiftControl(arDev.Narumi.LiftCommand.UP); PUB.Result.NextPos = ePosition.QC; } else PUB.Speak(Lang.커버업대기상태가아닙니다); @@ -92,7 +93,7 @@ namespace Project if (VAR.BOOL[eVarBool.WAIT_COVER_UP]) { PUB.log.Add($"버튼({diName}) 눌림"); - PUB.PLC.ZMot(FakePLC.ZMotDirection.Up); + PUB.AGV.LiftControl(arDev.Narumi.LiftCommand.UP); PUB.Result.NextPos = ePosition.QA; } else PUB.Speak(Lang.커버업대기상태가아닙니다); @@ -120,7 +121,7 @@ namespace Project { //Z-up기능으로 업데이트 230119 PUB.log.Add($"버튼({diName}) 눌림"); - PUB.PLC.ZMot(FakePLC.ZMotDirection.Up); + PUB.AGV.LiftControl(arDev.Narumi.LiftCommand.UP); } } else if (diName == arDev.FakePLC.DIName.PINI_EMG) @@ -172,8 +173,8 @@ namespace Project //} //PUB.flag.set(EFlag.FLAG_LIMITHIGH, (PUB.flag.get(EFlag.FLAG_LIMITHIGHL) && PUB.flag.get(EFlag.FLAG_LIMITHIGHR))); //PUB.flag.set(EFlag.FLAG_LIMITLOW, (PUB.flag.get(EFlag.FLAG_LIMITLOWL) && PUB.flag.get(EFlag.FLAG_LIMITLOWR))); - VAR.BOOL[eVarBool.FLAG_LIMITHIGH] = PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_LU) || PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_RU); - VAR.BOOL[eVarBool.FLAG_LIMITLOW] = PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_LD) || PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_RD); + VAR.BOOL[eVarBool.FLAG_LIMITHIGH] = false;// PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_LU) || PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_RU); + VAR.BOOL[eVarBool.FLAG_LIMITLOW] = false;//PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_LD) || PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_LIMIT_RD); VAR.BOOL[eVarBool.OVERLOAD] = (VAR.BOOL[eVarBool.OVERLOADL] || VAR.BOOL[eVarBool.OVERLOADR]); } else @@ -189,109 +190,7 @@ namespace Project DateTime lastplclogtime = DateTime.Now; string logmessage = ""; bool logerror = false; - void PLC_Message(object sender, FakePLC.MessageEventArgs e) - { - if (e.MsgType == arRS232.MessageType.Error) - { - PUB.logplc.Add("ERROR-MAIN", e.Message); - } - else if (e.MsgType == arRS232.MessageType.Normal) - { - //내부클래스에서 발생한 메세지(이 프로그램) - if (e.Message.StartsWith("@STP:") && e.Message.Length > 5) - { - PUB.Result.StopMessageSWR = e.Message.Substring(5); - PUB.Result.StopMessageTimeSWR = DateTime.Now; - } - PUB.logplc.Add("MOT", "[Inner Msg]" + e.Message); - } - else - { - //PLC에서 수신된 메세지 - if (e.Message.StartsWith("@STP|") && e.Message.Length > 5) - { - PUB.Result.StopMessagePLC = e.Message.Substring(5); - PUB.Result.StopMessageTimePLC = DateTime.Now; - PUB.logplc.Add("PLC", "[" + e.MsgType.ToString() + "]" + e.Message); - } - else if (e.Message.StartsWith("@FLAG|") && e.Message.Length > 6) - { - var flagData = e.Message.Split('|')[1].Split(','); - var flag = (COMM.eVarBool)(byte.Parse(flagData[0])); - - var flagmsg = "[" + flag.ToString() + "] = " + flagData[1]; - - - //플래그값이 바뀌면 로깅한다 - var fValueTrue = flagData[1] == "1"; - if (PUB.PLC.GetFlag(flag) != fValueTrue) - { - PUB.logplc.Add("MFLAG", flagmsg); - } - } - else if (e.Message.StartsWith("@SET|") && e.Message.Length > 5) - { - //셋팅관련 정보이다 - var flagData = e.Message.Split('|')[1]; - var splBuf = flagData.Split(':'); - if (splBuf[0] == "SAVE") PUB.PLC.SaveTime = DateTime.Now; - PUB.logplc.Add("SETUP", "[SETTING] " + flagData); - - } - else - { - - if (e.Message.StartsWith("ERR")) - { - logmessage = e.Message; - logerror = true; - } - else if (e.Message.StartsWith("@@") & e.Data.Length == 16) - { - //표시하지 말자 - logerror = false; - var hexstr = e.Data.GetHexString(); - logmessage = "[" + e.MsgType.ToString() + "]" + hexstr; - } - else - { - logmessage = "[" + e.MsgType.ToString() + "]" + e.Message; - logerror = false; - } - - bool addlog = false; - if (lastplclogmessage.StartsWith("[Recv] 40 40")) - { - if (lastplclogmessage.Length > 40) - { - var st = lastplclogmessage.Substring(0, 40); - var cr = logmessage.Substring(0, 40); - addlog = st.Equals(cr) == false; - if (addlog == false) - { - var ts = DateTime.Now - lastplclogtime; - if (ts.TotalSeconds > 5) addlog = true; - } - } - else addlog = true; - } - else if (logmessage.Equals(lastplclogmessage) == false) addlog = true; - else - { - var ts = DateTime.Now - lastplclogtime; - if (ts.TotalSeconds > 30) addlog = true; - } - if (addlog) - { - if (logerror) PUB.logplc.AddE(logmessage); - else PUB.logplc.Add("PLC", logmessage); - lastplclogmessage = logmessage; - lastplclogtime = DateTime.Now; - } - } - } - - } + } } diff --git a/Cs_HMI/Project/StateMachine/_Flag.cs b/Cs_HMI/Project/StateMachine/_Flag.cs index 25aadd8..01acea5 100644 --- a/Cs_HMI/Project/StateMachine/_Flag.cs +++ b/Cs_HMI/Project/StateMachine/_Flag.cs @@ -1,4 +1,5 @@ -using COMM; +using AR; +using COMM; using System; using System.Collections.Generic; using System.ComponentModel; @@ -62,7 +63,7 @@ namespace Project { if (NewValue) { - VAR.TIME.Set(eVarTime.ChargeStart); + VAR.TIME.Update(eVarTime.ChargeStart); PUB.counter.CountChargeA += 1; PUB.counter.Save(); PUB.Speak(Lang.충전을시작합니다); @@ -76,7 +77,7 @@ namespace Project { if (NewValue) { - VAR.TIME.Set(eVarTime.ChargeStart); + VAR.TIME.Update(eVarTime.ChargeStart); PUB.counter.CountChargeM += 1; PUB.counter.Save(); PUB.Speak(Lang.수동충전을시작합니다); diff --git a/Cs_HMI/Project/StateMachine/_Loop.cs b/Cs_HMI/Project/StateMachine/_Loop.cs index 6f28d88..46835a5 100644 --- a/Cs_HMI/Project/StateMachine/_Loop.cs +++ b/Cs_HMI/Project/StateMachine/_Loop.cs @@ -9,6 +9,7 @@ using static Project.StateMachine; using COMM; using System.Windows.Forms; using Project.ViewForm; +using AR; namespace Project { @@ -179,7 +180,7 @@ namespace Project { var b1 = PUB.XBE.IsOpen; var b2 = PUB.AGV.IsOpen; - var b3 = PUB.PLC.IsOpen; + var b3 = true;// PUB.PLC.IsOpen; var b4 = PUB.BMS.IsOpen; if (b1 == false || b2 == false || b3 == false || b4 == false) diff --git a/Cs_HMI/Project/StateMachine/_SPS.cs b/Cs_HMI/Project/StateMachine/_SPS.cs index 6c77a58..7918f90 100644 --- a/Cs_HMI/Project/StateMachine/_SPS.cs +++ b/Cs_HMI/Project/StateMachine/_SPS.cs @@ -4,6 +4,7 @@ using System.Data; using System.Drawing; using System.Linq; using System.Text; +using AR; using arCtl; using COMM; using static Project.StateMachine; @@ -23,10 +24,10 @@ namespace Project var tsPLC = VAR.TIME.RUN(conntry); if (tsPLC.TotalSeconds > 5) { - VAR.TIME.Set(conntry); + VAR.TIME.Update(conntry); try { - VAR.TIME.Set(recvtime); //this.LastReceiveTime = DateTime.Now; + VAR.TIME.Update(recvtime); //this.LastReceiveTime = DateTime.Now; dev.PortName = port; dev.BaudRate = baud; if (dev.Open()) @@ -38,8 +39,8 @@ namespace Project var errmessage = dev.errorMessage; PUB.log.Add("ERROR-" + port, errmessage); } - VAR.TIME.Set(conn); - VAR.TIME.Set(conntry); + VAR.TIME.Update(conn); + VAR.TIME.Update(conntry); } catch (Exception ex) { @@ -51,17 +52,53 @@ namespace Project { PUB.log.Add(port, $"포트변경({dev.PortName}->{port})으로 연결 종료"); dev.Close(); - VAR.TIME.Set(conntry); + VAR.TIME.Update(conntry); } } + void ConnectSerialPort(Device.Xbee dev, string port, int baud, eVarTime conn, eVarTime conntry, eVarTime recvtime) + { + if (dev.IsOpen == false && port.isEmpty() == false) + { + var tsPLC = VAR.TIME.RUN(conntry); + if (tsPLC.TotalSeconds > 5) + { + VAR.TIME.Update(conntry); + try + { + VAR.TIME.Update(recvtime); //this.LastReceiveTime = DateTime.Now; + dev.PortName = port; + dev.BaudRate = baud; + if (dev.Open()) + { + PUB.log.Add(port, "연결완료"); + } + else + { + var errmessage = dev.errorMessage; + PUB.log.Add("ERROR-" + port, errmessage); + } + VAR.TIME.Update(conn); + VAR.TIME.Update(conntry); + } + catch (Exception ex) + { + PUB.log.AddE(ex.Message); + } + } + } + else if (dev.PortName.Equals(port) == false) + { + PUB.log.Add(port, $"포트변경({dev.PortName}->{port})으로 연결 종료"); + dev.Close(); + VAR.TIME[(int)conntry] = DateTime.Now; ; + } + } + void sm_SPS(object sender, EventArgs e) { if (PUB.sm.Step < eSMStep.IDLE || PUB.sm.Step >= eSMStep.CLOSING) return; - //plc connect - ConnectSerialPort(PUB.PLC, PUB.setting.Port_PLC, PUB.setting.Baud_PLC, - eVarTime.LastConn_PLC, eVarTime.LastConnTry_PLC, eVarTime.LastRecv_PLC); - + //agv connect ConnectSerialPort(PUB.AGV, PUB.setting.Port_AGV, PUB.setting.Baud_AGV, eVarTime.LastConn_AGV, eVarTime.LastConnTry_AGV, eVarTime.LastRecv_AGV); @@ -78,14 +115,14 @@ namespace Project if (PUB.XBE != null && PUB.XBE.IsOpen) { //일정간격으로 상태를 전송한다 - if (PUB.XBE.lastSendTime.Year == 1982) PUB.XBE.lastSendTime = DateTime.Now.AddSeconds(1); - var ts = DateTime.Now - PUB.XBE.lastSendTime; + if (PUB.XBE.LastStatusSendTime.Year == 1982) PUB.XBE.LastStatusSendTime = DateTime.Now.AddSeconds(1); + var ts = DateTime.Now - PUB.XBE.LastStatusSendTime; if (ts.TotalSeconds >= PUB.setting.interval_xbe) { - var statusMsg = PUB.XBE.GetStatusString(); - PUB.XBE.SendStatus(statusMsg); + PUB.XBE.SendStatus(); } } + //배터리쿼리 if (PUB.BMS != null && PUB.BMS.IsOpen) { diff --git a/Cs_HMI/Project/StateMachine/_TMDisplay.cs b/Cs_HMI/Project/StateMachine/_TMDisplay.cs index b79a4dd..6b01714 100644 --- a/Cs_HMI/Project/StateMachine/_TMDisplay.cs +++ b/Cs_HMI/Project/StateMachine/_TMDisplay.cs @@ -1,4 +1,5 @@ -using COMM; +using AR; +using COMM; using System; using System.Drawing; using static Project.StateMachine; @@ -231,7 +232,7 @@ namespace Project //hw접속상태 표시 MenuAGV.BackColor = PUB.AGV.IsValid ? Color.FromArgb(40, 40, 40) : Color.Brown; MenuBMS.BackColor = PUB.BMS.IsValid ? Color.FromArgb(40, 40, 40) : Color.Brown; - MenuMAN.BackColor = PUB.PLC.IsValid ? Color.FromArgb(40, 40, 40) : Color.Brown; + MenuMAN.BackColor = PUB.AGV.IsValid ? Color.FromArgb(40, 40, 40) : Color.Brown; btChargeA.Enabled = !VAR.BOOL[eVarBool.FLAG_CHARGEONM]; @@ -296,7 +297,7 @@ namespace Project _AutoResetCount(); //상태를 DB에 저장한다. 230314 - var tsrun = COMM.VAR.TIME.RUN(eVarTime.StatusReporttime); + var tsrun = VAR.TIME.RUN(eVarTime.StatusReporttime); if (tsrun.TotalSeconds >= PUB.setting.StatusInterval) EEMStatus.UpdateStatusSQL(PUB.sm.Step, _extrun: true); tm1minute = DateTime.Now; @@ -410,7 +411,7 @@ namespace Project } - VAR.TIME.Set(eVarTime.BatWarnTime); + VAR.TIME.Update(eVarTime.BatWarnTime); } } } @@ -580,14 +581,14 @@ namespace Project UpdateStatusMessage("비상 정지", Color.Tomato, Color.Black); } } - else if (PUB.PLC.IsOpen == false) - { - UpdateStatusMessage(Lang.PLC연결실패, Color.Tomato, Color.Black); - } - else if (PUB.PLC.IsValid == false) - { - UpdateStatusMessage(Lang.PLC통신실패, Color.Tomato, Color.Black); - } + //else if (PUB.PLC.IsOpen == false) + //{ + // UpdateStatusMessage(Lang.PLC연결실패, Color.Tomato, Color.Black); + //} + //else if (PUB.PLC.IsValid == false) + //{ + // UpdateStatusMessage(Lang.PLC통신실패, Color.Tomato, Color.Black); + //} else if (VAR.BOOL[eVarBool.FLAG_CHARGEONA] == true) { //남은 충전시간 계산 @@ -646,8 +647,8 @@ namespace Project string stMsg; if (PUB.AGV.system1.stop_by_front_detect)//.GetValueI(arDev.FakePLC.DIName.PINI_LIDAR_STOP)) stMsg = Lang.전방에물체가감지되었습니다; - else if (PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_EMG)) - stMsg = Lang.비상정지신호가감지되었습니다; + //else if (PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_EMG)) + // stMsg = Lang.비상정지신호가감지되었습니다; else if (PUB.AGV.signal.front_gate_out == true) stMsg = Lang.선로를이탈했습니다; else if (PUB.AGV.error.runerror_by_no_magent_line) diff --git a/Cs_HMI/Project/ViewForm/fAuto.cs b/Cs_HMI/Project/ViewForm/fAuto.cs index df7b060..48dcdca 100644 --- a/Cs_HMI/Project/ViewForm/fAuto.cs +++ b/Cs_HMI/Project/ViewForm/fAuto.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using System.Windows.Forms; using static Project.StateMachine; using COMM; +using AR; namespace Project.ViewForm { @@ -28,7 +29,7 @@ namespace Project.ViewForm private void fAuto_Load(object sender, EventArgs e) { ctlAuto1.dev_agv = PUB.AGV; - ctlAuto1.dev_plc = PUB.PLC; + // ctlAuto1.dev_plc = PUB.PLC; ctlAuto1.dev_bms = PUB.BMS; ctlAuto1.dev_xbe = PUB.XBE; this.timer1.Start(); @@ -40,7 +41,7 @@ namespace Project.ViewForm { PUB.log.Add("ui reset click"); PUB.AGV.AGVErrorReset(); - } + } } private void Sm_StepChanged(object sender, StepChangeEventArgs e) @@ -52,7 +53,7 @@ namespace Project.ViewForm } private void FAuto_FormClosed(object sender, FormClosedEventArgs e) - { + { timer1.Stop(); PUB.sm.StepChanged -= Sm_StepChanged; this.ctlAuto1.ButtonClick -= CtlAuto1_ButtonClick; @@ -67,21 +68,13 @@ namespace Project.ViewForm this.ctlAuto1.OnUpdateMode = true; - //lbBatteryLevel.Text = $"{PUB.BMS.Current_Level}%"; - //lbBatteryLevel.ProgressValue = PUB.BMS.Current_Level; - - if(this.ctlAuto1.Scean == CtlAuto.eScean.Progress) + if (this.ctlAuto1.Scean == CtlAuto.eScean.Progress) { ctlAuto1.ProgressVal = PUB.Result.SMSG_ProgressValue; ctlAuto1.ProgressMax = PUB.Result.SMSG_ProgressMax; ctlAuto1.StatusMessage = VAR.STR?.Get(eVarString.StatusMessage) ?? string.Empty; } - - //if(Pub.Result.StopMessagePLC.StartsWith() - if (PUB.PLC.GetValueI(arDev.FakePLC.DIName.PINI_EMG) == true) - this.ctlAuto1.StopMessage = PUB.Result.StopMessagePLC; - else - this.ctlAuto1.StopMessage = string.Empty; + this.ctlAuto1.StopMessage = string.Empty; if (PUB.sm.Step == StateMachine.eSMStep.RUN) { diff --git a/Cs_HMI/Project/ViewForm/fFlag.cs b/Cs_HMI/Project/ViewForm/fFlag.cs index 877fe32..3d8d8b5 100644 --- a/Cs_HMI/Project/ViewForm/fFlag.cs +++ b/Cs_HMI/Project/ViewForm/fFlag.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using AR; using COMM; namespace Project.ViewForm diff --git a/Cs_HMI/Project/ViewForm/fIO.Designer.cs b/Cs_HMI/Project/ViewForm/fIO.Designer.cs index 9445ff9..5509aff 100644 --- a/Cs_HMI/Project/ViewForm/fIO.Designer.cs +++ b/Cs_HMI/Project/ViewForm/fIO.Designer.cs @@ -29,28 +29,29 @@ private void InitializeComponent() { this.components = new System.ComponentModel.Container(); - arFrame.Control.ColorListItem colorListItem1 = new arFrame.Control.ColorListItem(); - arFrame.Control.ColorListItem colorListItem2 = new arFrame.Control.ColorListItem(); - arFrame.Control.ColorListItem colorListItem3 = new arFrame.Control.ColorListItem(); - arFrame.Control.ColorListItem colorListItem4 = new arFrame.Control.ColorListItem(); - arFrame.Control.ColorListItem colorListItem5 = new arFrame.Control.ColorListItem(); - arFrame.Control.ColorListItem colorListItem6 = new arFrame.Control.ColorListItem(); - arFrame.Control.ColorListItem colorListItem7 = new arFrame.Control.ColorListItem(); - arFrame.Control.ColorListItem colorListItem8 = new arFrame.Control.ColorListItem(); + arFrame.Control.ColorListItem colorListItem25 = new arFrame.Control.ColorListItem(); + arFrame.Control.ColorListItem colorListItem26 = new arFrame.Control.ColorListItem(); + arFrame.Control.ColorListItem colorListItem27 = new arFrame.Control.ColorListItem(); + arFrame.Control.ColorListItem colorListItem28 = new arFrame.Control.ColorListItem(); + arFrame.Control.ColorListItem colorListItem29 = new arFrame.Control.ColorListItem(); + arFrame.Control.ColorListItem colorListItem30 = new arFrame.Control.ColorListItem(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(fIO)); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.HWState = new arFrame.Control.GridView(); - this.tblMain = new arFrame.Control.GridView(); this.panel1 = new System.Windows.Forms.Panel(); this.label1 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); - this.timer1 = new System.Windows.Forms.Timer(this.components); + this.panel3 = new System.Windows.Forms.Panel(); this.panel2 = new System.Windows.Forms.Panel(); this.button2 = new System.Windows.Forms.Button(); this.button3 = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button(); + this.timer1 = new System.Windows.Forms.Timer(this.components); + this.button4 = new System.Windows.Forms.Button(); + this.button5 = new System.Windows.Forms.Button(); this.tableLayoutPanel1.SuspendLayout(); this.panel1.SuspendLayout(); + this.panel3.SuspendLayout(); this.panel2.SuspendLayout(); this.SuspendLayout(); // @@ -59,8 +60,8 @@ this.tableLayoutPanel1.ColumnCount = 1; this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); this.tableLayoutPanel1.Controls.Add(this.HWState, 0, 2); - this.tableLayoutPanel1.Controls.Add(this.tblMain, 0, 1); this.tableLayoutPanel1.Controls.Add(this.panel1, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.panel3, 0, 1); this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; @@ -68,38 +69,38 @@ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 58F)); - this.tableLayoutPanel1.Size = new System.Drawing.Size(957, 583); + this.tableLayoutPanel1.Size = new System.Drawing.Size(1056, 583); this.tableLayoutPanel1.TabIndex = 5; // // HWState // this.HWState.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(60)))), ((int)(((byte)(60)))), ((int)(((byte)(60))))); this.HWState.BorderSize = 0; - colorListItem1.BackColor1 = System.Drawing.Color.Gray; - colorListItem1.BackColor2 = System.Drawing.Color.FromArgb(((int)(((byte)(100)))), ((int)(((byte)(100)))), ((int)(((byte)(100))))); - colorListItem1.Remark = "타이틀바(상)"; - colorListItem2.BackColor1 = System.Drawing.Color.FromArgb(((int)(((byte)(40)))), ((int)(((byte)(40)))), ((int)(((byte)(40))))); - colorListItem2.BackColor2 = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); - colorListItem2.Remark = "상태표시(하)"; - colorListItem3.BackColor1 = System.Drawing.Color.FromArgb(((int)(((byte)(40)))), ((int)(((byte)(40)))), ((int)(((byte)(40))))); - colorListItem3.BackColor2 = System.Drawing.Color.Lime; - colorListItem3.Remark = "정상"; - colorListItem4.BackColor1 = System.Drawing.Color.FromArgb(((int)(((byte)(40)))), ((int)(((byte)(40)))), ((int)(((byte)(40))))); - colorListItem4.BackColor2 = System.Drawing.Color.Red; - colorListItem4.Remark = "오류"; - colorListItem5.BackColor1 = System.Drawing.Color.FromArgb(((int)(((byte)(40)))), ((int)(((byte)(40)))), ((int)(((byte)(40))))); - colorListItem5.BackColor2 = System.Drawing.Color.Yellow; - colorListItem5.Remark = "오류(깜박)"; - colorListItem6.BackColor1 = System.Drawing.Color.FromArgb(((int)(((byte)(40)))), ((int)(((byte)(40)))), ((int)(((byte)(40))))); - colorListItem6.BackColor2 = System.Drawing.Color.DarkViolet; - colorListItem6.Remark = "오류(유효)"; + colorListItem25.BackColor1 = System.Drawing.Color.Gray; + colorListItem25.BackColor2 = System.Drawing.Color.FromArgb(((int)(((byte)(100)))), ((int)(((byte)(100)))), ((int)(((byte)(100))))); + colorListItem25.Remark = "타이틀바(상)"; + colorListItem26.BackColor1 = System.Drawing.Color.FromArgb(((int)(((byte)(40)))), ((int)(((byte)(40)))), ((int)(((byte)(40))))); + colorListItem26.BackColor2 = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); + colorListItem26.Remark = "상태표시(하)"; + colorListItem27.BackColor1 = System.Drawing.Color.FromArgb(((int)(((byte)(40)))), ((int)(((byte)(40)))), ((int)(((byte)(40))))); + colorListItem27.BackColor2 = System.Drawing.Color.Lime; + colorListItem27.Remark = "정상"; + colorListItem28.BackColor1 = System.Drawing.Color.FromArgb(((int)(((byte)(40)))), ((int)(((byte)(40)))), ((int)(((byte)(40))))); + colorListItem28.BackColor2 = System.Drawing.Color.Red; + colorListItem28.Remark = "오류"; + colorListItem29.BackColor1 = System.Drawing.Color.FromArgb(((int)(((byte)(40)))), ((int)(((byte)(40)))), ((int)(((byte)(40))))); + colorListItem29.BackColor2 = System.Drawing.Color.Yellow; + colorListItem29.Remark = "오류(깜박)"; + colorListItem30.BackColor1 = System.Drawing.Color.FromArgb(((int)(((byte)(40)))), ((int)(((byte)(40)))), ((int)(((byte)(40))))); + colorListItem30.BackColor2 = System.Drawing.Color.DarkViolet; + colorListItem30.Remark = "오류(유효)"; this.HWState.ColorList = new arFrame.Control.ColorListItem[] { - colorListItem1, - colorListItem2, - colorListItem3, - colorListItem4, - colorListItem5, - colorListItem6}; + colorListItem25, + colorListItem26, + colorListItem27, + colorListItem28, + colorListItem29, + colorListItem30}; this.HWState.Dock = System.Windows.Forms.DockStyle.Fill; this.HWState.Font = new System.Drawing.Font("Consolas", 13F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.HWState.FontPin = new System.Drawing.Font("Consolas", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); @@ -107,7 +108,7 @@ this.HWState.ForeColorPin = System.Drawing.Color.Moccasin; this.HWState.Location = new System.Drawing.Point(0, 525); this.HWState.Margin = new System.Windows.Forms.Padding(0); - this.HWState.MatrixSize = new System.Drawing.Point(4, 2); + this.HWState.MatrixSize = new System.Drawing.Point(3, 2); this.HWState.MenuBorderSize = 1; this.HWState.MenuGap = 5; this.HWState.MinimumSize = new System.Drawing.Size(100, 0); @@ -128,61 +129,21 @@ this.HWState.ShadowColor = System.Drawing.Color.FromArgb(((int)(((byte)(60)))), ((int)(((byte)(60)))), ((int)(((byte)(60))))); this.HWState.showDebugInfo = false; this.HWState.ShowIndexString = false; - this.HWState.Size = new System.Drawing.Size(957, 58); + this.HWState.Size = new System.Drawing.Size(1056, 58); this.HWState.TabIndex = 9; this.HWState.Tags = null; this.HWState.Text = "gridView3"; this.HWState.TextAttachToImage = true; this.HWState.Titles = new string[] { - "AGV|XBE|PLC|BAT|", - "C00|C00|C00|C00|"}; + "AGV|XBE|BAT|", + "C00|C00|C00|"}; this.HWState.Values = new ushort[] { ((ushort)(0)), ((ushort)(0)), ((ushort)(0)), - ((ushort)(0)), - ((ushort)(1)), ((ushort)(1)), ((ushort)(1)), ((ushort)(1))}; - // - // tblMain - // - this.tblMain.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(100)))), ((int)(((byte)(100)))), ((int)(((byte)(100))))); - this.tblMain.BorderSize = 1; - colorListItem7.BackColor1 = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30))))); - colorListItem7.BackColor2 = System.Drawing.Color.FromArgb(((int)(((byte)(18)))), ((int)(((byte)(18)))), ((int)(((byte)(18))))); - colorListItem7.Remark = ""; - colorListItem8.BackColor1 = System.Drawing.Color.Orange; - colorListItem8.BackColor2 = System.Drawing.Color.DarkOrange; - colorListItem8.Remark = ""; - this.tblMain.ColorList = new arFrame.Control.ColorListItem[] { - colorListItem7, - colorListItem8}; - this.tblMain.Cursor = System.Windows.Forms.Cursors.Arrow; - this.tblMain.Dock = System.Windows.Forms.DockStyle.Fill; - this.tblMain.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.tblMain.FontPin = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Bold); - this.tblMain.ForeColor = System.Drawing.Color.White; - this.tblMain.ForeColorPin = System.Drawing.Color.WhiteSmoke; - this.tblMain.Location = new System.Drawing.Point(3, 23); - this.tblMain.MatrixSize = new System.Drawing.Point(8, 4); - this.tblMain.MenuBorderSize = 1; - this.tblMain.MenuGap = 5; - this.tblMain.MinimumSize = new System.Drawing.Size(100, 50); - this.tblMain.Name = "tblMain"; - this.tblMain.Names = null; - this.tblMain.ShadowColor = System.Drawing.Color.Black; - this.tblMain.showDebugInfo = false; - this.tblMain.ShowIndexString = true; - this.tblMain.Size = new System.Drawing.Size(951, 499); - this.tblMain.TabIndex = 4; - this.tblMain.Tags = null; - this.tblMain.Text = "gridView1"; - this.tblMain.TextAttachToImage = true; - this.tblMain.Titles = null; - this.tblMain.Values = null; - this.tblMain.ItemClick += new System.EventHandler(this.tblIn1_ItemClick); // // panel1 // @@ -191,7 +152,7 @@ this.panel1.Dock = System.Windows.Forms.DockStyle.Fill; this.panel1.Location = new System.Drawing.Point(3, 3); this.panel1.Name = "panel1"; - this.panel1.Size = new System.Drawing.Size(951, 14); + this.panel1.Size = new System.Drawing.Size(1050, 14); this.panel1.TabIndex = 6; // // label1 @@ -200,7 +161,7 @@ this.label1.ForeColor = System.Drawing.Color.White; this.label1.Location = new System.Drawing.Point(0, 0); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(551, 14); + this.label1.Size = new System.Drawing.Size(650, 14); this.label1.TabIndex = 5; this.label1.Text = "label1"; this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; @@ -209,17 +170,23 @@ // this.label3.Dock = System.Windows.Forms.DockStyle.Right; this.label3.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(128))))); - this.label3.Location = new System.Drawing.Point(551, 0); + this.label3.Location = new System.Drawing.Point(650, 0); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(400, 14); this.label3.TabIndex = 6; this.label3.Text = "label3"; this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // - // timer1 + // panel3 // - this.timer1.Interval = 200; - this.timer1.Tick += new System.EventHandler(this.timer1_Tick); + this.panel3.Controls.Add(this.button5); + this.panel3.Controls.Add(this.button4); + this.panel3.Controls.Add(this.panel2); + this.panel3.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel3.Location = new System.Drawing.Point(3, 23); + this.panel3.Name = "panel3"; + this.panel3.Size = new System.Drawing.Size(1050, 499); + this.panel3.TabIndex = 10; // // panel2 // @@ -227,10 +194,9 @@ this.panel2.Controls.Add(this.button2); this.panel2.Controls.Add(this.button3); this.panel2.Controls.Add(this.button1); - this.panel2.Dock = System.Windows.Forms.DockStyle.Right; - this.panel2.Location = new System.Drawing.Point(957, 0); + this.panel2.Location = new System.Drawing.Point(925, 15); this.panel2.Name = "panel2"; - this.panel2.Size = new System.Drawing.Size(99, 583); + this.panel2.Size = new System.Drawing.Size(99, 315); this.panel2.TabIndex = 6; // // button2 @@ -239,7 +205,7 @@ this.button2.Image = ((System.Drawing.Image)(resources.GetObject("button2.Image"))); this.button2.Location = new System.Drawing.Point(0, 100); this.button2.Name = "button2"; - this.button2.Size = new System.Drawing.Size(99, 383); + this.button2.Size = new System.Drawing.Size(99, 115); this.button2.TabIndex = 1; this.button2.UseVisualStyleBackColor = true; this.button2.Click += new System.EventHandler(this.button2_Click); @@ -248,7 +214,7 @@ // this.button3.Dock = System.Windows.Forms.DockStyle.Bottom; this.button3.Image = ((System.Drawing.Image)(resources.GetObject("button3.Image"))); - this.button3.Location = new System.Drawing.Point(0, 483); + this.button3.Location = new System.Drawing.Point(0, 215); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(99, 100); this.button3.TabIndex = 2; @@ -266,13 +232,37 @@ this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // + // timer1 + // + this.timer1.Interval = 200; + this.timer1.Tick += new System.EventHandler(this.timer1_Tick); + // + // button4 + // + this.button4.Location = new System.Drawing.Point(726, 53); + this.button4.Name = "button4"; + this.button4.Size = new System.Drawing.Size(134, 100); + this.button4.TabIndex = 7; + this.button4.Text = "Magnet On"; + this.button4.UseVisualStyleBackColor = true; + this.button4.Click += new System.EventHandler(this.button4_Click); + // + // button5 + // + this.button5.Location = new System.Drawing.Point(726, 159); + this.button5.Name = "button5"; + this.button5.Size = new System.Drawing.Size(134, 100); + this.button5.TabIndex = 8; + this.button5.Text = "Magnet Off"; + this.button5.UseVisualStyleBackColor = true; + this.button5.Click += new System.EventHandler(this.button5_Click); + // // fIO // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(15)))), ((int)(((byte)(15)))), ((int)(((byte)(15))))); this.ClientSize = new System.Drawing.Size(1056, 583); this.Controls.Add(this.tableLayoutPanel1); - this.Controls.Add(this.panel2); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.Name = "fIO"; this.Text = "fIO"; @@ -280,14 +270,13 @@ this.VisibleChanged += new System.EventHandler(this.fIO_VisibleChanged); this.tableLayoutPanel1.ResumeLayout(false); this.panel1.ResumeLayout(false); + this.panel3.ResumeLayout(false); this.panel2.ResumeLayout(false); this.ResumeLayout(false); } #endregion - - private arFrame.Control.GridView tblMain; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; private System.Windows.Forms.Timer timer1; private System.Windows.Forms.Label label1; @@ -298,5 +287,8 @@ private System.Windows.Forms.Button button2; private System.Windows.Forms.Button button3; private System.Windows.Forms.Button button1; + private System.Windows.Forms.Panel panel3; + private System.Windows.Forms.Button button4; + private System.Windows.Forms.Button button5; } } \ No newline at end of file diff --git a/Cs_HMI/Project/ViewForm/fIO.cs b/Cs_HMI/Project/ViewForm/fIO.cs index 4163df5..1d9d5c7 100644 --- a/Cs_HMI/Project/ViewForm/fIO.cs +++ b/Cs_HMI/Project/ViewForm/fIO.cs @@ -16,7 +16,6 @@ namespace Project.ViewForm { InitializeComponent(); - tblMain.SuspendLayout(); //이름설정 INput #1 List namearray = new List(32); @@ -50,25 +49,17 @@ namespace Project.ViewForm } namearray.Add(flagName); } - this.tblMain.setTitle(namearray.ToArray()); - this.tblMain.setTag(tagarray.ToArray()); - this.tblMain.setItemTextAlign(ContentAlignment.BottomLeft); + + ////값설정 + //List fgValueM = new List(); + //List fgValueS = new List(); + ////mainplc + //for (byte i = 0; i < 16; i++) + // fgValueM.Add(PUB.PLC.GetValueI(i)); + //for (byte i = 0; i < 16; i++) + // fgValueM.Add(PUB.PLC.GetValueO(i)); - //값설정 - List fgValueM = new List(); - List fgValueS = new List(); - - //mainplc - for (byte i = 0; i < 16; i++) - fgValueM.Add(PUB.PLC.GetValueI(i)); - for (byte i = 0; i < 16; i++) - fgValueM.Add(PUB.PLC.GetValueO(i)); - - - - tblMain.setValue(fgValueM.ToArray()); - tblMain.ResumeLayout(); this.FormClosed += FIO_FormClosed; UpdateControl(); @@ -85,8 +76,8 @@ namespace Project.ViewForm if (PUB.XBE.IsOpen == false) BlinkGridViewItem(HWState, rownum, colIdx++, 3, 4); else HWState.setValue(rownum, colIdx++, 2); // - if (PUB.PLC.IsOpen == false) BlinkGridViewItem(HWState, rownum, colIdx++, 3, 4); - else HWState.setValue(rownum, colIdx++, 2); // + //if (PUB.PLC.IsOpen == false) BlinkGridViewItem(HWState, rownum, colIdx++, 3, 4); + //else HWState.setValue(rownum, colIdx++, 2); // if (PUB.BMS.IsOpen == false) BlinkGridViewItem(HWState, rownum, colIdx++, 3, 4); else HWState.setValue(rownum, colIdx++, 2); // @@ -103,13 +94,13 @@ namespace Project.ViewForm var colIdx = 0; HWState.setTitle(0, colIdx++, "AGV"); HWState.setTitle(0, colIdx++, "XBE"); - HWState.setTitle(0, colIdx++, "PLC"); + //HWState.setTitle(0, colIdx++, "PLC"); HWState.setTitle(0, colIdx++, "BAT"); colIdx = 0; HWState.setTitle(rowNum, colIdx++, PUB.setting.Port_AGV); HWState.setTitle(rowNum, colIdx++, PUB.setting.Port_XBE); - HWState.setTitle(rowNum, colIdx++, PUB.setting.Port_PLC); + //HWState.setTitle(rowNum, colIdx++, PUB.setting.Port_PLC); HWState.setTitle(rowNum, colIdx++, PUB.setting.Port_BAT); HWState.Invalidate(); @@ -126,27 +117,7 @@ namespace Project.ViewForm } - private void tblIn1_ItemClick(object sender, arFrame.Control.GridView.ItemClickEventArgs e) - { - var dataIndex = (byte)e.idx; - if (dataIndex >= 16) - { - var ctl = sender as arFrame.Control.GridView; - var pinNoStr = ctl.Tags[e.idx]; - if (pinNoStr.isEmpty() == true) - { - Util.MsgE("해당 포트는 핀번호가 설정되지 않았습니다", true); - } - else - { - var pinNo = byte.Parse(pinNoStr); - var curVal = PUB.PLC.GetValueO((byte)(dataIndex - 16)); - PUB.PLC.SetOutput(pinNo, !curVal);// .Sendcommand(Device.PLC1.eCommand.SET_DOUTPUT, pinNo, newval); - } - } - else Util.MsgE("해당 주소는 허용되지 않습니다.", true); - } - + bool tmrun = false; @@ -156,24 +127,11 @@ namespace Project.ViewForm if (tmrun == true) return; tmrun = true; - label1.Text = string.Format("{0} / {1}", - PUB.PLC.ioBinStr, PUB.PLC.SetupStr); - label3.Text = PUB.PLC.LastMessage; - Update_HWStatus(); List fgValueM = new List(); List fgValueS = new List(); - //mainplc - for (byte i = 0; i < 16; i++) - this.tblMain.setValue(i, PUB.PLC.GetValueI(i)); - - for (byte i = 0; i < 16; i++) - this.tblMain.setValue(i + 16, PUB.PLC.GetValueO(i)); - - - this.tblMain.Invalidate(); tmrun = false; } @@ -187,18 +145,28 @@ namespace Project.ViewForm private void button1_Click(object sender, EventArgs e) { - PUB.PLC.ZMot(arDev.FakePLC.ZMotDirection.Up); + PUB.AGV.LiftControl(arDev.Narumi.LiftCommand.UP); } private void button2_Click(object sender, EventArgs e) { - PUB.PLC.ZMot(arDev.FakePLC.ZMotDirection.Stop); + PUB.AGV.LiftControl(arDev.Narumi.LiftCommand.STP); } private void button3_Click_1(object sender, EventArgs e) { - PUB.PLC.ZMot(arDev.FakePLC.ZMotDirection.Down); + PUB.AGV.LiftControl(arDev.Narumi.LiftCommand.DN); + } + + private void button4_Click(object sender, EventArgs e) + { + PUB.AGV.LiftControl(arDev.Narumi.LiftCommand.ON); + } + + private void button5_Click(object sender, EventArgs e) + { + PUB.AGV.LiftControl(arDev.Narumi.LiftCommand.OFF); } } } diff --git a/Cs_HMI/Project/ViewForm/fIO.resx b/Cs_HMI/Project/ViewForm/fIO.resx index f0d1f60..5c09ea0 100644 --- a/Cs_HMI/Project/ViewForm/fIO.resx +++ b/Cs_HMI/Project/ViewForm/fIO.resx @@ -117,9 +117,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 17, 17 - @@ -211,4 +208,7 @@ iAXpTl+ARH8vfFW5YszxNxI+Afqdj2aEL3vaoNP9AxkclDhe7/QIAAAAAElFTkSuQmCC + + 17, 17 + \ No newline at end of file diff --git a/Cs_HMI/Project/ViewForm/fManual.cs b/Cs_HMI/Project/ViewForm/fManual.cs index 94513ce..7f9d0d5 100644 --- a/Cs_HMI/Project/ViewForm/fManual.cs +++ b/Cs_HMI/Project/ViewForm/fManual.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using AR; using arDev; using COMM; @@ -330,25 +331,7 @@ namespace Project.ViewForm } - private void button2_Click(object sender, EventArgs e) - { - PUB.AGV.AGVCommand("SCK", "0010"); - } - - private void button2_Click_1(object sender, EventArgs e) - { - PUB.PLC.ZMot(arDev.FakePLC.ZMotDirection.Stop); - } - - private void button3_Click_1(object sender, EventArgs e) - { - PUB.PLC.ZMot(arDev.FakePLC.ZMotDirection.Up); - } - - private void button4_Click_1(object sender, EventArgs e) - { - PUB.PLC.ZMot(arDev.FakePLC.ZMotDirection.Down); - } + private void arLabel1_Click_1(object sender, EventArgs e) { diff --git a/Cs_HMI/Project/fMain.cs b/Cs_HMI/Project/fMain.cs index c0249be..f2882d6 100644 --- a/Cs_HMI/Project/fMain.cs +++ b/Cs_HMI/Project/fMain.cs @@ -12,6 +12,7 @@ using Microsoft.Speech.Synthesis; using Microsoft.Speech; using COMM; using System.CodeDom; +using AR; namespace Project { @@ -31,7 +32,7 @@ namespace Project public fMain() { InitializeComponent(); - COMM.VAR.Init(128); + VAR.Init(128); PUB.initCore(); this.KeyDown += (s1, e1) => { @@ -186,15 +187,15 @@ namespace Project VAR.BOOL.PropertyChanged += BOOL_PropertyChanged; - ///모터용 pLC - PUB.PLC = new arDev.FakePLC(); - PUB.PLC.ValueChanged += PLC_DioChanged; - PUB.PLC.FlagChanged += PLC_FlagChanged; - PUB.PLC.Message += PLC_Message; + /////모터용 pLC + //PUB.PLC = new arDev.FakePLC(); + //PUB.PLC.ValueChanged += PLC_DioChanged; + //PUB.PLC.FlagChanged += PLC_FlagChanged; + //PUB.PLC.Message += PLC_Message; //지그비통신 PUB.XBE = new Device.Xbee(); - PUB.XBE.Message += Xbee_Message; + //PUB.XBE.Message += Xbee_Message; //HWState.setTitle(1, 3, Pub.setting.Port_Xbee); //HWState.setTitle(1, 0, Pub.setting.Address_RFID); @@ -294,63 +295,7 @@ namespace Project #endregion - string last_xbee_tx = ""; - string last_xbee_rx = ""; - - DateTime lasttime_xbee_tx = DateTime.Now; - DateTime lasttime_xbee_rx = DateTime.Now; - private void Xbee_Message(object sender, arDev.arRS232.MessageEventArgs e) - { - if (e.MsgType == arDev.arRS232.MessageType.Error) PUB.logcal.AddE("xbee err : " + e.Message); - else if (e.MsgType == arDev.arRS232.MessageType.Normal) PUB.logcal.Add("xbe", e.Message); - else if (e.MsgType == arDev.arRS232.MessageType.Recv) - { - var datastr = System.Text.Encoding.Default.GetString(e.Data, 1, e.Data.Length - 2); - var val = datastr.Substring(datastr.Length - 1); - var kitno = datastr.Substring(0, datastr.Length - 1); - - if (last_xbee_rx.Equals(e.Message) == false) - { - PUB.logcal.Add("xbe-rx", e.Message); - last_xbee_rx = e.Message; - lasttime_xbee_rx = DateTime.Now; - } - else - { - var ts = DateTime.Now - lasttime_xbee_rx; - if (ts.TotalSeconds > 30) - { - PUB.logcal.Add("xbe-rx", e.Message); - last_xbee_rx = e.Message; - lasttime_xbee_rx = DateTime.Now; - } - } - - PUB.log.Add($"콜버튼:{kitno} 값:{val} 수신"); - //PUB.XBE.NewMsgEvent(kitno[0], val[0]); - } - else if (e.MsgType == arDev.arRS232.MessageType.Send) - { - if (last_xbee_tx.Equals(e.Message) == false) - { - PUB.logcal.Add("xbe-tx", e.Message); - last_xbee_tx = e.Message; - lasttime_xbee_tx = DateTime.Now; - } - else - { - var ts = DateTime.Now - lasttime_xbee_tx; - if (ts.TotalSeconds > 30) - { - PUB.logcal.Add("xbe-tx", e.Message); - last_xbee_tx = e.Message; - lasttime_xbee_tx = DateTime.Now; - } - } - - } - else PUB.logcal.Add("XBEE", $"Rx:{e.Message}"); - } + private void CtlPos1_ItemClick(object sender, CtlPos.ItemClickEventArgs e) { if (VAR.BOOL[eVarBool.FLAG_CHARGEONM] == true) @@ -1005,7 +950,7 @@ namespace Project private void btChargeM_Click(object sender, EventArgs e) { - if (COMM.VAR.BOOL[eVarBool.FLAG_CHARGEONM]) + if (VAR.BOOL[eVarBool.FLAG_CHARGEONM]) { var dlg = Util.MsgQ("수동 충전을 해제 할까요?"); if (dlg != DialogResult.Yes) return; diff --git a/Cs_HMI/Project/fSetup.Designer.cs b/Cs_HMI/Project/fSetup.Designer.cs index 0e61e4b..8511491 100644 --- a/Cs_HMI/Project/fSetup.Designer.cs +++ b/Cs_HMI/Project/fSetup.Designer.cs @@ -84,7 +84,6 @@ this.button3 = new System.Windows.Forms.Button(); this.label30 = new System.Windows.Forms.Label(); this.label12 = new System.Windows.Forms.Label(); - this.label13 = new System.Windows.Forms.Label(); this.button2 = new System.Windows.Forms.Button(); this.tbBaudBAT = new System.Windows.Forms.ComboBox(); this.tbportBMS = new System.Windows.Forms.TextBox(); @@ -93,16 +92,11 @@ this.tbBaudAGV = new System.Windows.Forms.ComboBox(); this.tbPortAGV = new System.Windows.Forms.TextBox(); this.label6 = new System.Windows.Forms.Label(); - this.btSelPlc1 = new System.Windows.Forms.Button(); this.btSelXbee = new System.Windows.Forms.Button(); - this.tbBaudPLC = new System.Windows.Forms.ComboBox(); this.tbBaudXBE = new System.Windows.Forms.ComboBox(); - this.tbPortPLC = new System.Windows.Forms.TextBox(); this.tbPortXBE = new System.Windows.Forms.TextBox(); - this.label7 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label(); this.valIntervalBMS = new AGVControl.ValueSelect(); - this.valueSelect4 = new AGVControl.ValueSelect(); this.valIntervalXBE = new AGVControl.ValueSelect(); this.tabPage3 = new System.Windows.Forms.TabPage(); this.cmbChargerPos = new System.Windows.Forms.ComboBox(); @@ -171,6 +165,7 @@ this.vcTagNOT = new AGVControl.ValueSelect(); this.tabPage4 = new System.Windows.Forms.TabPage(); this.groupBox3 = new System.Windows.Forms.GroupBox(); + this.chkClearPos = new System.Windows.Forms.CheckBox(); this.propertyGrid1 = new System.Windows.Forms.PropertyGrid(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.tbMCID = new System.Windows.Forms.TextBox(); @@ -207,7 +202,6 @@ this.bt1 = new arCtl.arLabel(); this.bt0 = new arCtl.arLabel(); this.btSave = new arCtl.arLabel(); - this.chkClearPos = new System.Windows.Forms.CheckBox(); this.tabControl1.SuspendLayout(); this.tabPage6.SuspendLayout(); this.panel1.SuspendLayout(); @@ -1236,7 +1230,6 @@ this.tabPage2.Controls.Add(this.button3); this.tabPage2.Controls.Add(this.label30); this.tabPage2.Controls.Add(this.label12); - this.tabPage2.Controls.Add(this.label13); this.tabPage2.Controls.Add(this.button2); this.tabPage2.Controls.Add(this.tbBaudBAT); this.tabPage2.Controls.Add(this.tbportBMS); @@ -1245,16 +1238,11 @@ this.tabPage2.Controls.Add(this.tbBaudAGV); this.tabPage2.Controls.Add(this.tbPortAGV); this.tabPage2.Controls.Add(this.label6); - this.tabPage2.Controls.Add(this.btSelPlc1); this.tabPage2.Controls.Add(this.btSelXbee); - this.tabPage2.Controls.Add(this.tbBaudPLC); this.tabPage2.Controls.Add(this.tbBaudXBE); - this.tabPage2.Controls.Add(this.tbPortPLC); this.tabPage2.Controls.Add(this.tbPortXBE); - this.tabPage2.Controls.Add(this.label7); this.tabPage2.Controls.Add(this.label5); this.tabPage2.Controls.Add(this.valIntervalBMS); - this.tabPage2.Controls.Add(this.valueSelect4); this.tabPage2.Controls.Add(this.valIntervalXBE); this.tabPage2.Location = new System.Drawing.Point(4, 4); this.tabPage2.Name = "tabPage2"; @@ -1296,17 +1284,6 @@ this.label12.TabIndex = 33; this.label12.Text = "ms"; // - // label13 - // - this.label13.AutoSize = true; - this.label13.Font = new System.Drawing.Font("궁서체", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(129))); - this.label13.ForeColor = System.Drawing.Color.WhiteSmoke; - this.label13.Location = new System.Drawing.Point(946, 114); - this.label13.Name = "label13"; - this.label13.Size = new System.Drawing.Size(36, 24); - this.label13.TabIndex = 15; - this.label13.Text = "ms"; - // // button2 // this.button2.Location = new System.Drawing.Point(383, 178); @@ -1405,17 +1382,6 @@ this.label6.TabIndex = 21; this.label6.Text = "AGV PORT"; // - // btSelPlc1 - // - this.btSelPlc1.Location = new System.Drawing.Point(383, 98); - this.btSelPlc1.Name = "btSelPlc1"; - this.btSelPlc1.Size = new System.Drawing.Size(89, 56); - this.btSelPlc1.TabIndex = 15; - this.btSelPlc1.Tag = "PLC"; - this.btSelPlc1.Text = "..."; - this.btSelPlc1.UseVisualStyleBackColor = true; - this.btSelPlc1.Click += new System.EventHandler(this.btSelXbee_Click); - // // btSelXbee // this.btSelXbee.Location = new System.Drawing.Point(383, 257); @@ -1427,23 +1393,6 @@ this.btSelXbee.UseVisualStyleBackColor = true; this.btSelXbee.Click += new System.EventHandler(this.btSelXbee_Click); // - // tbBaudPLC - // - this.tbBaudPLC.Font = new System.Drawing.Font("궁서체", 32F, System.Drawing.FontStyle.Bold); - this.tbBaudPLC.FormattingEnabled = true; - this.tbBaudPLC.Items.AddRange(new object[] { - "4800", - "9600", - "19200", - "46800", - "115200", - "250000"}); - this.tbBaudPLC.Location = new System.Drawing.Point(478, 101); - this.tbBaudPLC.Name = "tbBaudPLC"; - this.tbBaudPLC.Size = new System.Drawing.Size(217, 51); - this.tbBaudPLC.TabIndex = 10; - this.tbBaudPLC.Tag = "P1"; - // // tbBaudXBE // this.tbBaudXBE.Font = new System.Drawing.Font("궁서체", 32F, System.Drawing.FontStyle.Bold); @@ -1461,16 +1410,6 @@ this.tbBaudXBE.TabIndex = 8; this.tbBaudXBE.Tag = "XB"; // - // tbPortPLC - // - this.tbPortPLC.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224))))); - this.tbPortPLC.Font = new System.Drawing.Font("궁서체", 32F, System.Drawing.FontStyle.Bold); - this.tbPortPLC.Location = new System.Drawing.Point(161, 98); - this.tbPortPLC.Name = "tbPortPLC"; - this.tbPortPLC.Size = new System.Drawing.Size(216, 56); - this.tbPortPLC.TabIndex = 5; - this.tbPortPLC.Tag = "P1"; - // // tbPortXBE // this.tbPortXBE.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224))))); @@ -1481,17 +1420,6 @@ this.tbPortXBE.TabIndex = 3; this.tbPortXBE.Tag = "XB"; // - // label7 - // - this.label7.AutoSize = true; - this.label7.Font = new System.Drawing.Font("궁서체", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(129))); - this.label7.ForeColor = System.Drawing.Color.WhiteSmoke; - this.label7.Location = new System.Drawing.Point(38, 114); - this.label7.Name = "label7"; - this.label7.Size = new System.Drawing.Size(114, 24); - this.label7.TabIndex = 2; - this.label7.Text = "PLC PORT"; - // // label5 // this.label5.AutoSize = true; @@ -1526,29 +1454,6 @@ this.valIntervalBMS.Value = 0D; this.valIntervalBMS.ButtonClick += new System.EventHandler(this.valIntervalBMS_ButtonClick); // - // valueSelect4 - // - this.valueSelect4.BackColorButton = System.Drawing.Color.White; - this.valueSelect4.ButtonWidth = "30"; - this.valueSelect4.ColorBorder = System.Drawing.Color.White; - this.valueSelect4.DecimalPosition = ((ushort)(0)); - this.valueSelect4.Font = new System.Drawing.Font("궁서체", 32F, System.Drawing.FontStyle.Bold); - this.valueSelect4.FontSideButton = new System.Drawing.Font("Consolas", 15F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.valueSelect4.ForeColor = System.Drawing.Color.White; - this.valueSelect4.ForeColorButton = System.Drawing.Color.Black; - this.valueSelect4.Location = new System.Drawing.Point(701, 101); - this.valueSelect4.MaxValue = 254D; - this.valueSelect4.MinValue = 0D; - this.valueSelect4.Name = "valueSelect4"; - this.valueSelect4.NullDisplay = "--"; - this.valueSelect4.SideButtonClickValue = 20D; - this.valueSelect4.Size = new System.Drawing.Size(239, 51); - this.valueSelect4.TabIndex = 13; - this.valueSelect4.Tag = "SL"; - this.valueSelect4.Text = "1"; - this.valueSelect4.Value = 1D; - this.valueSelect4.ButtonClick += new System.EventHandler(this.vcChargeLow_ButtonClick); - // // valIntervalXBE // this.valIntervalXBE.BackColorButton = System.Drawing.Color.White; @@ -2762,6 +2667,17 @@ this.groupBox3.TabStop = false; this.groupBox3.Text = "일반 설정"; // + // chkClearPos + // + this.chkClearPos.AutoSize = true; + this.chkClearPos.Font = new System.Drawing.Font("궁서체", 20F, System.Drawing.FontStyle.Bold); + this.chkClearPos.Location = new System.Drawing.Point(27, 371); + this.chkClearPos.Name = "chkClearPos"; + this.chkClearPos.Size = new System.Drawing.Size(468, 31); + this.chkClearPos.TabIndex = 12; + this.chkClearPos.Text = "자동모드 해제 시 위치정보 삭제"; + this.chkClearPos.UseVisualStyleBackColor = true; + // // propertyGrid1 // this.propertyGrid1.Font = new System.Drawing.Font("맑은 고딕", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(129))); @@ -3410,17 +3326,6 @@ this.btSave.TextVisible = true; this.btSave.Click += new System.EventHandler(this.btSave_Click); // - // chkClearPos - // - this.chkClearPos.AutoSize = true; - this.chkClearPos.Font = new System.Drawing.Font("궁서체", 20F, System.Drawing.FontStyle.Bold); - this.chkClearPos.Location = new System.Drawing.Point(27, 371); - this.chkClearPos.Name = "chkClearPos"; - this.chkClearPos.Size = new System.Drawing.Size(468, 31); - this.chkClearPos.TabIndex = 12; - this.chkClearPos.Text = "자동모드 해제 시 위치정보 삭제"; - this.chkClearPos.UseVisualStyleBackColor = true; - // // fSetup // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; @@ -3477,20 +3382,14 @@ private System.Windows.Forms.Panel panel1; private System.Windows.Forms.TabPage tabPage2; private System.Windows.Forms.Label label5; - private System.Windows.Forms.Label label7; private System.Windows.Forms.TextBox tbPortXBE; - private System.Windows.Forms.TextBox tbPortPLC; private System.Windows.Forms.ComboBox tbBaudXBE; - private System.Windows.Forms.ComboBox tbBaudPLC; private System.Windows.Forms.Button btSelXbee; - private System.Windows.Forms.Button btSelPlc1; private System.Windows.Forms.Panel panTopMenu; private arCtl.arLabel btClose; private System.Windows.Forms.PictureBox pictureBox1; private System.Windows.Forms.Label label10; private AGVControl.ValueSelect valIntervalXBE; - private AGVControl.ValueSelect valueSelect4; - private System.Windows.Forms.Label label13; private System.Windows.Forms.Timer timer1; private System.Windows.Forms.Label label8; private System.Windows.Forms.TabPage tabPage4; diff --git a/Cs_HMI/Project/fSetup.cs b/Cs_HMI/Project/fSetup.cs index 0381f58..f2f5d0b 100644 --- a/Cs_HMI/Project/fSetup.cs +++ b/Cs_HMI/Project/fSetup.cs @@ -53,12 +53,12 @@ namespace Project //통신값 표시 //tbPortBMS.Text = Pub.setting.Port_BMS; - tbPortPLC.Text = PUB.setting.Port_PLC; + ///tbPortPLC.Text = PUB.setting.Port_PLC; tbPortAGV.Text = PUB.setting.Port_AGV; tbPortXBE.Text = PUB.setting.Port_XBE; tbportBMS.Text = PUB.setting.Port_BAT; - tbBaudPLC.Text = PUB.setting.Baud_PLC.ToString(); + // tbBaudPLC.Text = PUB.setting.Baud_PLC.ToString(); tbBaudAGV.Text = PUB.setting.Baud_AGV.ToString(); tbBaudXBE.Text = PUB.setting.Baud_XBE.ToString(); tbBaudBAT.Text = PUB.setting.Baud_BAT.ToString(); @@ -66,7 +66,7 @@ namespace Project //valueSelect1.Value = Pub.setting.interval_bms; valIntervalXBE.Value = PUB.setting.interval_xbe; vcpidDS.Value = PUB.setting.ZSpeed; - valueSelect4.Value = PUB.setting.interval_iostate; + //valueSelect4.Value = PUB.setting.interval_iostate; valIntervalBMS.Value = PUB.setting.interval_bms; tbChargerID.Value = PUB.setting.ChargerID; @@ -221,13 +221,13 @@ namespace Project //통신정보저장 // Pub.setting.Port_BMS = tbPortBMS.Text; PUB.setting.Port_XBE = tbPortXBE.Text; - PUB.setting.Port_PLC = tbPortPLC.Text; + //PUB.setting.Port_PLC = tbPortPLC.Text; PUB.setting.Port_AGV = tbPortAGV.Text; PUB.setting.Port_BAT = tbportBMS.Text; // Pub.setting.Baud_bms = int.Parse(tbBaudBms.Text); PUB.setting.Baud_XBE = int.Parse(tbBaudXBE.Text); - PUB.setting.Baud_PLC = int.Parse(tbBaudPLC.Text); + //PUB.setting.Baud_PLC = int.Parse(tbBaudPLC.Text); PUB.setting.Baud_AGV = int.Parse(tbBaudAGV.Text); PUB.setting.Baud_BAT = int.Parse(tbBaudBAT.Text); @@ -237,7 +237,7 @@ namespace Project PUB.setting.interval_bms = (int)valIntervalBMS.Value; PUB.setting.interval_xbe = (float)valIntervalXBE.Value; PUB.setting.ZSpeed = (byte)vcpidDS.Value; - PUB.setting.interval_iostate = (byte)valueSelect4.Value; + //PUB.setting.interval_iostate = (byte)valueSelect4.Value; PUB.setting.chargerpos = this.cmbChargerPos.SelectedIndex; PUB.setting.AutoModeOffAndClearPosition = this.chkClearPos.Checked; //PUB.setting.MotorUpTime = (byte)valueSelect5.Value; @@ -487,7 +487,7 @@ namespace Project if (tagStr == "XBE") tbPortXBE.Text = newPort; else if (tagStr == "AGV") tbPortAGV.Text = newPort; - else if (tagStr == "PLC") tbPortPLC.Text = newPort; + // else if (tagStr == "PLC") tbPortPLC.Text = newPort; else if (tagStr == "BAT") tbportBMS.Text = newPort; } @@ -551,14 +551,14 @@ namespace Project if (this.tbPortAGV.Text == "COM21") { this.tbPortAGV.Text = "COM11"; - this.tbPortPLC.Text = "COM6"; + // this.tbPortPLC.Text = "COM6"; this.tbportBMS.Text = "COM15"; this.tbPortXBE.Text = "COM18"; } else { this.tbPortAGV.Text = "COM21"; - this.tbPortPLC.Text = "COM31"; + // this.tbPortPLC.Text = "COM31"; this.tbportBMS.Text = "COM41"; this.tbPortXBE.Text = "COM51"; } diff --git a/Cs_HMI/SubProject/AGV/Command.cs b/Cs_HMI/SubProject/AGV/Command.cs index c94ef1c..1115b06 100644 --- a/Cs_HMI/SubProject/AGV/Command.cs +++ b/Cs_HMI/SubProject/AGV/Command.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using System.Collections; using COMM; using System.Security.Cryptography.X509Certificates; +using AR; namespace arDev { @@ -41,7 +42,6 @@ namespace arDev else cmd += item.ToString()[0]; cmd += speed.ToString("0000"); return AddCommand(cmd); - } public bool AGVMoveStop(string Reason, eStopOpt opt = eStopOpt.Stop) { @@ -236,6 +236,11 @@ namespace arDev retval = AddCommand(cmdString); break; + case eAgvCmd.CPUReset: + cmdString = "CRS0000"; + retval = AddCommand(cmdString); + break; + } return retval; } diff --git a/Cs_HMI/SubProject/AGV/EnumData.cs b/Cs_HMI/SubProject/AGV/EnumData.cs index 4d9dd50..2f0fcd5 100644 --- a/Cs_HMI/SubProject/AGV/EnumData.cs +++ b/Cs_HMI/SubProject/AGV/EnumData.cs @@ -173,6 +173,8 @@ namespace arDev /// SRS /// SetSpeed, + + CPUReset, } public enum eForm { diff --git a/Cs_HMI/SubProject/AGV/NARUMI.csproj b/Cs_HMI/SubProject/AGV/NARUMI.csproj index 4398b20..407d24e 100644 --- a/Cs_HMI/SubProject/AGV/NARUMI.csproj +++ b/Cs_HMI/SubProject/AGV/NARUMI.csproj @@ -59,6 +59,10 @@ {14e8c9a5-013e-49ba-b435-efefc77dd623} CommData + + {14e8c9a5-013e-49ba-b435-ffffff7dd623} + arCommUtil + \ No newline at end of file diff --git a/Cs_HMI/SubProject/AGV/Narumi.cs b/Cs_HMI/SubProject/AGV/Narumi.cs index a7604f3..972d7b9 100644 --- a/Cs_HMI/SubProject/AGV/Narumi.cs +++ b/Cs_HMI/SubProject/AGV/Narumi.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using System.Collections; using COMM; using System.Security.Cryptography.X509Certificates; +using AR; namespace arDev { @@ -61,7 +62,7 @@ namespace arDev Errlog = new Queue(); MinRecvLength = 4; - COMM.VAR.Init(128); + VAR.Init(128); } diff --git a/Cs_HMI/SubProject/AGV/Structure/Signals.cs b/Cs_HMI/SubProject/AGV/Structure/Signals.cs index 42677cb..869e446 100644 --- a/Cs_HMI/SubProject/AGV/Structure/Signals.cs +++ b/Cs_HMI/SubProject/AGV/Structure/Signals.cs @@ -26,6 +26,13 @@ namespace arDev front_right_sensor, front_center_sensor, charger_align_sensor, + + lift_up, + lift_down, + magnet_on, + + cart_detect1, + cart_detect2, } public bool GetValue(eflag idx) @@ -46,6 +53,11 @@ namespace arDev public Boolean front_right_sensor { get { return GetValue(eflag.front_right_sensor); } } public Boolean front_center_sensor { get { return GetValue(eflag.front_center_sensor); } } public Boolean charger_align_sensor { get { return GetValue(eflag.charger_align_sensor); } } + public Boolean lift_up { get { return GetValue(eflag.lift_up); } } + public Boolean lift_down { get { return GetValue(eflag.lift_down); } } + public Boolean magnet_on { get { return GetValue(eflag.magnet_on); } } + public Boolean cart_detect1 { get { return GetValue(eflag.cart_detect1); } } + public Boolean cart_detect2 { get { return GetValue(eflag.cart_detect2); } } public override string ToString() { //모든사태값을 탭으로 구분하여 문자를 생성한다 diff --git a/Cs_HMI/SubProject/CommData/Enum.cs b/Cs_HMI/SubProject/CommData/Enum.cs index 295b01a..9599ce0 100644 --- a/Cs_HMI/SubProject/CommData/Enum.cs +++ b/Cs_HMI/SubProject/CommData/Enum.cs @@ -135,10 +135,7 @@ namespace COMM public enum eVarTime { - LastConnTry_PLC, - LastConn_PLC, - LastRecv_PLC, - + LastConnTry_XBE, LastConn_XBE, LastRecv_XBE, diff --git a/Cs_HMI/SubProject/CommData/Var.cs b/Cs_HMI/SubProject/CommData/Var.cs index 92f638a..7b0bec8 100644 --- a/Cs_HMI/SubProject/CommData/Var.cs +++ b/Cs_HMI/SubProject/CommData/Var.cs @@ -1,340 +1,340 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; +//using System; +//using System.Collections.Generic; +//using System.ComponentModel; +//using System.Linq; +//using System.Text; -namespace COMM -{ - public abstract class VarData : INotifyPropertyChanged - { - protected T[] _values; - protected T defaultvalue; - protected string[] _code; - protected string[] _desc; +//namespace COMM +//{ +// public abstract class VarData : INotifyPropertyChanged +// { +// protected T[] _values; +// protected T defaultvalue; +// protected string[] _code; +// protected string[] _desc; - public event PropertyChangedEventHandler PropertyChanged; +// public event PropertyChangedEventHandler PropertyChanged; - protected void OnPropertyChanged(string name) - { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); - } +// protected void OnPropertyChanged(string name) +// { +// PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); +// } - public T this[int idx] - { - get { return Get(idx); } - set { Set(idx, value); } - } +// public T this[int idx] +// { +// get { return Get(idx); } +// set { Set(idx, value); } +// } - public string StrType - { - get - { - return typeof(T).ToString(); - } - } - public VarData(int capa, T defvalue = default(T)) - { - _values = new T[capa]; - _code = new string[capa]; - _desc = new string[capa]; +// public string StrType +// { +// get +// { +// return typeof(T).ToString(); +// } +// } +// public VarData(int capa, T defvalue = default(T)) +// { +// _values = new T[capa]; +// _code = new string[capa]; +// _desc = new string[capa]; - defaultvalue = defvalue; - Clear(); +// defaultvalue = defvalue; +// Clear(); - if (typeof(T) == typeof(UInt16)) SupportAdd = true; - else if (typeof(T) == typeof(UInt32)) SupportAdd = true; - else if (typeof(T) == typeof(Int16)) SupportAdd = true; - else if (typeof(T) == typeof(Int32)) SupportAdd = true; - else if (typeof(T) == typeof(Int64)) SupportAdd = true; - else if (typeof(T) == typeof(UInt64)) SupportAdd = true; - else if (typeof(T) == typeof(byte)) SupportAdd = true; - else if (typeof(T) == typeof(double)) SupportAdd = true; - else if (typeof(T) == typeof(Single)) SupportAdd = true; - else if (typeof(T) == typeof(string)) SupportAdd = false; - else if (typeof(T) == typeof(bool)) SupportAdd = false; - else if (typeof(T) == typeof(DateTime)) SupportAdd = false; - else throw new Exception($"Support Data Type : {typeof(T)}"); - } +// if (typeof(T) == typeof(UInt16)) SupportAdd = true; +// else if (typeof(T) == typeof(UInt32)) SupportAdd = true; +// else if (typeof(T) == typeof(Int16)) SupportAdd = true; +// else if (typeof(T) == typeof(Int32)) SupportAdd = true; +// else if (typeof(T) == typeof(Int64)) SupportAdd = true; +// else if (typeof(T) == typeof(UInt64)) SupportAdd = true; +// else if (typeof(T) == typeof(byte)) SupportAdd = true; +// else if (typeof(T) == typeof(double)) SupportAdd = true; +// else if (typeof(T) == typeof(Single)) SupportAdd = true; +// else if (typeof(T) == typeof(string)) SupportAdd = false; +// else if (typeof(T) == typeof(bool)) SupportAdd = false; +// else if (typeof(T) == typeof(DateTime)) SupportAdd = false; +// else throw new Exception($"Support Data Type : {typeof(T)}"); +// } - public virtual void Set(int idx, T value) - { - var changed = _values[idx].Equals(value); - _values[idx] = value; - if (changed) OnPropertyChanged($"{idx}|{value}"); //idx값을 알림한다 - } - public virtual T Get(int idx) - { - return _values[idx]; - } +// public virtual void Set(int idx, T value) +// { +// var changed = _values[idx].Equals(value); +// _values[idx] = value; +// if (changed) OnPropertyChanged($"{idx}|{value}"); //idx값을 알림한다 +// } +// public virtual T Get(int idx) +// { +// return _values[idx]; +// } - public virtual void Clear(T value) - { - for (int i = 0; i < _values.Length; i++) - _values[i] = value; - } - public virtual void Clear() - { - Clear(defaultvalue); - } - public void Clear(int idx) - { - _values[idx] = defaultvalue; - } - public Tuple GetCodeDesc(int idx) - { - return new Tuple(_code[idx], _desc[idx]); - } - public virtual bool SupportAdd { get; private set; } - } +// public virtual void Clear(T value) +// { +// for (int i = 0; i < _values.Length; i++) +// _values[i] = value; +// } +// public virtual void Clear() +// { +// Clear(defaultvalue); +// } +// public void Clear(int idx) +// { +// _values[idx] = defaultvalue; +// } +// public Tuple GetCodeDesc(int idx) +// { +// return new Tuple(_code[idx], _desc[idx]); +// } +// public virtual bool SupportAdd { get; private set; } +// } - public abstract class VarDataNumber : VarData - { - public VarDataNumber(int capa) : base(capa) { } +// public abstract class VarDataNumber : VarData +// { +// public VarDataNumber(int capa) : base(capa) { } - public abstract void Add(T value); - public abstract void Add(int idx, T value); - } +// public abstract void Add(T value); +// public abstract void Add(int idx, T value); +// } - public class VarDataI32 : VarDataNumber - { - public VarDataI32(int capa) : base(capa) { } +// public class VarDataI32 : VarDataNumber +// { +// public VarDataI32(int capa) : base(capa) { } - public override void Add(Int32 value) - { - for (int i = 0; i < _values.Length; i++) - _values[i] += value; - } +// public override void Add(Int32 value) +// { +// for (int i = 0; i < _values.Length; i++) +// _values[i] += value; +// } - public override void Add(int idx, Int32 value) - { - _values[idx] += value; - } - public void Add(eVarInt32 idx, Int32 value = 1) - { - Add((int)idx, value); - } - public void Clear(eVarInt32 idx) - { - Clear((int)idx); - } - public Int32 this[eVarInt32 idx] - { - get { return Get((int)idx); } - set { Set((int)idx, value); } - } +// public override void Add(int idx, Int32 value) +// { +// _values[idx] += value; +// } +// public void Add(eVarInt32 idx, Int32 value = 1) +// { +// Add((int)idx, value); +// } +// public void Clear(eVarInt32 idx) +// { +// Clear((int)idx); +// } +// public Int32 this[eVarInt32 idx] +// { +// get { return Get((int)idx); } +// set { Set((int)idx, value); } +// } - } - public class VarDataDBL : VarDataNumber - { - public VarDataDBL(int capa) : base(capa) { } +// } +// public class VarDataDBL : VarDataNumber +// { +// public VarDataDBL(int capa) : base(capa) { } - public override void Add(double value) - { - for (int i = 0; i < _values.Length; i++) - _values[i] += value; - } +// public override void Add(double value) +// { +// for (int i = 0; i < _values.Length; i++) +// _values[i] += value; +// } - public override void Add(int idx, double value) - { - _values[idx] += value; - } - public void Add(eVarDBL idx, double value = 1) - { - Add((int)idx, value); - } - public void Clear(eVarDBL idx) - { - Clear((int)idx); - } - public double this[eVarDBL idx] - { - get { return Get((int)idx); } - set { Set((int)idx, value); } - } - } - public class VarDataUI32 : VarDataNumber - { - public VarDataUI32(int capa) : base(capa) { } +// public override void Add(int idx, double value) +// { +// _values[idx] += value; +// } +// public void Add(eVarDBL idx, double value = 1) +// { +// Add((int)idx, value); +// } +// public void Clear(eVarDBL idx) +// { +// Clear((int)idx); +// } +// public double this[eVarDBL idx] +// { +// get { return Get((int)idx); } +// set { Set((int)idx, value); } +// } +// } +// public class VarDataUI32 : VarDataNumber +// { +// public VarDataUI32(int capa) : base(capa) { } - public override void Add(UInt32 value) - { - for (int i = 0; i < _values.Length; i++) - _values[i] += value; - } +// public override void Add(UInt32 value) +// { +// for (int i = 0; i < _values.Length; i++) +// _values[i] += value; +// } - public override void Add(int idx, UInt32 value) - { - _values[idx] += value; - } - public void Add(eVarUInt32 idx, UInt32 value = 1) - { - Add((int)idx, value); - } - public void Clear(eVarUInt32 idx) - { - Clear((int)idx); - } - public UInt32 this[eVarUInt32 idx] - { - get { return Get((int)idx); } - set { Set((int)idx, value); } - } - } +// public override void Add(int idx, UInt32 value) +// { +// _values[idx] += value; +// } +// public void Add(eVarUInt32 idx, UInt32 value = 1) +// { +// Add((int)idx, value); +// } +// public void Clear(eVarUInt32 idx) +// { +// Clear((int)idx); +// } +// public UInt32 this[eVarUInt32 idx] +// { +// get { return Get((int)idx); } +// set { Set((int)idx, value); } +// } +// } - public class VarDataByte : VarDataNumber - { - public VarDataByte(int capa) : base(capa) { } +// public class VarDataByte : VarDataNumber +// { +// public VarDataByte(int capa) : base(capa) { } - public override void Add(byte value) - { - for (int i = 0; i < _values.Length; i++) - _values[i] += value; - } - public override void Add(int idx, byte value) - { - _values[idx] += value; - } - public void Add(eVarByte idx, byte value) - { - Add((int)idx, value); - } - public byte this[eVarByte idx] - { - get - { - return Get((int)idx); - } - set - { - Set((int)idx, value); - } - } - } +// public override void Add(byte value) +// { +// for (int i = 0; i < _values.Length; i++) +// _values[i] += value; +// } +// public override void Add(int idx, byte value) +// { +// _values[idx] += value; +// } +// public void Add(eVarByte idx, byte value) +// { +// Add((int)idx, value); +// } +// public byte this[eVarByte idx] +// { +// get +// { +// return Get((int)idx); +// } +// set +// { +// Set((int)idx, value); +// } +// } +// } - public class VarDataBool : VarData - { - public VarDataBool(int capa) : base(capa) { } +// public class VarDataBool : VarData +// { +// public VarDataBool(int capa) : base(capa) { } - public bool this[eVarBool idx] - { - get - { - return Get(idx); - } - set - { - Set(idx, value); - } - } - public bool Get(eVarBool idx) - { - return Get((int)idx); - } - public void Set(eVarBool idx, bool value) - { - Set((int)idx, value); - } - } +// public bool this[eVarBool idx] +// { +// get +// { +// return Get(idx); +// } +// set +// { +// Set(idx, value); +// } +// } +// public bool Get(eVarBool idx) +// { +// return Get((int)idx); +// } +// public void Set(eVarBool idx, bool value) +// { +// Set((int)idx, value); +// } +// } - public class VarDataStr : VarData - { - public VarDataStr(int capa) : base(capa, string.Empty) { } - public string Get(eVarString idx) - { - return Get((int)idx); - } - public void Set(eVarString idx, string value) - { - Set((int)idx, value); - } - public string this[eVarString idx] - { - get { return Get(idx); } - set { Set(idx, value); } - } - } - public class VarDataDateTime : VarData - { - public VarDataDateTime(int capa) : base(capa, new DateTime(1982, 11, 23)) { } +// public class VarDataStr : VarData +// { +// public VarDataStr(int capa) : base(capa, string.Empty) { } +// public string Get(eVarString idx) +// { +// return Get((int)idx); +// } +// public void Set(eVarString idx, string value) +// { +// Set((int)idx, value); +// } +// public string this[eVarString idx] +// { +// get { return Get(idx); } +// set { Set(idx, value); } +// } +// } +// public class VarDataDateTime : VarData +// { +// public VarDataDateTime(int capa) : base(capa, new DateTime(1982, 11, 23)) { } - public DateTime this[eVarTime idx] - { - get - { - return Get((int)idx); - } - set - { - Set(idx, value); - } - } +// public DateTime this[eVarTime idx] +// { +// get +// { +// return Get((int)idx); +// } +// set +// { +// Set(idx, value); +// } +// } - public TimeSpan RUN(int idx) - { - return DateTime.Now - _values[idx]; - } - public TimeSpan RUN(eVarTime idx) - { - return RUN((int)idx); - } - [Browsable(false)] - public void Add(int idx, TimeSpan value) - { - _values[idx] += value; - } +// public TimeSpan RUN(int idx) +// { +// return DateTime.Now - _values[idx]; +// } +// public TimeSpan RUN(eVarTime idx) +// { +// return RUN((int)idx); +// } +// [Browsable(false)] +// public void Add(int idx, TimeSpan value) +// { +// _values[idx] += value; +// } - public void Add(eVarTime idx, TimeSpan value) - { - Add((int)idx, value); - } - /// - /// 지정된 시간으로 업데이트 합니다 - /// - /// - /// - public void Set(eVarTime idx, DateTime value) - { - Set((int)idx, value); - } - /// - /// 현재시간으로 업데이트 합니다 - /// - /// - public void Set(eVarTime idx) - { - Set(idx, DateTime.Now); - } - public bool IsSet(eVarTime idx) - { - return this[idx].Year != 1982; - } - } - //공용변수(시간) - public static class VAR - { - public static VarDataBool BOOL; - public static VarDataByte BYTE; - public static VarDataStr STR; - public static VarDataDateTime TIME; - public static VarDataI32 I32; - public static VarDataUI32 U32; - public static VarDataDBL DBL; +// public void Add(eVarTime idx, TimeSpan value) +// { +// Add((int)idx, value); +// } +// /// +// /// 지정된 시간으로 업데이트 합니다 +// /// +// /// +// /// +// public void Set(eVarTime idx, DateTime value) +// { +// Set((int)idx, value); +// } +// /// +// /// 현재시간으로 업데이트 합니다 +// /// +// /// +// public void Set(eVarTime idx) +// { +// Set(idx, DateTime.Now); +// } +// public bool IsSet(eVarTime idx) +// { +// return this[idx].Year != 1982; +// } +// } +// //공용변수(시간) +// public static class VAR +// { +// public static VarDataBool BOOL; +// public static VarDataByte BYTE; +// public static VarDataStr STR; +// public static VarDataDateTime TIME; +// public static VarDataI32 I32; +// public static VarDataUI32 U32; +// public static VarDataDBL DBL; - public static bool isInit { get; private set; } = false; +// public static bool isInit { get; private set; } = false; - public static void Init(int varlen) - { - if (isInit) return; //already init - //가변 데이트타임변수 - BOOL = new VarDataBool(varlen); - BYTE = new VarDataByte(varlen); - STR = new VarDataStr(varlen); - TIME = new VarDataDateTime(varlen); - I32 = new VarDataI32(varlen); - U32 = new VarDataUI32(varlen); - DBL = new VarDataDBL(varlen); - isInit = true; - } - } -} +// public static void Init(int varlen) +// { +// if (isInit) return; //already init +// //가변 데이트타임변수 +// BOOL = new VarDataBool(varlen); +// BYTE = new VarDataByte(varlen); +// STR = new VarDataStr(varlen); +// TIME = new VarDataDateTime(varlen); +// I32 = new VarDataI32(varlen); +// U32 = new VarDataUI32(varlen); +// DBL = new VarDataDBL(varlen); +// isInit = true; +// } +// } +//} diff --git a/Cs_HMI/SubProject/ProPLC/FakePLC.cs b/Cs_HMI/SubProject/ProPLC/FakePLC.cs index eb98a61..b125593 100644 --- a/Cs_HMI/SubProject/ProPLC/FakePLC.cs +++ b/Cs_HMI/SubProject/ProPLC/FakePLC.cs @@ -6,6 +6,8 @@ using System.Threading; using System.Threading.Tasks; using arDev.Arduino; using COMM; +using AR; + namespace arDev { @@ -17,7 +19,7 @@ namespace arDev public FakePLC() { - COMM.VAR.Init(128); + VAR.Init(128); } ~FakePLC() @@ -198,12 +200,12 @@ namespace arDev } public Boolean GetFlag(int flag) { - return COMM.VAR.BOOL[flag]; + return VAR.BOOL[flag]; } public Boolean GetFlag(COMM.eVarBool flag) { - return COMM.VAR.BOOL[(int)flag]; + return VAR.BOOL[(int)flag]; } public Boolean SetFlag(byte idx, Boolean value)