@ -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 AI_VALUES [ ] = {
@ -9,19 +28,83 @@ void setup() {
// put your setup code here, to run once:
Serial . begin ( 9600 ) ;
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 ( ) {
// put your main code here, to run repeatedly:
int i = 0 ;
// wait for a new client:
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.println(AnalogTest(3));
}
Serial . println ( " " ) ;
delay ( 1000 ) ;
Serial . println ( ) ;
}