<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Linux Forum &mdash; RS485 (плата PCI1602B)]]></title>
		<link>https://linuxforum.ru/viewtopic.php?id=25990</link>
		<atom:link href="https://linuxforum.ru/extern.php?action=feed&amp;tid=25990&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «RS485 (плата PCI1602B)».]]></description>
		<lastBuildDate>Sat, 07 Dec 2013 21:37:27 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: RS485 (плата PCI1602B)]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=380479#p380479</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (vic5710)]]></author>
			<pubDate>Sat, 07 Dec 2013 21:37:27 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=380479#p380479</guid>
		</item>
		<item>
			<title><![CDATA[RS485 (плата PCI1602B)]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=319918#p319918</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (plica98)]]></author>
			<pubDate>Fri, 11 Jan 2013 11:27:29 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=319918#p319918</guid>
		</item>
	</channel>
</rss>
