<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Linux Forum &mdash; RS485 (плата PCI1602B)]]></title>
	<link rel="self" href="https://linuxforum.ru/extern.php?action=feed&amp;tid=25990&amp;type=atom" />
	<updated>2013-12-07T21:37:27Z</updated>
	<generator>PunBB</generator>
	<id>https://linuxforum.ru/viewtopic.php?id=25990</id>
		<entry>
			<title type="html"><![CDATA[Re: RS485 (плата PCI1602B)]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=380479#p380479" />
			<content type="html"><![CDATA[<p>А где запись - чтение ?<br />Я с такими платами работал (4 порта) всегда делал проверку на open &amp;&amp; read или вы можете писать в несуществующее устройство<br />ls /dev/ttyAP* сначала<br /></p><div class="codebox"><pre><code>int rx = open(&quot;/dev/ttyАP1&quot;,O_RDWR | O_NONBLOCK);
if (rx &lt; 0 ) {
 perror(&quot;open&quot;);
 return -1;
}
char buf[4096];
int count = read(rx,buf,4096);
if (count &lt; 0) {
 perror(&quot;read&quot;);
 return -1;
}
//int tx - аналогично rx
// termios set there 
/* 
 struct termios ts_new;
     memset(&amp;ts_new,0,sizeof(ts_new));
     ts_new.c_cflag |= ( B115200 | CS8 | CREAD | CLOCAL | HUPCL);
     ts_new.c_cflag &amp;= ~(CRTSCTS | PARENB | PARODD);
     ts_new.c_iflag &amp;= ~(IXON | IXOFF | IUCLC | IGNCR | ICRNL | ISTRIP | INLCR);
     ts_new.c_lflag &amp;= ~(ICANON | ECHO);
     ts_new.c_oflag = 0;
     ts_new.c_cc[VMIN] = 0;
     ts_new.c_cc[VTIME] = 0;
    tcsetattr(rx,TCSANOW,&amp;ts_new);
    tcsetattr(tx,TCSANOW,&amp;ts_new);
 //вроде tcsetattr ошипку не возвращает, для проверки надо tcgetattr;
*/
char* msg =&quot;Hello&quot;;
count = write(tx,msg,strlen(msg));
if (count &lt; 0) { perror(&quot;write tx&quot;); return -1;}
//delay
sleep(1);
count = read(rx,buf,sizeof(buf));
if (count &lt; 0) { perror(&quot; read rx&quot;);return -1;}
write(1,buf,count);</code></pre></div><p>как-то так</p>]]></content>
			<author>
				<name><![CDATA[vic5710]]></name>
				<uri>https://linuxforum.ru/profile.php?id=32751</uri>
			</author>
			<updated>2013-12-07T21:37:27Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=380479#p380479</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[RS485 (плата PCI1602B)]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=319918#p319918" />
			<content type="html"><![CDATA[<p>Добрый день, уважаемые Коллеги.</p><p>Возникли проблемы при работе с RS485 (плата PCI-1602B - двухголовая). <br />Нет приема. <br />Может кто- нибудь работал с этой платой или что подскажет или какие-нибудь исходники скинет.<br />Может не совсем корректно проинициализировал плату ?<br />Заранее благодарю за помощь и внимание.</p><p>У платы две головы. Я соединил выход одной с входом другой и наоборот.<br />Передающая пишет в порт по 5 байт (write) с интервалом.</p><p>Приемная должна читать по 5 байт (read).</p><br /> <br /><div class="codebox"><pre><code>void open_dev()
{
    struct termios m_termios;
    int j,status;
    m_port.primary =open(&quot;/dev/ttyAP0&quot;,O_RDWR|O_NDELAY|O_NOCTTY);

    if(m_port.primary &lt; 0) {
    printf(&quot;/dev/ttyAP0 Open BAD !!!\n&quot;)  ;
        exit(-1);
    }
    printf(&quot;/dev/ttyAP0 Open Ok !!!\n&quot;)  ;

    if(tcgetattr(m_port.primary, &amp;m_termios)==-1) {
    printf(&quot;/dev/ttyAP0 ERROR GETATTR !!!\n&quot;);
    }

    m_termios.c_cflag |= ( CREAD | CLOCAL | HUPCL  );
    m_termios.c_cflag &amp;= ~CSIZE; /* Mask the character size bits */
    m_termios.c_cflag |= CS8;    /* Select 8 data bits */
    m_termios.c_cflag &amp;= ~PARENB;
    m_termios.c_cflag &amp;= ~CSTOPB;

    cfsetispeed(&amp;m_termios,B115200);
    cfsetospeed(&amp;m_termios,B115200);


     m_termios.c_lflag &amp;= ~(ICANON | ECHO | ECHOE | ISIG); //Raw input

    m_termios.c_iflag &amp;= ~( IXON | IXANY | IXOFF ) ;

    m_termios.c_oflag &amp;= ~OPOST;

    tcflush(m_port.primary,TCIOFLUSH);

    if(tcsetattr(m_port.primary,TCSANOW,&amp;m_termios)==-1) {
    printf(&quot;/dev/ttyAP0 ERROR SETATTR !!!\n&quot;);
    }

}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[plica98]]></name>
				<uri>https://linuxforum.ru/profile.php?id=27724</uri>
			</author>
			<updated>2013-01-11T11:27:29Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=319918#p319918</id>
		</entry>
</feed>
