½Ã¸®¾óÆ÷Æ®¿ë ¸±·¹ÀÌ Á¦¾î.

   Á¶È¸ 3072   Ãßõ 0    

https://www.aliexpress.com/item/32990413968.html
RS232 시리얼포트/196; 1228;Ǻ12;.104;lj16; 4채널 릴/112;1060; 1228;품1012; 샀습니다.

https://onedrive.live.com/redir?resid=3DFF9FAEE8435679!15927&authkey=!AG1AzoSlnv7JM4g&ithint=file%2crar
그런데 1228;공Ȣ16;lj16; 소프트웨Ǻ12;lj16; 윈도우용 C#1004;/196; 1676;여1652; 코드 1104;1060;네요.

단순Ȣ16;,172; 그냥 161652;수값1012; writeȢ16;면 .104;lj16;,152;/196; 생각Ȣ16;고 리눅스에서 C코드를 1089;성Ȣ16;였1004;나 ᇼ1;1089;1060; 안.104;네요.

무Ǻ16;가 IC를 1228;Ǻ12;Ȣ16;lj16; 별도1032; 라1060;브러리가 필요한,163;1068;까요?

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


#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>

#include <sys/types.h>
#include <sys/stat.h>

#define COM3 &#160; &#160;"/dev/ttyS0"

static int fd3;

// 시리얼포트 속성처리용 구1312;체
struct termios newtio3;

int serial_init(void)
{
&#160; &#160; fd3 = open(COM3, O_RDWR | O_NOCTTY);

&#160; &#160; // COM1 시리얼 속성 셋ᔚ1;
&#160; &#160; memset(&newtio3, 0, sizeof(newtio3));

&#160; &#160; cfsetispeed(&newtio3, B9600);
&#160; &#160; cfsetospeed(&newtio3, B9600);

&#160; &#160; newtio3.c_cflag |= PARENB;
&#160; &#160; newtio3.c_cflag &= ~PARODD;
&#160; &#160; newtio3.c_cflag &= ~CSTOPB;
&#160; &#160; newtio3.c_cflag &= ~CSIZE;
&#160; &#160; newtio3.c_cflag |= CS8;

&#160; &#160; newtio3.c_cflag |= CLOCAL;
&#160; &#160; newtio3.c_cflag |= CREAD;
&#160; &#160; newtio3.c_iflag = IGNPAR;
&#160; &#160; newtio3.c_oflag = 0;
&#160; &#160; newtio3.c_lflag = 0;
&#160; &#160; newtio3.c_cc[VTIME] = 0;
&#160; &#160; newtio3.c_cc[VMIN] = 1;

&#160; &#160; tcflush (fd3, TCIFLUSH);
&#160; &#160; tcsetattr(fd3, TCSANOW, &newtio3);

&#160; &#160; return 0;
}

int main(int argc, char* argv[])
{
&#160; &#160; int bytes, i;
&#160; &#160; char buf[4][8];
&#160; &#160; char momentary[8];

&#160; &#160; serial_init();

&#160; &#160; memset(momentary, 0x00, 8);

&#160; &#160; momentary[0] = 0x55; momentary[1] = 0x56; momentary[2] = 0x00; momentary[3] = 0x00;
&#160; &#160; momentary[4] = 0x00; momentary[5] = 0x01; momentary[6] = 0x04; momentary[7] = 0xB0;

&#160; &#160; //setvbuf(stdout, NULL, _IOFBF, 0);

&#160; &#160; bytes = write(fd3, momentary, 8);

#if 0
&#160; &#160; for(i=0;i<4;i++)
&#160; &#160; {
&#160; &#160; &#160; &#160; memset(buf[i], 0x00, 8);
&#160; &#160; }

&#160; &#160; // Relay Open
&#160; &#160; buf[0][0] = 0x55; buf[0][1] = 0x56; buf[0][2] = 0x00; buf[0][3] = 0x00; buf[0][4] = 0x00; buf[0][5] = 0x01; buf[0][6] = 0x01; buf[0][7] = 0xAD;
&#160; &#160; buf[1][0] = 0x55; buf[1][1] = 0x56; buf[1][2] = 0x00; buf[1][3] = 0x00; buf[1][4] = 0x00; buf[1][5] = 0x02; buf[1][6] = 0x01; buf[1][7] = 0xAE;
&#160; &#160; buf[2][0] = 0x55; buf[2][1] = 0x56; buf[2][2] = 0x00; buf[2][3] = 0x00; buf[2][4] = 0x00; buf[2][5] = 0x03; buf[2][6] = 0x01; buf[2][7] = 0xAF;
&#160; &#160; buf[3][0] = 0x55; buf[3][1] = 0x56; buf[3][2] = 0x00; buf[3][3] = 0x00; buf[3][4] = 0x00; buf[3][5] = 0x04; buf[3][6] = 0x01; buf[3][7] = 0xB0;

&#160; &#160; for(i=0;i<4;i++)
&#160; &#160; {
&#160; &#160; &#160; &#160; write(fd3, buf[i], 8);
&#160; &#160; &#160; &#160; sleep(1);
&#160; &#160; }

&#160; &#160; // Relay Close
&#160; &#160; buf[0][0] = 0x55; buf[0][1] = 0x56; buf[0][2] = 0x00; buf[0][3] = 0x00; buf[0][4] = 0x00; buf[0][5] = 0x01; buf[0][6] = 0x02; buf[0][7] = 0xAE;
&#160; &#160; buf[1][0] = 0x55; buf[1][1] = 0x56; buf[1][2] = 0x00; buf[1][3] = 0x00; buf[1][4] = 0x00; buf[1][5] = 0x02; buf[1][6] = 0x02; buf[1][7] = 0xAF;
&#160; &#160; buf[2][0] = 0x55; buf[2][1] = 0x56; buf[2][2] = 0x00; buf[2][3] = 0x00; buf[2][4] = 0x00; buf[2][5] = 0x03; buf[2][6] = 0x02; buf[2][7] = 0xB0;
&#160; &#160; buf[3][0] = 0x55; buf[3][1] = 0x56; buf[3][2] = 0x00; buf[3][3] = 0x00; buf[3][4] = 0x00; buf[3][5] = 0x04; buf[3][6] = 0x02; buf[3][7] = 0xB1;

&#160; &#160; for(i=0;i<4;i++)
&#160; &#160; {
&#160; &#160; &#160; &#160; write(fd3, buf[i], 8);
&#160; &#160; &#160; &#160; sleep(1);
&#160; &#160; }
#endif
&#160; &#160; close(fd3);

&#160; &#160; return 0;
}

ªÀº±Û Àϼö·Ï ½ÅÁßÇÏ°Ô.
datafaber 2020-06
¸ÕÀú Á¦°øÇÏ´Â ¼ÒÇÁÆ®¿þ¾î¿Í RS232ÄÉÀ̺í·Î º¸µå°¡ ÀÛµ¿ÇÏ´ÂÁöºÎÅÍ È®ÀÎÇغ¸½Ã´Â°Ô ÁÁÀ»°Í°°³×¿ä.
     
½Ã¸®¾óÆ÷Æ® ´Þ¸° À©µµ¿ì ¸Ó½ÅÀÌ ÇöÀç ¾ø½À´Ï´Ù. @@
          
datafaber 2020-06
RS232ÄÉÀ̺íÀÌ Á¦´ë·Î ÀÛµ¿Çؼ­ Á¾´Ü±îÁö ÆÐŶÀÌ Àß ³¯¶ó°¡´ÂÁö È®½ÇÇÏÁö ¾ÊÀº »óÅ¿¡¼­´Â ¹é³¯ ÄÚµùÇغÁ¾ß ¾µ¸ð°¡ ¾ø½À´Ï´Ù. ¸ÕÀú HW¸¦ üũÇغ¸½ÃÁÒ. º¸µåÀÛµ¿À̶ó´ø°¡ RS232ÄÉÀ̺íÀÌ ¸é ·çÇÁ¹é Å×½ºÆ®µµ °¡´ÉÇÏ´Ï °Å±â¼­ºÎÅÍ ½ÃÀÛÇغ¸½Ã´Â°Ô ÁÁÀ»°Í°°³×¿ä.
               
¹æ±Ý À©µµ¿ì10 ¼³Ä¡ÇÏ°í ¸µÅ©¿¡ ÷ºÎµÈ C# ÇÁ·Î±×·¥À¸·Î Á¤»óÅ×½ºÆ®¸¦ ¸¶ÃƽÀ´Ï´Ù.
À©µµ¿ì10¿¡¼­´Â Àß µ¿À۵dz׿ä.
¹«¾Æ 2020-06
ÇØ´ç c# Äڵ带 ´Ù¿îÇؼ­ º¸´Ï
¾Æ·¡Ã³·³ µÇ¾î Àִµ¥..
Æ÷Æ®¹øÈ£ ¼³Á¤¸¸ ÀÖ°í ´Ù¸¥ °Ç ¾ø´Â °Å º¸´Ï c# ¿¡¼­ »ç¿ëÇÏ´Â µðÆúÆ® ¼³Á¤ÀÎ µí ÇÕ´Ï´Ù.
vs c# ¿¡¼­ µðÆúÆ® ¼³Á¤ À̹ÌÁö¸¦ ¿Ã¸®´Ï Âü°íÇÏ¿© c ¿¡¼­µµ ¼³Á¤ÀÌ °°°Ô µÇ¾î ÀÖ´ÂÁö È®ÀÎÇغ¸¼¼¿ä.
[https://i.imgur.com/Hcf1BHO.png]
public class SerialRelay
    {
        private System.IO.Ports.SerialPort port = new SerialPort();
        private string _lastError = string.Empty;
        private byte[] _sums = new byte[] {0xAB,0xAD,0xAE,0xAF,0xB0,0xAE,0xAF,0xB0,0xB1,0xAF,0xB0,0xB1,0xB2,0xB0,0xB1,0xB2,0xB3};
        byte[] b = new byte[8];

        public static String[] GetPorts()
        {
            return SerialPort.GetPortNames();
        }
        public string LastError
        {
            get { return _lastError; }
        }
        public SerialRelay()
        {
            b[0] = 0x55;
            b[1] = 0x56;
            b[2] = 0x00;
            b[3] = 0x00;
            b[4] = 0x00;
        }

        public bool Open(string portName)
        {
            _lastError = string.Empty;
            if (port.IsOpen) port.Close();
            port.PortName = portName;
            try
            {
                port.Open();
                return true;
            }
            catch(Exception ex)
            {
                _lastError = ex.Message;
            }
            return false;
        }
        public void SendCommand(RelayCommand command,int channel)
        {
            if (!port.IsOpen) return;
            if (channel < 1 || channel > 4) return;
            b[5] = Convert.ToByte(channel);
            b[6] = Convert.ToByte(command);
            b[7] = 0xAB;
            b[7] += b[5];
            b[7] += b[6];

            port.Write(b, 0, 8);
        }
    }
     
½Ã¸®¾ó Æ÷Æ® ¼³Á¤ÀÌ ²¿¿´´ø°Ô ¹®Á¦¿´½À´Ï´Ù.
´ÙÀ½°ú °°ÀÌ C Äڵ带 ¼öÁ¤ÇÏ¿© ÇذẸ¾Ò½À´Ï´Ù. °¨»çÇÕ´Ï´Ù.

struct termios newtio3;

int serial_init(void)
{
    fd3 = open(COM3, O_RDWR | O_NOCTTY);

    newtio3.c_cflag = B9600;
    newtio3.c_cflag |= CS8;
    newtio3.c_cflag |= CLOCAL;
    newtio3.c_cflag |= CREAD;
    newtio3.c_iflag = 0;
    newtio3.c_oflag = 0;
    newtio3.c_lflag = 0;
    newtio3.c_cc[VTIME] = 0;
    newtio3.c_cc[VMIN] = 1;

    tcflush(fd3, TCIFLUSH);
    tcsetattr(fd3, TCSANOW, &newtio3);

    return 0;
}


QnA
Á¦¸ñPage 336/420
2021-05   2869   ¼öÆÛ½ÎÀ̾ð
2020-06   3208   SugarCube
2021-05   1972   NaHS
2020-06   2865   KurTurCho
2021-05   2955   Á¦¿ÂÇÁ·Î
2020-06   3958   Á¤ÀǼ®
2021-04   1583   sffbig
2020-06   30510   DDDIE
2021-04   2763   ¸ÇȦȫ
2020-06   9672   Ãʱް³¹ßÀÚ
2021-04   2061   ¸Ô¯ÀÌ
2020-06   3010   newretrowave
2021-04   1735   ¹Ì»çÄ«¹ÌÄÚÅä
2020-06   2598   cjp1117
2021-04   2407   Á¤ÁÖȯ
2020-06   2802   ³ªºñz
2021-04   1994   Noname1
2020-06   2477   ÂÞÂÞºÀ
2021-04   4703   AMDºô·±
2020-06   3674   ´«ºÎ½Å¾Æħ