From f96a5544b5ae11350b6b43c4b2489ec8ae462843 Mon Sep 17 00:00:00 2001 From: Changwoo Park Date: Tue, 9 May 2023 19:00:10 +0900 Subject: [PATCH] =?UTF-8?q?[TCPIP]=20[AI]=20-=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC=20-TCPIP=20=20=20=E3=84=B4=20AI=20=EB=B0=8F?= =?UTF-8?q?=20AO::0000,FFFF=20=EB=93=B1=20=EB=AA=85=EB=A0=B9=20=EC=88=98?= =?UTF-8?q?=ED=96=89=20=EA=B0=80=EB=8A=A5=20=20=20=E3=84=B4=20Labview=20Te?= =?UTF-8?q?st=20=ED=8C=8C=EC=9D=BC=20-=20=EC=98=88=EC=A0=9C=EC=86=8C?= =?UTF-8?q?=EC=8A=A4=20(MCP4922)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FC_InferfaceBoard/FC_InferfaceBoard.ino | 187 +++++++++++++++++++----- FC_InferfaceBoard/Processes.ino | 24 +++ FC_InferfaceBoard/TCPIP - Write Read.vi | Bin 0 -> 21570 bytes FC_InferfaceBoard/Utils.ino | 36 +++++ libraries/Scitech/SC_AI.cpp | 10 +- test/mcp4922/mcp4922.ino | 47 ++++++ 6 files changed, 261 insertions(+), 43 deletions(-) create mode 100644 FC_InferfaceBoard/Processes.ino create mode 100644 FC_InferfaceBoard/TCPIP - Write Read.vi create mode 100644 FC_InferfaceBoard/Utils.ino create mode 100644 test/mcp4922/mcp4922.ino diff --git a/FC_InferfaceBoard/FC_InferfaceBoard.ino b/FC_InferfaceBoard/FC_InferfaceBoard.ino index 08c503f..15f6ff5 100644 --- a/FC_InferfaceBoard/FC_InferfaceBoard.ino +++ b/FC_InferfaceBoard/FC_InferfaceBoard.ino @@ -6,23 +6,38 @@ #include "SC_AI.h" // Differential analog input collector #include "SC_MC9.h" // MC9 Tempreture Controller +#define RcvOK "OK\r\n" +#define RcvErr "ER\r\n" +#define MODE_DEBUG false + // Enter a MAC address and IP address for your controller below. // The IP address will be dependent on your local network. // gateway and subnet are optional: -byte mac[] = { - 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x00 }; +byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x00 }; IPAddress ip(192, 168, 20, 177); IPAddress gateway(192, 168, 20, 1); IPAddress subnet(255, 255, 255, 0); -// telnet defaults to port 23 -EthernetServer server(23); -boolean alreadyConnected = false; // whether or not the client was connected previously +// SCPI defaults to port 5025 +EthernetServer server(5025); +EthernetClient client; + +// HTTP defaults to port 5025 +EthernetServer web(80); + +unsigned long lastDataReceivedTime; +unsigned long timeoutPeriod = 5000; // 타임아웃 시간 (5초) + +bool busy = false; +bool connection = false; +char buffer[1024]; -int Size_AI = 8; +int Size_AI = 16; int AI_VALUES[] = { - 0, 0, 0, 0, 0, 0, 0, 0 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +int msCnt = 0; +unsigned long timer = 0; void setup() { // put your setup code here, to run once: @@ -35,14 +50,12 @@ void setup() { SC_AI_setup(); SC_MC9_setup(); - - // - MsTimer2::set(50, AnalogIn); - MsTimer2::set(1000, AnalogIn_Print); + // Timer set + MsTimer2::set(10, periodic_10ms); MsTimer2::start(); // Report address - Serial.print("MAC:"); + Serial.print("MAC>>"); for (int i = 0; i < 6; i++) { if (mac[i] < 16) { Serial.print("0"); @@ -53,37 +66,81 @@ void setup() { } } Serial.println(); - Serial.print("IP:"); + Serial.print("IP >>"); Serial.println(Ethernet.localIP()); - - } void loop() { // wait for a new client: - EthernetClient client = server.available(); - //SC_AI(AI_VALUES, Size_AI); - // check if client is connected + + webReponse(); + client = server.available(); + + if (client) { + // check if client is connected + Serial.println("Client Connected!!!"); + + // Do What Message Command + while(client.connected()){ + + int buffCnt = 0; + + // check for command byte + if (client.available() > 0) { + char c; + + String command; + String cmd; + unsigned int data[32]; + int dataSize; + + busy = true; + // Read message by byte + while ((c = client.read())) { + // Read data until LF or CR + if((c != 10) && (c != 13)){ + command += c; + }else{ + break; + } + } + + cmd = demuxCMD(command, data, &dataSize); + + if(cmd=="AI"){ + client.print(Prcss_AI()); + }else if(cmd=="AO"){ + client.print(Prcss_AO(data, dataSize)); + }else{ + client.print(RcvErr); + } + + + // Debug + if(MODE_DEBUG){ + //Serial.print("Received command: "); + //Serial.println(command); + } + + busy = false; + // 데이터를 수신했으므로 타임아웃 타이머 초기화 + lastDataReceivedTime = millis(); + + }// if end, client.available() + //Serial.println("end client available"); + + // 타임아웃 확인 + if (millis() - lastDataReceivedTime > timeoutPeriod) { + Serial.println("Client Disconnected... (Timeout)"); + client.stop(); + } - // check for command byte - if (client.available() > 0) { - cli();//stop interrupts - Serial.print(" "); - byte command = client.read(); - if (command == 'A'){ - client.print("AI"); - SC_MC9_read(AI_VALUES, Size_AI); - } - if (command == 'B'){ - client.print("AO"); - SC_MC9_write(AI_VALUES, Size_AI); - } - sei();//allow interrupts } - } - //delay(50); + Serial.println("Client Disconnected..."); + + } } @@ -94,17 +151,69 @@ void TCPIP_setup(byte mac[], IPAddress ip, IPAddress gateway, IPAddress subnet){ Ethernet.begin(mac, ip, gateway, subnet); // start listening for clients server.begin(); + web.begin(); } -void AnalogIn(){ - SC_AI(AI_VALUES, Size_AI); +void periodic_10ms(){ + + + msCnt += 10; + if(!busy){ + + SC_AI(AI_VALUES, Size_AI); + + // periodic_1s + if (msCnt > 1000){ + msCnt = 0; + periodic_1s(); + } + } + } -void AnalogIn_Print(){ +void periodic_1s(){ - for (int i = 0; i < 8; i++) { + //AnalogIn_Print(); +} + + +void AnalogIn_Print(){ + for (int i = 0; i < Size_AI; i++) { Serial.print(AI_VALUES[i]); - + Serial.print("\t"); } Serial.println(); +} + + + +void webReponse(){ + EthernetClient webClient = web.available(); + if (webClient) { + Serial.println("Web client connected"); + while (webClient.connected()) { + if (webClient.available()) { + // 웹 브라우저에서 요청이 도착한 경우 + String request = webClient.readStringUntil('\r'); + //Serial.println(request); + webClient.flush(); + + // 웹 브라우저에 출력할 문구 작성 + String response = "HTTP/1.1 200 OK\r\n"; + response += "Content-Type: text/html\r\n\r\n"; + response += ""; + response += Prcss_AI(); + //response += "

Hello, World!

"; + response += ""; + + // 문구를 웹 브라우저로 전송 + webClient.print(response); + delay(1); + + // 클라이언트 연결 종료 + webClient.stop(); + } + } + } + } \ No newline at end of file diff --git a/FC_InferfaceBoard/Processes.ino b/FC_InferfaceBoard/Processes.ino new file mode 100644 index 0000000..a87dde4 --- /dev/null +++ b/FC_InferfaceBoard/Processes.ino @@ -0,0 +1,24 @@ +String Prcss_AI(){ + + String str = ""; + for (int i = 0; i < Size_AI; i++) { + char formattedNumber[5]; // 4자리 숫자 + 널 종료 문자 + sprintf(formattedNumber, "%04X", AI_VALUES[i]); // 4자리로 고정된 형식의 문자열 생성 + str += formattedNumber; // 형식화된 문자열 추가 + //str += String(AI_VALUES[i]); + str += ','; + } + + str += RcvOK; + return str; +} + +String Prcss_AO(unsigned int data[], int dataSize){ + String str = ""; + for(int i=0 ; i#Uol05N+dH_f;@PWDm5~T81n)rgeBy=V&TN2?5 z%ecFq^)JsXG^a zuO^=%<`($9oIVW~42z5xL1J(qSYl8*&@~;v_t5ScL5Z?f zUzG5JTa4p-DbfsT=P|x8HL|-ls?$=+U|?X-KFurFs(tbF8Q!h$^YFX&CfO7woeQyR zjJ?y#Apd?Xb|DlwKZ6N%o>~4UZLl`MQ3AycJ=#afV%_s zY!h<05B8z8!zfLz8E9t(`$QY4?`Zp=+1#x1t=t^Wvi9nwfkxCNK(uFzAgsS7iV`; zS~7R3Vrzb#j*zEg?9f~#|L~&RH^iW=KI8?4M6^P9e;pD2#)xCoz(fx-+c>5W)K@|+ zb6zp(r^9uj7~|PE(<)<0n`)zOBmqwy82f0})8fytr%tAO;BB-V=IR|}-f7Lm+qG7W zj|IeY^^IC4SYu$@{5qgdCt3`qa1GlINttubJ&874vuI3XacD^+?Wex+~dabk<-(ZK^ zq^MlPAD@G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Gg5N1bC+Q{S&eOQpF_%EBV*udLMKW)O&h>HKR2`iv3 zt*Y`l->QqL{yZ;ijfAR*=uf`q5Bc{a zL&;O%O3dW_4dae+dt~T)_-pcJ@6ZD?(g<6FaEBF z^=lk3f1MY*@uwdAzi_|$jPNhq;!i!qf8kDka!7x1I50oC`+a|ZU>yA4a4f&!e$LOo z`T$4sH+t@W=WxsZ&fz`yJBM%Z8!q-Y+%I4K%Q*0-{;o&xn{yB({$1};>TkHWzu_u= z!!`V!qig*Q_vf|z*L={e{#}p$7xgb=qeu8f{?(Qq|2G`z-#NaK-*CV2l@w$j?|u5~ v98!V5;Ua&-{l*8<0zdV9|FS2q3E^<={|`^fNUGsz32c{DHU%DcxLW=%_HD{- literal 0 HcmV?d00001 diff --git a/FC_InferfaceBoard/Utils.ino b/FC_InferfaceBoard/Utils.ino new file mode 100644 index 0000000..4ae6dbb --- /dev/null +++ b/FC_InferfaceBoard/Utils.ino @@ -0,0 +1,36 @@ +String demuxCMD(String command, unsigned int data[], int* dataSize) { + + command.replace(" ", ""); + + // "::"를 기준으로 문자열을 분리 + int separatorIndex = command.indexOf("::"); + String leftPart = command.substring(0, separatorIndex); + String rightPart = command.substring(separatorIndex + 2); + + // 우측의 16진수 배열을 분리하여 추출 + const char* delimiter = ","; + int startIndex = 0; + int endIndex = rightPart.indexOf(delimiter); + int index = 0; + + while (endIndex >= 0) { + String hexValue = rightPart.substring(startIndex, endIndex); + // 16진수 문자열을 16진수 숫자로 변환하여 data 배열에 저장 + data[index] = strtoul(hexValue.c_str(), NULL, 16); + index++; + + startIndex = endIndex + 1; + endIndex = rightPart.indexOf(delimiter, startIndex); + } + + // 남은 마지막 16진수 배열 원소 처리 + String hexValue = rightPart.substring(startIndex); + data[index] = strtoul(hexValue.c_str(), NULL, 16); + index++; + + // dataSize에 배열 크기 저장 + *dataSize = index; + + // 왼쪽 부분인 "ABC"을 반환 + return leftPart; +} diff --git a/libraries/Scitech/SC_AI.cpp b/libraries/Scitech/SC_AI.cpp index 8748ff1..e397b9c 100644 --- a/libraries/Scitech/SC_AI.cpp +++ b/libraries/Scitech/SC_AI.cpp @@ -7,19 +7,21 @@ #include #include - +int aipin[] = {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15}; void SC_AI_setup(){ } void SC_AI(int arr[], int size){ - cli();//stop interrupts + //cli();//stop interrupts int i = 0; for(i = 0 ; i < size ; i++){ - arr[i] = i; + arr[i] = analogRead(aipin[i]); } - sei();//allow interrupts + + + //sei();//allow interrupts } diff --git a/test/mcp4922/mcp4922.ino b/test/mcp4922/mcp4922.ino new file mode 100644 index 0000000..86dee48 --- /dev/null +++ b/test/mcp4922/mcp4922.ino @@ -0,0 +1,47 @@ +// MCP4922 Demo code sinewave at 16 res top to bot. +// For comparison to MCP4725 operation (DAC_RESOLUTION=-5). +#include + + + +SPISettings settingsA(16000000, MSBFIRST, SPI_MODE0); // At 16 = SPI Clock = 8MHz. + +int RCLKPin = 53; // pin 12 on the 74hc595 latch - nSS +int SRCLKPin = 52; // pin 11 on the 74hc595 shift register clock - SCK +int SERPin = 51; // MOSI + +////////////////////////////////////////////////////////////////////////////// +void setup() { + Serial.begin(115200); // Start serial port (debug). + + pinMode(RCLKPin, OUTPUT); // Set SPI control PINs to output. + pinMode(SRCLKPin, OUTPUT); + pinMode(SERPin, OUTPUT); + + SPI.begin(); + + Serial.println("MCP4922 SPI Dual DAC SPI hardware mode"); + noInterrupts(); +} + +////////////////////////////////////////////////////////////////////////////// +// 0 - A, 1 - B +// +void writeMCP4922_AB(byte AB, uint16_t v) { + + v |=0xf000; // B15(A/B)=1 B, B14(BUF)=1 on, B13(GAn) 1=x1 B12(SHDNn) 1=off + if (!AB) v &= ~0x8000; // When zero clear B15 for A. + + SPI.beginTransaction(settingsA); + digitalWrite(RCLKPin, LOW); + SPI.transfer( (0xff00 & v)>>8 ); + SPI.transfer( 0x00ff & v ); + digitalWrite(RCLKPin, HIGH); + SPI.endTransaction; +} + +void loop() { + writeMCP4922_AB( 0, 4092 ); + writeMCP4922_AB( 1, 3000 ); + +}