Selasa, 29 September 2015

Porsea City



Porsea is beautifull and cold place. At map we can see porsea in north sumatra near Toba Lake. At porse is cold and it feel so cold in the night and the morninng. There are so cold because around of porsea is montains and there are so many daily activity  people is farmer, so when you go to porsea and see left and right so many paddy with big area, that’s make porsea is beautifull and cold. the other reason why porsea is beautifull and cold place, location porsea is 400 meter highest from sea surface, and porsea near to intersted place of north sumatra is Toba Lake. Around is montains, many paddy with big area, 400 meter highest from sea surface and near Toba Lake make porsea is beautifull and cold place.

Minggu, 14 Juni 2015

Praktikum -Komunikasi Ethernet menggunakan VB



 Praktikum - Komunikasi Ethernet

 Dasar Teori
 
Komunikasi Ethernet merupakan salah satu jenis komunikasi yang paling sering
ditemui saat ini. Penggunaannya juga beragam, bisa digunakan untuk komunikasi antar
PC, PC dengan mikrokontroller, PC dengan PLC, PLC dengan PLC dan sebagainya.
Komunikasi Ethernet dapat menggunakan media berupa kabel maupun nirkabel.
Media kabel yang digunakan biasanya berupa kabel UTP yang ditiap ujungnya terdapat
konektor RJ45, sedangkan yang nirkabel biasanya memanfaatkan router wireless. Untuk
mengenali tujuan pengiriman data, komunikasi ini menggunakan IP address dan port. IP
Address dianalogikan sebagai kompleks perumahan, dan port dianalogikan sebagai
nomor rumah. Jika IP Address dan port yang digunakan asal-asalan, maka paket data
yang dikirimkan juga tidak akan pernah sampai ke device tujuan.
Pada komunikasi Ethernet terdapat 2 jenis protocol pengiriman data, yaitu TCP dan
UDP. Kedua protocol tersebut memiliki kelebihan dan kekurangan masing-masing. Pada
praktikum kali ini, kita akan membuat sebuah aplikasi chatting teks sederhana
menggunakan protocol UDP.

Pertama kita buka aplikasi visual studio



Lalu kita buat form seperti ini :



ketiga,
Kita tambahkan library dengan ini :

using System.Net;
using System.Net.Sockets;
using System.Threading;


Library tersebut digunakan untuk mengakses thread, socket dan beberapa method
yang dibutuhkan untuk pembuatan aplikasi.

keempat,
Ini adalah codingannya :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;

namespace WindowsFormsApplication1
{
    public partial class chatform : Form
    {
        delegate void Addmessage(string message);
        //string username;
        //TcpClient topclient = new TcpClient();
        int port = 11000;
        const string broadcastAddress = "192.168.1.13";
        UdpClient receivingclient = new UdpClient(11000);
        UdpClient sendingclient;
        Thread receivingthread;

        public chatform()
        {
            InitializeComponent();
            this.Load += new EventHandler(chatform_Load);
            btnsend.Click += new EventHandler(btnsend_Click);
            //topclient.Connect("192.168.0.255",11000);
        }
       
        private void chatform_Load(object sender, EventArgs e)
        {
            textBoxtbsend.Focus();
            initializesender();
            initializeReceiver();

        }
        private void initializesender()
        {
            sendingclient = new UdpClient(broadcastAddress, port);
            sendingclient.EnableBroadcast = true;
        }

        private void initializeReceiver()
        {
            ThreadStart start = new ThreadStart (Receiver); //</p>
            receivingthread = new Thread(start); //</p>
            receivingthread .IsBackground  = true ;
            receivingthread.Start();

        }

        private void btnsend_Click(object sender, EventArgs e)
        {
            textBoxtbsend.Text = textBoxtbsend.Text.TrimEnd();
            if (!string.IsNullOrEmpty(textBoxtbsend.Text))
            {
                string tosend = "<" + Environment.MachineName + ">:" + textBoxtbsend.Text;
                byte[] data = Encoding.ASCII.GetBytes(tosend);
                sendingclient.Send(data, data.Length);
                textBoxtbsend.Text = "";

            }
            textBoxtbsend.Focus();

        }
        private void Receiver()
        {
            IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, port);
            Addmessage messagedelegate = messagereceived;
            while (true)
            {
                byte []  data = receivingclient .Receive (ref endpoint);
                string message = Encoding .ASCII .GetString (data);
                Invoke (messagedelegate ,message );
                System.Console.Beep (1500,300);

            }
        }
        private void messagereceived(string message)
        {
            richTextBoxrtbchat.Text += message + "/n";
        }
    }
}

Kelima
Compile dan amati

Keenam
Coba ganti IP addrass dan port yg digunakan

Ketujuh
Kompile dan amati lagi..

Terimakasih semoga bermanfaat J

Minggu, 31 Mei 2015

Transmiting Data (mematikan dan menghidupkan 3 lampu) menggunakan aplikasi Visual Studio

 Dasar Teori

Pengiriman data melalui serial port sangat sederhana, cukup
menggunakan method Write dengan parameter berupa string yang
ingin dikirim.

pertama buat desigen seperti ini :



lalu buat coding seperti ini :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;

namespace Kontrol_3_led
{
    public partial class Form1 : Form
    {
        Image biru = Properties.Resources.biru;
        Image putih = Properties.Resources.putih;

        public Form1()
        {
            InitializeComponent();
           
            pictureBox1.BackgroundImage = putih;
            pictureBox2.BackgroundImage = putih;
            pictureBox3.BackgroundImage = putih;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            serialPort1.Open();
            comboBox1.Items.Add("COM1");
        }

        private void on1_Click(object sender, EventArgs e)
        {
            try
            {
                serialPort1.Write("1");
                pictureBox1.BackgroundImage = biru;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);      
            }
        }

        private void off1_Click(object sender, EventArgs e)
        {
            try
            {
                serialPort1.Write("0");
                pictureBox1.BackgroundImage = putih;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void Exit_Click(object sender, EventArgs e)
        {
            serialPort1.Close();
            Application.Exit();
        }

        private void kirim_Click(object sender, EventArgs e)
        {
            serialPort1.Write(textBox1.Text);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (serialPort1.BytesToRead != 0)
            {
                textBox2.Text = serialPort1.ReadExisting();
            }
        }

        private void on2_Click(object sender, EventArgs e)
        {
            try
            {
                serialPort1.Write("2");
                pictureBox2.BackgroundImage = biru;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
              
            }
        }

        private void off2_Click(object sender, EventArgs e)
        {

            try
            {
                serialPort1.Write("3");
                pictureBox2.BackgroundImage = putih;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void on3_Click(object sender, EventArgs e)
        {
            try
            {
                serialPort1.Write("4");
                pictureBox3.BackgroundImage = biru;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

            }
        }

        private void off3_Click(object sender, EventArgs e)
        {
            try
            {
                serialPort1.Write("5");
                pictureBox3.BackgroundImage = putih;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
  }
}