Busan IT/공장내 Network2015. 7. 13. 17:47

================================ Outline ====================================

Server/Client socket 프로그램 만들기

----------------------------------------------------------------------------

 

예약된 PORT 번호는 1 - 1,024이며 system에서 사용한다.

//가장 흔히 사용하는 webPORT #80이다.



일반적으로는 995까지는 시스템에서 사용한다. bind함수를 사용하여 socket정보를 엮을 때 1024내에 번호를 설정하면 오류가 난다.

 

 

사용 가능한 PORT 번호는 0 - 65,535까지이다.

 

make 명령어를 사용하여 컴파일이 가능하도록 만들어 보자.

 

vi편집기 기본 세팅문서로 들어간다.

 

# vi /home/newind2000/.vimrc

 

vi편집기의 기본세팅에 스페이스가 입력되는 설정을 주석처리 해주자. 주석처리는 로 해준다.

 

 

vi makefile을 입력하여 makefile을 만든다.

아래와 같이 편집한다.

//골뱅이(@)가 없으면 명령어인 echo test가 같이 출력 됨으로 골뱅이 표시를 넣어준다.

make를 치면 아래와 같이 출력된다.

 

 

 

이것을 적용하여,

 

server : server.c smartsock.h

gcc -lm -o server server.c

 

다음과 같이 명령어를 넣어주면 ‘make'만 쳐도 컴파일이 된다.

 

! 명령어(위에서는 ‘gcc') 이전에는 TAB키를 사용하여 띄워주어야 함을 명심하자.


/*** 소스 ***/



#include "smartsock.h"

int main(void)
{
    int iSock;   //소켓 함수의 반환 값을 받는 변수
    int iRet;
    struct sockaddr_in stAddr;

    iSock = socket(AF_INET, SOCK_STREAM, 0);    //AF_INET = 2, 
    if(0 > iSock)
    {
        perror("socket : ");
        return -1;
    }
    // stAddr구조체에 socket연결을 위한 필수 정보 입력  setting
    bzero(&stAddr, sizeof(stAddr));            //구조체 비우기(0으로 채우기)
    stAddr.sin_family = AF_INET;               //#define AF_INET 2 /* IP protocol family. */
    stAddr.sin_addr.s_addr = inet_addr(IP);    //IP와 PORT값은 헤더파일에 정의되어 있다.
    stAddr.sin_port = htons((PORT));

    iRet = bind(iSock, (struct sockaddr *)&stAddr,sizeof(stAddr));
    if(iRet < 0)
    {
        perror("bind : ");
        close(iSock);

        return -2;
    }

    close(iSock);
    return 0;
}


#ifndef __SMART_SOCKET_H__
#define __SMART_SOCKET_H__
#include <stdio.h>
#include <sys/types.h>          /* See NOTES */
#include <sys/socket.h>
#include <sys/stat.h>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <string.h>



#endif // __SMART_SOCKET_H__











 

 

 

 

 

 

반응형

'Busan IT > 공장내 Network' 카테고리의 다른 글

Echo Server/Client  (0) 2015.07.15
Echo Server, Echo Client(진행 중)  (0) 2015.07.14
소켓 연결  (0) 2015.07.07
네트워크 연결  (0) 2015.07.06
프로토콜 계층구조  (0) 2015.05.22
Posted by newind2000
Busan IT/모터제어2015. 7. 13. 13:24

================================ Outline ====================================

AX-12+ Baud Rate 값 변경

Packet 전달 함수 만들기

----------------------------------------------------------------------------

/* 

모터가 300도와 0도 사이를 오가며 지속적으로 회전시키려면 모터 회전 후 딜레이 값을 0.865초를 주면 된다.

 

_delay_ms(865);


*/

 

AX-12+ Baud Rate 값 변경


Baud Rate를 변경해 주기 위해서는 instruction에 WRITE_DATA(#3), Length 값에 4, Write Address 값은 4이다.



바꿔주고자하는 Baud Rate는 9,600bps로 한다.

207은 Hex값으로 0x67이다.


AX-12+와 통신을 위해 AX-12+의 Baud Rate를 바꿔주고 난 후 ATmega2560의 Baud Rate도 변경해 주어야 한다.



그리하여 코드는 아래와 같다.



#include <avr/io.h>
#include <util/delay.h>

void USART0_init()
{
  /* BAUD Rate Set */
  UBRR0 = 0x67;

  /* USART Set */
  UCSR0A = 0b00000000;    //일반모드 
  UCSR0B = 0b00001000;    //인터럽트 사용 안함
  UCSR0C = 0b00000110;
}

void PacketTX_P1(unsigned char ID, unsigned char Length, unsigned char Instruction, unsigned char cmd, unsigned char para1)
{
    Data_Tx0(0xFF);  //ini
    Data_Tx0(0xFF);  //ini
    Data_Tx0(ID);  //ID
    Data_Tx0(Length);  //LENGTH = 2+ # of parameter
    Data_Tx0(Instruction);  //Instruction 
    Data_Tx0(cmd);  //command in control table
    Data_Tx0(para1);  //goal position(rear byte)
  
    Data_Tx0((unsigned char)(~(ID + Length + Instruction + cmd + para1)));
    _delay_ms(865);
}

int main(void)

{

  _delay_ms(1000);
  USART0_init();
  
  //Baud Rate 9600으로 변경 
  PacketTX_P1(0x0C, 0x040x030x040xCF);    
  _delay_ms(3000);
  UBRR0 = 0x67;
  _delay_ms(3000);

return 0;

}


 

Packet 전달 함수 만들기

 

주의할 점은 check sum의 값이다. parameter의 개수와 관련이 있음으로 Length의 값을 이용하여 함수를 만들어주면 쉽게 값을 도출할 수 있다.

parameter의 개수에 따라 함수를 달리해 주어야 한다.

void PacketTX_P1(unsigned char ID, unsigned char Length, unsigned char Instruction, unsigned char cmd, unsigned char para1)
{
    Data_Tx0(0xFF);  //ini
    Data_Tx0(0xFF);  //ini
    Data_Tx0(ID);  //ID
    Data_Tx0(Length);  //LENGTH = 2+ # of parameter
    Data_Tx0(Instruction);  //Instruction 
    Data_Tx0(cmd);  //command in control table
    Data_Tx0(para1);  //goal position(rear byte)
  
    Data_Tx0((unsigned char)(~(ID + Length + Instruction + cmd + para1)));
    _delay_ms(865);
}
void PacketTX_P2(unsigned char ID, unsigned char Length, unsigned char Instruction, unsigned char cmd, unsigned char para1, unsigned char para2)
{
    Data_Tx0(0xFF);  //ini
    Data_Tx0(0xFF);  //ini
    Data_Tx0(ID);  //ID
    Data_Tx0(Length);  //LENGTH = 2+ # of parameter
    Data_Tx0(Instruction);  //Instruction 
    Data_Tx0(cmd);  //command in control table
    Data_Tx0(para1);  //goal position(rear byte)
    Data_Tx0(para2);  //goal position(head byte)
  
    Data_Tx0((unsigned char)(~(ID + Length + Instruction + cmd + para1 + para2)));
    _delay_ms(865);
}






반응형
Posted by newind2000
Busan IT/모터제어2015. 7. 10. 13:43

================================ Outline ====================================

모터 가동(Dynamixel AX-12)

---------------------------------------------------------------------------- 

Instruction Packet에 명령어를 입력하여 모터의 각을 300도에서 0로 지속적으로 움직이게 하는 코드를 짜보자.



우선 처음 2byte는 명령어 전달이 시작됨을 알리기 위해 0xFF를 두 번 넣어준다.

 

그 다음 모터의 ID값을 전달해준다.

 

//ID가 안 맞으면 broadcast 0xFE를 던져주면 된다.

 

Parameter의 바이트 수 + 2한 값을 length에 넣어준다. Parameter에는 시작 주소의 값과 2byte의 원하는 각도 값을 넣어주어야 함으로 이 경우 5를 입력해주면 된다.

 

instruction‘WRITE'명령임으로 3을 넣어준다.


 

//Goal Position을 입력할 때 하위 1바이트부터 입력해야 한다.


#include <avr/io.h>
#include <util/delay.h>

void USART0_init()
{
  /* BAUD Rate Set */
  UBRR0 = 0;

  /* USART Set */
  UCSR0A = 0b00000000;    //일반모드 
  UCSR0B = 0b00001000;    //인터럽트 사용 안함
  UCSR0C = 0b00000110;

}

void Data_Tx( unsigned char data )
{
  /* Wait for empty transmit buffer */
  while ( !( UCSR0A & (1<<UDRE0)) );
  
  /* Put data into buffer, sends the data */
  UDR0 = data;

  
}
int main(void)
{
  //unsigned char ucInit[9];
  //int iCnt;
  
  _delay_ms(1000);
  USART0_init();
  /*
  ucInit[0] = 0xFF;  //ini
  ucInit[1] = 0xFF;  //ini
  ucInit[2] = 0xFE;  //ID =10, Broadcase = 0xFE
  ucInit[3] = 0x05;  //LENGTH = 3+2
  ucInit[4] = 0x03;  //Instruction WRITE = 3
  ucInit[5] = 0x1E;  //모터 회전
  ucInit[6] = 0x03;  //각도 300 = 0x3FF
  ucInit[7] = 0xFA;  //각도 300 = 0x3FF
  ucInit[8] = ~((unsigned char)(0xFE + 0x05 + 0x03 + 0x1E + 0x03 + 0xFA));


  for(iCnt = 0; iCnt < 9; ++iCnt)
  {
      Data_Tx(ucInit[iCnt]);    
  }
*/

  while(1)
  {
    Data_Tx(0xFF);  //ini
    Data_Tx(0xFF);  //ini
    Data_Tx(0x0C);  //ID =12, Broadcase = 0xFE
    Data_Tx(0x05);  //LENGTH = 3+2
    Data_Tx(0x03);  //Instruction WRITE = 3
    Data_Tx(0x1E);  //모터 회전
    Data_Tx(0xFF);  //각도 300 = 0x3FF
    Data_Tx(0x03);  //각도 300 = 0x3FF
    Data_Tx((unsigned char)(~(0x0C + 0x05 + 0x03 + 0x1E + 0xFF + 0x03)));
    _delay_ms(1000);



    Data_Tx(0xFF);  //ini
    Data_Tx(0xFF);  //ini
    Data_Tx(0x0C);  //ID =12, Broadcase = 0xFE
    Data_Tx(0x05);  //LENGTH = 2+2
    Data_Tx(0x03);  //Instruction WRITE = 3
    Data_Tx(0x1E);  //모터 회전
    Data_Tx(0x00);  //각도 0 = 0x000
    Data_Tx(0x00);  //각도 0 = 0x000
  
    Data_Tx((unsigned char)(~(0x0C + 0x05 + 0x03 + 0x1E + 0x00 + 0x00)));
    _delay_ms(1000);

  }
  return 0;
}




반응형
Posted by newind2000
Busan IT/제어 UI(C#)2015. 7. 9. 17:09


mook_Message.exe


일대일채팅.pdf


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;// IP Address
using System.Net.Sockets;//TcpListener 클래스 사용
using System.Threading;// 스레드 클래스 사용
using System.IO;//파일 클리스 사용
using Microsoft.Win32;//레지스트리 클래스 사용 _code Line 38번
using System.Runtime.InteropServices; //폼 깜빡임 구현 "User32.dll 활용"

namespace _20150708_chatting
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private TcpListener Server;
        private TcpClient SerClient, client;
        private NetworkStream myStream;
        private StreamReader myRead;
        private StreamWriter myWrite;
        private Boolean Start = false;
        private Boolean ClientCon = false;
        private int myPort;
        private string myName;
        private Thread myReader, myServer;
        private Boolean TextChange = false;

        private RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\NETFramework"true);

        private delegate void AddTextDelegate(string strText);
        private AddTextDelegate AddText = null;

        [DllImport("User32.dll")]
        private static extern bool FlashWindow(IntPtr hwnd, bool bInbert);

        


        private void 설정ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.설정ToolStripMenuItem.Enabled = false;
            this.plOption.Visible = true;
            this.txtId.Focus();
            this.txtId.Text = (string)key.GetValue("Message_name");
            this.txtPort.Text = (string)key.GetValue("Message_port");
        }

        private void 닫기ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if(this.cbServer.Checked == true)
            {
                ControlCheck();
            }
            else
            {
                if(this.txtIp.Text == "")
                {
                    this.txtIp.Focus();
                }
                else
                {
                    ControlCheck();
                }
            }

        }
        private void ControlCheck()
        {
            if(this.txtId.Text =="")
            {
                this.txtId.Focus();
            }
            else if(this.txtPort.Text == "")
            {
                this.txtPort.Focus();
            }
            else
            {
                try
                {
                    var name = this.txtId.Text;
                    var port = this.txtPort.Text;
                    key.SetValue("Message_name", name);
                    key.SetValue("Message_port", port);
                    this.plOption.Visible = false;
                    this.설정ToolStripMenuItem.Enabled = true;
                    this.tsbtnConn.Enabled = true;
                }
                catch
                {
                    MessageBox.Show("설정이 저장되지 않았습니다.""에러", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

        private void btbClose_Click(object sender, EventArgs e)
        {
            this.설정ToolStripMenuItem.Enabled = true;
            this.plOption.Visible = false;
            this.txtMessage.Focus();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            if ((string)key.GetValue("Message name")=="")
            {
                this.myName = this.txtId.Text;
                this.myPort = Convert.ToInt32(this.txtPort.Text);
            }
            else
          {
                try
                {
                    this.myName = (string)key.GetValue("Message_name");
                    this.myPort = Convert.ToInt32(key.GetValue("Message_port"));                    
                }
                catch
                {
                    this.myName = this.txtId.Text;
                    this.myPort = Convert.ToInt32(this.txtPort.Text);
                }
                
          }

        }

        private void tsbtnConn_Click(object sender, EventArgs e)
        {
            AddText = new AddTextDelegate(MessageView);
            if(this.cbServer.Checked == true)
            {
                var addr = new IPAddress(0);
                try 
                {
                    this.myName = (string)key.GetValue("Message_name");
                    this.myPort = Convert.ToInt32(key.GetValue("Message_port"));
                }
                catch
                {
                    this.myName = this.txtId.Text;
                    this.myPort = Convert.ToInt32(this.txtPort.Text);
                }

                if(!(this.Start))
                {
                    try
                    {
                        Server = new TcpListener(addr, this.myPort);
                        Server.Start();

                        this.Start = true;
                        this.txtMessage.Enabled = true;
                        this.txtMessage.Focus();
                        this.tsbtnDisconn.Enabled = true;
                        this.tsbtnConn.Enabled = false;
                        this.cbServer.Enabled = false;

                        myServer = new Thread(ServerStart);
                        myServer.Start();

                        this.설정ToolStripMenuItem.Enabled = false;
                    }
                    catch
                    {
                        Invoke(AddText, "서버를 실행할 수 없습니다.");
                    }
                }
                else
                {
                    ServerStop();
                }
            }
            else
            {
                if(!(this.ClientCon))
                {
                    this.myName = (string)key.GetValue("Message_name");
                    this.myPort = Convert.ToInt32(key.GetValue("Message_port"));
                    ClientConnection();
                }
                else
                {
                    this.txtMessage.Enabled = false;
                    this.btnSend.Enabled = false;
                    Disconnection();
                }
            }            
        }

        private void tsbtnDisconn_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.cbServer.Checked)
                {
                    var dt = Convert.ToString(DateTime.Now);
                    myWrite.WriteLine(this.myName + "&" + "채팅 APP가 종료되었습니다." + "&" + dt);
                    myWrite.Flush();
                }
            }

            catch { }
            ServerStop();
            this.설정ToolStripMenuItem.Enabled = true;
        }

        private void ServerStart()
        {
            Invoke(AddText, "서버 실행 : 챗 상대의 접속을 기다립니다...");
            while(Start)
            {
                try
                {
                    SerClient = Server.AcceptTcpClient();
                    Invoke(AddText, "챗 상대 접속..");
                    myStream = SerClient.GetStream();

                    myRead = new StreamReader(myStream);
                    myWrite = new StreamWriter(myStream);
                    this.ClientCon = true;
                    myReader = new Thread(Receive);
                    myReader.Start();
                }
                catch { }
            }
        }


        private void ServerStop()
        {
            this.Start = false;
            this.txtMessage.Enabled = false;
            this.txtMessage.Clear();
            this.btnSend.Enabled = false;
            this.tsbtnConn.Enabled = true;
            this.tsbtnDisconn.Enabled = false;
            this.cbServer.Enabled = true;
            this.ClientCon = false;

            if(!(myRead == null))
            {
                myRead.Close();
            }
            if(!(myWrite == null))
            {
                myWrite.Close();
            }
            if (!(myStream == null))
            {
                myStream.Close();
            }
            if (!(SerClient == null))
            {
                SerClient.Close();
            }
            if (!(Server == null))
            {
                Server.Stop();
            }
            if (!(myReader == null))
            {
                myReader.Abort();
            }
            if (!(myServer == null))
            {
                myServer.Abort();
            }
            if (!(AddText == null))
            {
                Invoke(AddText, "연결이 끊어졌습니다.");
            }

        }

        private void ClientConnection()
        {
            try
            {
                client = new TcpClient(this.txtIp.Text, this.myPort);
                Invoke(AddText, "서버에 접속 했습니다.");
                myStream = client.GetStream();

                myRead = new StreamReader(myStream);
                myWrite = new StreamWriter(myStream);
                this.ClientCon = true;
                this.tsbtnConn.Enabled = false;
                this.tsbtnDisconn.Enabled = true;
                this.btnSend.Enabled = true;
                this.txtMessage.Focus();

                myReader = new Thread(Receive);
                myReader.Start();
            }
            catch
            {
                this.ClientCon = false;
                Invoke(AddText, "서버에 접속하지 못했습니다.");
            }
        }

        private void Disconnection()
        {
            this.ClientCon = false;
            try
            {
                if (!(myRead == null))
                {
                    myRead.Close();
                }
                if (!(myWrite == null))
                {
                    myWrite.Close();
                }
                if (!(myStream == null))
                {
                    myStream.Close();
                }
                if (!(client == null))
                {
                    client.Close();
                }
                if (!(myReader == null))
                {
                    myReader.Abort();
                }
            }
            catch
            {
                return;
            }
        }

        private void Receive()
        {
            try
            {
                while(this.ClientCon)
                {
                    if(myStream.CanRead)
                    {
                        var msg = myRead.ReadLine();
                        var Smsg = msg.Split('&');
                        if(Smsg[0== "S001")
                        {
                            this.tsslblTime.Text = Smsg[1];
                        }
                        else
                        {
                            if(msg.Length > 0)
                            {
                                Invoke(AddText, Smsg[0] + " ; " + Smsg[1]);
                            }
                            this.tsslblTime.Text = "마지막으로 받은 시각:" + Smsg[2];
                        }
                    }
                }
            }
            catch { }
        }

        private void MessageView(string strText)
        {
            this.rtbText.AppendText(strText + "\r\n");
            this.rtbText.Focus();
            this.rtbText.ScrollToCaret();
            this.txtMessage.Focus();
            FlashWindow(this.Handle, true);
        }

        private void txtMessage_KeyPress(object sender, KeyPressEventArgs e)
        {
            if(e.KeyChar == (char)13)
            {
                e.Handled = true;
                if(this.txtMessage.Text =="")
                {
                    this.txtMessage.Focus();
                }
                else
                {
                    Msg_send();
                }
            }
        }

        private void btnSend_Click(object sender, EventArgs e)
        {
            if(this.txtMessage.Text=="")
            {
                this.txtMessage.Focus();
            }
            else
            {
                Msg_send();
            }
        }

        private void Msg_send()
        {
            try
            {
                var dt = Convert.ToString(DateTime.Now);
                myWrite.WriteLine(this.myName + "&" + this.txtMessage.Text + "&" + dt);
                myWrite.Flush();
                MessageView(this.myName + "; " + this.txtMessage.Text);
                this.txtMessage.Clear();
            }
            catch
            {
                Invoke(AddText, "데이터를 보내는 동안 오류가 발생하였습니다");
                this.txtMessage.Clear();
            }
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            try { ServerStop(); }
            catch { Disconnection(); }
        }

        private void cbServer_CheckedChanged(object sender, EventArgs e)
        {
            if(TextChange == false)
            {
                TextChange = true;
                myWrite.WriteLine("S001" + "&" + "상대방이 메세지 입력중입니다." + "&" + " ");
                myWrite.Flush();
            }
            else if (this.txtMessage.Text == "" && TextChange == true)
            {
                TextChange = false;                
            }
        }
    }
}


반응형

'Busan IT > 제어 UI(C#)' 카테고리의 다른 글

리플렉션&애트리뷰트  (0) 2015.07.07
네트워크 프로그래밍  (0) 2015.07.06
스레드 동기화, 파일 다루기  (0) 2015.07.03
프로세서와 스레드  (0) 2015.07.02
MSSQL  (0) 2015.06.30
Posted by newind2000
Busan IT/모터제어2015. 7. 9. 13:27

================================ Outline ====================================

AX-12+ 데이터시트 

----------------------------------------------------------------------------

 

AX-12+ 스텝핑 모터 데이터 시트

우선 요약의 내용을 정독하고, 작동 원리와 작동 방법을 위주로 읽어보자.

 

 

기능:

 

- 1024단계의 resolution으로 속도와 각도 제어

resolution :: Physics & Chemistry The act or process of separating or reducing something into its constituent parts: the prismatic resolution of sunlight into its spectral colors.

compliance :: flexibility in physics.

torque :: a power of moving circular object

 

- 위치 제어에 있어서 탄력의 정도를 설정할 수 있다.

 

- 위치각, 속도와 구동중인 load의 크기 값을 알려준다.

 

- 사용자가 조작한 가동범위를 벗어났을 때 이를 알려주고 이 때 자동으로 동작을 멈춘다.

 

- 통신속도는 1M/BPS이다.

 

- 하나의 패킷 안에 속도, 위치, 탄력 값을 전달할 수 있다.

 

- 오류 발생 시 내용을 LED를 사용하여 전달해준다.

 

 

상세정보:

 

- 한 단계의 각 = 0.35

 

- 최대 동작각 = 300

 

- 동작 온도 = -5- 85

 

- 통신 프로토콜 = 8bit, 1stop, 패리티 없음

 

- 통신 속도 = 7343bps - 1Mbps

 

- 표시 정보 값 = 위치, 온도, 로드, 입력 전압 등

3개의 선(VDD, GND, Data)을 활용하여 구동할 수 있고 나머지 3개의 핀은 다른 모터 연결하여 동시에 구동할 때 사용할 수 있다.

 

매뉴얼에 나와 있는 main controller가 없음으로 코드를 사용해 이를 제어해야 한다.






통신을 위한 ID설정 시 packet충돌을 막기 위해서 ID가 중복되지 않도록 유의해야 한다.

통신 프로토콜은 8bit, 1 stop bit, 패리티 없음이고, 비동기식이다.

 

패킷의 구조는 다음과 같다.

앞의 두 개의 0xFFpacket 시작 신호를 알린다.

 

서보 모터 예제 진행 순서

 

1.USART 설정

2.데이터 송신 함수 작성

3.통신 프로토콜 분석

4.송신 Packet 함수 작성


USART 사용을 위한 설정과 TX함수


#include <avr/io.h>
#include <util/delay.h>

void USART0_init()
{
  /* BAUD Rate Set */
  UBRR0 = 0;

  /* USART Set */
  UCSR0A = 0b00000000;    //일반모드 
  UCSR0B = 0b00001000;    //인터럽트 사용 안함
  UCSR0C = 0b00000110;

}

void Data_Tx( unsigned char data )
{
  /* Wait for empty transmit buffer */
  while ( !( UCSR0A & (1<<UDRE0)) )
  ;
  /* Put data into buffer, sends the data */
  UDR0 = data;
}
int main(void)
{
  unsigned char ucInit[8];
  int iCnt;
  ucInit[0= 0xFF;
  ucInit[1= 0xFF;
  ucInit[2= 0x01;
  //...  
  ucInit[4= 0x03;    //instruction: write

  
  USART0_init();
  while(1)
  {
    
    ;
  }
  return 0;
}

반응형
Posted by newind2000
Busan IT/모터제어2015. 7. 8. 13:31

 

================================ Outline ====================================

AVR Studio ISP 모드

스텝핑 모터

----------------------------------------------------------------------------

AVR Studio ISP 모드

MOSI : Master Output, Slave Input

** MISO


 

퓨즈비트와 락비트는 함부로 건들면 복구가 힘듦으로 신중하게 다루어야 한다.

 

//EEPROM (Electrically Erasable Programmable Read-Only Memory, E2PROM)

 

 

스텝핑 모터

 

Timer/CounterPWM의 활용

- DC모터 제어

- Remote Controller -> 적외선 LED

 

//PWM: Pulse-width modulation

 

AX-12 모터 데이터 시트를 다운 받아서 살펴보자.

 

stepping 모터는 정밀 제어가 가능하다는 장점이 있다.








반응형

'Busan IT > 모터제어' 카테고리의 다른 글

모터 가동(Dynamixel AX-12)  (0) 2015.07.10
AX-12+ 데이터시트  (0) 2015.07.09
AVR 툴체인 설치  (0) 2015.07.07
타이머/카운터 복습, PFC PWM  (0) 2015.05.22
서보 모터  (0) 2015.05.21
Posted by newind2000

================================ Outline ====================================

socket연결

----------------------------------------------------------------------------

htonl의 메뉴얼

 

htonl, htons, ntohl, ntohs - convert values between host and network byte order

 

 

//2바이트와 4바이트만 변환해 준다. 자료형은 longshort가 존재한다.

 

//internet 기반의 소켓 생성 (INET)

if ((server_sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)

{

perror("socket error : ");

exit(0);

}

bzero(&serveraddr, sizeof(serveraddr));

serveraddr.sin_family = AF_INET;

serveraddr.sin_addr.s_addr = htonl(INADDR_ANY);

serveraddr.sin_port = htons(atoi(argv[1]));

 

 

소켓 생성 -> serveraddr 구조체에 IP와 포트번호 입력

 

bind의 메뉴얼

 

NAME

bind - bind a name to a socket

 

SYNOPSIS

#include <sys/types.h> /* See NOTES */

#include <sys/socket.h>

 

int bind(int sockfd, const struct sockaddr *addr,

socklen_t addrlen);

 

소켓으로 함수로만 불완전한 소켓 생성 및 정보를 sockaddr_in 구조체의 정보와 합치기 위해서 bind 함수를 사용한다.

 

 

IP는 네트워크 통신을 위한 주소이고 PORTIP내 데이터를 받을 창구를 뜻한다.

 

컴퓨터에서 작동하고 있는 프로그램을 프로세스라고 하고 프로세스는 고유의 번호를 갖는데 이를 PID라고 한다.

 

 

 

linux에서 pid를 보는 명령어는 ps이다. 프로세스 중에서도 네트워크를 사용하는 프로세스는 port번호를 사용한다.

 

 

다음 시간에 포트 번호에 대해서 더 학습하겠다.





반응형
Posted by newind2000
Busan IT/제어 UI(C#)2015. 7. 7. 16:38

================================ Outline ====================================

리플렉션&애트리뷰트

----------------------------------------------------------------------------


 

모든 타입은 object class의 자식이다.






 

 

반응형

'Busan IT > 제어 UI(C#)' 카테고리의 다른 글

일대일 채팅 프로그램  (0) 2015.07.09
네트워크 프로그래밍  (0) 2015.07.06
스레드 동기화, 파일 다루기  (0) 2015.07.03
프로세서와 스레드  (0) 2015.07.02
MSSQL  (0) 2015.06.30
Posted by newind2000
Busan IT/모터제어2015. 7. 7. 16:35

================================ Outline ====================================

AVR 툴체인 설치

----------------------------------------------------------------------------

 

수업의 방향은 모든 ATMEGA시리즈를 활용하여 코딩이 가능하도록 만드는데 있다. 예전에는 'make'라는 명령어를 사용했지만 이제 AVR Studio를 사용하겠다.

 

AVR Studio 4.19시리즈는 ‘make'를 사용하지 못한다.

 

이를 해결하기 위해 툴체인을 다운 받는다.

 

http://www.atmel.com/tools/ATMELAVRTOOLCHAINFORWINDOWS.aspx






 

최신 버전을 쓰지 않는 이유는 ISP를 쓸 수 없기 때문이다. 4.19버전이 ISP를 사용가능한 가장 최근 버전이다.

 

C:\WinAVR-20100110\avr\include\avr




반응형

'Busan IT > 모터제어' 카테고리의 다른 글

AX-12+ 데이터시트  (0) 2015.07.09
AVR Studio ISP 모드, 스테핑 모터  (0) 2015.07.08
타이머/카운터 복습, PFC PWM  (0) 2015.05.22
서보 모터  (0) 2015.05.21
PC PWM를 활용한 모터제어, SE-SM 243 모터  (0) 2015.05.20
Posted by newind2000
Busan IT/제어 UI(C#)2015. 7. 6. 15:55

================================ Outline ====================================

네트워크 프로그래밍

----------------------------------------------------------------------------

 데이터 전송을 하기 위해 필요한 계층을 설명한 것을 네트워크 계층이라고 한다.

 

네트워크 연결을 위한 저수준 언어의 절차들이 socket에 의하여 간단히 구현가능하다.

TCP방식은 데이터 전송을 확인하지만 UDP은 데이터가 제대로 전송이 되었는지 확인하지 않는다. 때문에 UDP가 네트워크 성능은 빠르지만 신뢰성이 떨어진다.

 

 

네트워크를 위한 물리적인 장치가 port이고 이것을 소프트웨어적으로 설정하는 것이 socket이다. 










반응형

'Busan IT > 제어 UI(C#)' 카테고리의 다른 글

일대일 채팅 프로그램  (0) 2015.07.09
리플렉션&애트리뷰트  (0) 2015.07.07
스레드 동기화, 파일 다루기  (0) 2015.07.03
프로세서와 스레드  (0) 2015.07.02
MSSQL  (0) 2015.06.30
Posted by newind2000