[TCPIP] [Timer]

- TCPIP
  ㄴ TCPIP는 Main Loop에서 동작
  ㄴ TCPIP 명령에 따른 수행 레이아웃 완료

- Timer
  ㄴ Serial print 동작하나 (1sec)
  ㄴ SC_AI 는 미동작 *원인 파악 필요

- 기타
  ㄴ 485 read & write 구현 완료
  ㄴ MC9 프로토콜 적용 필요
  ㄴ AI C/O 필요
main
Changwoo Park 2 years ago
parent 61851c6f5e
commit 5091ae49f7

@ -1,4 +1,23 @@
#include "Sc_AnalogIn.h" // Differential analog input collector #include <MsTimer2.h> // Timer
#include <Ethernet2.h>
#include <avr/wdt.h> // ??
#include "SC_AI.h" // Differential analog input collector
#include "SC_MC9.h" // MC9 Tempreture Controller
// 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 };
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
int Size_AI = 8; int Size_AI = 8;
int AI_VALUES[] = { int AI_VALUES[] = {
@ -9,19 +28,83 @@ void setup() {
// put your setup code here, to run once: // put your setup code here, to run once:
Serial.begin(9600); Serial.begin(9600);
Serial.println("Start!"); Serial.println("Start!");
TCPIP_setup(mac, ip, gateway, subnet);
// scitech korea Library
SC_AI_setup();
SC_MC9_setup();
//
MsTimer2::set(50, AnalogIn);
MsTimer2::set(1000, AnalogIn_Print);
MsTimer2::start();
// Report address
Serial.print("MAC:");
for (int i = 0; i < 6; i++) {
if (mac[i] < 16) {
Serial.print("0");
}
Serial.print(mac[i], HEX);
if (i < 5) {
Serial.print(":");
}
}
Serial.println();
Serial.print("IP:");
Serial.println(Ethernet.localIP());
} }
void loop() { void loop() {
// put your main code here, to run repeatedly: // wait for a new client:
int i = 0; EthernetClient client = server.available();
//SC_AI(AI_VALUES, Size_AI);
// check if client is connected
if (client) {
// 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);
}
void TCPIP_setup(byte mac[], IPAddress ip, IPAddress gateway, IPAddress subnet){
mac[5] = ip[3] & 0xFF;
// initialize the ethernet device
Ethernet.begin(mac, ip, gateway, subnet);
// start listening for clients
server.begin();
}
void AnalogIn(){
SC_AI(AI_VALUES, Size_AI);
}
AnalogIn(AI_VALUES, Size_AI); void AnalogIn_Print(){
for (i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
Serial.print(AI_VALUES[i]); Serial.print(AI_VALUES[i]);
// Serial.println(AnalogTest(3));
} }
Serial.println(""); Serial.println();
delay(1000);
} }

@ -0,0 +1,25 @@
/*
History:
20230504 - V0.2
20230504 - V0.1 init.
*/
#include <SC_AI.h>
#include <Arduino.h>
void SC_AI_setup(){
}
void SC_AI(int arr[], int size){
cli();//stop interrupts
int i = 0;
for(i = 0 ; i < size ; i++){
arr[i] = i;
}
sei();//allow interrupts
}

@ -0,0 +1,7 @@
#ifndef SC_AI_h
#define SC_AI_h
void SC_AI_setup();
void SC_AI(int arr[], int size);
#endif

@ -0,0 +1,32 @@
/*
History:
20230504 - V0.2
20230504 - V0.1 init.
*/
#include <SC_MC9.h>
#include <Arduino.h>
//#include <HardwareSerial.h>
void SC_MC9_setup(){
Serial1.begin(9600);
pinMode(RS485_OE_1, OUTPUT);
delay(10);
digitalWrite(RS485_OE_1, HIGH);
}
void SC_MC9_read(int arr[], int size){
cli();//stop interrupts
Serial1.print("485 Read!!"); //Serial Write ADC_Value to RS-485 Bus
sei();//allow interrupts
}
void SC_MC9_write(int arr[], int size){
cli();//stop interrupts
Serial1.print("485 Write^^"); //Serial Write ADC_Value to RS-485 Bus
sei();//allow interrupts
}

@ -0,0 +1,15 @@
#ifndef SC_MC9_h
#define SC_MC9_h
// Sample communication Code for RS 485 Shield with Arduino Mega 2560
#define RS485_OE_1 24 //RS485 CH#1 Output Enable => pin 24 for CH#1
#define RS485_OE_2 26 //RS485 CH#2 Output Enable => pin 26 for CH#2
#define Snd_485 HIGH
#define Rcv_485 LOW
void SC_MC9_setup();
void SC_MC9_read(int arr[], int size);
void SC_MC9_write(int arr[], int size);
#endif

@ -1,28 +0,0 @@
/*
MsTimer2.h - Using timer2 with 1ms resolution
Javier Valencia <javiervalencia80@gmail.com>
https://github.com/PaulStoffregen/MsTimer2
History:
20230504 - V0.2
20230504 - V0.1 init.
*/
#include <Sc_AnalogIn.h>
void AnalogIn(int arr[], int size){
cli();//stop interrupts
int i = 0;
for(i = 0 ; i < size ; i++){
arr[i] = i;
}
sei();//allow interrupts
}
int AnalogTest(int i){
return i+4;
}

@ -1,12 +0,0 @@
#ifndef Sc_AnalogIn_h
#define Sc_AnalogIn_h
void AnalogIn(int arr[], int size);
int AnalogTest(int i);
#endif
#ifdef __AVR__
#include <avr/interrupt.h>
#elif defined(__arm__) && defined(TEENSYDUINO)
#include <Arduino.h>
#endif
Loading…
Cancel
Save