ATC-1000M test program

From DP

Jump to: navigation , search

Contents

About

ATC-1000M demonstration applications.

C# demo app

#if INTRODUCTION
 
By: Sevenstring
Demonstration of ATC1000M Module using C#'s
 
Version:
    00.08.00
        - First Release
 
#endif
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.IO;
using System.Threading;
 
namespace ATC1000MDemo
{
 
    class Program
    {
        const string APP_VER="E-Gizmo TCP/IP Shield Loopback Test using C# - 00.08.00";
 
        static void Main(string[] args)
        {
        string tempBuffer;
        ATC1000M myDevice=new ATC1000M();
 
        Console.WriteLine(APP_VER);
 
        Console.WriteLine("\n\nOpening 192.168.2.1 Port 23...");
        myDevice.Open("192.168.2.1",23);
        Console.WriteLine("Opened!");
 
 
        Console.WriteLine("I will just test if there is a string on the buffer...");
        tempBuffer=myDevice.ReadString();
        if(tempBuffer!=null)
            {
            Console.WriteLine("Received String from Buffer: \n{0}",tempBuffer);
            }
        else
            {
            Console.WriteLine("No String Received!");
            }
 
        Console.WriteLine("\n\nC# Now Sending a String... Please wait...\n\n");
        myDevice.Write("Hello World! This string sent through TCP/IP by C#!\nIt this is displayed, the test is successful! Congrats!");
        Thread.Sleep(1000);
 
        tempBuffer=myDevice.ReadString();
        if(tempBuffer!=null)
            {
            Console.WriteLine("Received String from Buffer! \n{0}",tempBuffer);
            }
        else
            {
            Console.WriteLine("No String Received!");
            }
 
        Console.WriteLine("\n\nClosing the connection and the streams...");
        myDevice.Close();
        Console.WriteLine("Closed!");
        }// end of static void Main(string[] args)
    }
 
    public class ATC1000M
    {
        TcpClient tcpclient=null;
        NetworkStream output;
        BinaryWriter writer;
        BinaryReader reader;
 
        public bool Open(string hostname,int port)
        {
        tcpclient=new TcpClient();
        tcpclient.Connect(hostname,port);
        output=tcpclient.GetStream();
        writer=new BinaryWriter(output);
        reader=new BinaryReader(output);
        reader.BaseStream.ReadTimeout=500;
        return tcpclient.Connected;     
        }
 
        public void Write(string data)
        {
        writer.Write(data);
        }
 
        public string ReadString()
        {
        string retString;
 
        try
            {
            retString=reader.ReadString();
            }
        catch(System.IO.IOException)
            {
            retString=null;
            }
        return retString;
        }
 
        public void Close()
        {
        writer.Dispose();
        reader.Dispose();
        output.Dispose();
        tcpclient.Close();
        }
    }//end of public class ATC1000M
 
}

Python demo app

'''
By: 7
Sample Loopback Program for TCP/IP to Serial Shield
'''
import socket,time
 
HOST = '192.168.2.1'
PORT = 23
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
try:
s.send('Hello, world')
time.sleep(.5)
data = s.recv(1024)
finally:
s.close()
 
print 'Received:', repr(data)

Arduino demo source

// By 7
// Version 00.08.00
#include <SoftwareSerial.h>
 
#define rxPin 0
#define txPin 1
 
SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);
byte pinState = 0;
 
void setup() {
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
pinMode(ledPin, OUTPUT);
mySerial.begin(9600);
mySerial.print("Hello! This is Gizduino!");
}
 
void loop() {
char c = mySerial.read();
mySerial.print((char)(c+1));
}