<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="pl-pl">
<link rel="self" type="application/atom+xml" href="https://forum.atnel.pl/feed.php?f=30&amp;t=5473&amp;mode" />

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2014-01-08T03:07:32+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=30&amp;t=5473&amp;mode</id>
<entry>
<author><name><![CDATA[IUVOit]]></name></author>
<updated>2014-01-08T03:07:32+01:00</updated>
<published>2014-01-08T03:07:32+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64268#p64268</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64268#p64268"/>
<title type="html"><![CDATA[Re: Sterowanie RS232 z serwera WWW- problem]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64268#p64268"><![CDATA[
Dokładnie jest tak jak mówisz, już to przetestowałem.<br />Ja steruje swój sterownik i wszystko hula <img src="https://forum.atnel.pl/images/smilies/icon_e_biggrin.gif" alt=":D" title="Bardzo szczęśliwy" /> <br />Kody które działają przy wysyłaniu stringów to:<br />[syntax=php]$serial-&gt;sendMessage('AT'.chr(10).chr(13));<br />  $serial-&gt;sendMessage(&quot;AT\r\n&quot;);[/syntax]<br /><br /><strong><span style="color: #808000">------------------------ [ Dodano po: 3 minutach ]</span></strong><br /><br />Jeżeli się wpisuje stringa w PHP i jest w &quot; &quot; to znaki specjalne są interpretowane, zminne itd. Natomiast jak się wpisuje w '  ' to znaki specjalne nie są interpretowane. Kiedyś więcej wiedziałem o PHP ale z biegiem lat wszystko mi uciekło <img src="https://forum.atnel.pl/images/smilies/icon_e_biggrin.gif" alt=":D" title="Bardzo szczęśliwy" /> Będę musiał odświeżyć wiedzę:D<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=94">IUVOit</a> — 8 sty 2014, o 03:07</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Villentre]]></name></author>
<updated>2014-01-08T02:59:32+01:00</updated>
<published>2014-01-08T02:59:32+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64267#p64267</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64267#p64267"/>
<title type="html"><![CDATA[Re: Sterowanie RS232 z serwera WWW- problem]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64267#p64267"><![CDATA[
Mam spięty laptop (z uruchomionym PuTTy) i stacjonarny (XAMPP i Twój kod z pierwszego postu, z dopisanym jedynie tym &quot;$serial-&gt;confCharacterLength(8);&quot;; po zmianie kodowania różnicy w działaniu nie zauważyłem) najzwyklejszym RS232 (właściwie to nawet tylko rx&lt;-tx i gnd&lt;-&gt;gnd).<br /><br />W odpowiedzi otrzymuję (to co powinienem):<br />[syntax=txt]AT<br />AT<br />AT\r\n[/syntax]<br /><br />PHP stringów pomiędzy ' ' w żaden sposób nie interpretuje, więc oczywiście, w ostatnim przypadku wyświetla &quot;\r\n&quot; zamiast entera.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=517">Villentre</a> — 8 sty 2014, o 02:59</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[IUVOit]]></name></author>
<updated>2014-01-08T02:46:20+01:00</updated>
<published>2014-01-08T02:46:20+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64266#p64266</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64266#p64266"/>
<title type="html"><![CDATA[Re: Sterowanie RS232 z serwera WWW- problem]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64266#p64266"><![CDATA[
Mi nie działa:( Komp zaczął mi się wieszać <img src="https://forum.atnel.pl/images/smilies/icon_e_sad.gif" alt=":(" title="Smutny" /> <br /><br />[syntax=csharp]$serial-&gt;sendMessage('AT'.chr(10).chr(13));<br />$serial-&gt;sendMessage(&quot;AT\r\n&quot;);<br />$serial-&gt;sendMessage('AT\r\n');[/syntax]<br /><br />Wszystkie z tych komend? Chce wysłać komendę AT do uP i ma być zakończona znakami CR i LF.<br /><br />Kodowanie pliku UTF8, ASCII itd to ma tu znaczenie???<br /><br />Ale super, że CI działa!!! Teraz wiem, że kod jest dobry tylko u mnie coś nie tak.<br /><br />A jak Ty dokładnie to testujesz? Odbierasz w przeglądarce znaki? i masz zwarte RX i TX?<br /><br /><strong><span style="color: #808000">------------------------ [ Dodano po: 4 minutach ]</span></strong><br /><br /><strong>Villentre</strong> WIELKIE DZIĘKI PO RAZ 2 W DZISIEJSZYM DNI <img src="https://forum.atnel.pl/images/smilies/icon_e_biggrin.gif" alt=":D" title="Bardzo szczęśliwy" /> Diodka mi zamrugała!!! <img src="https://forum.atnel.pl/images/smilies/icon_e_biggrin.gif" alt=":D" title="Bardzo szczęśliwy" /> Zaczeło dziłać!!!<br /><br /><strong><span style="color: #808000">------------------------ [ Dodano po: 6 minutach ]</span></strong><br /><br /><img src="https://forum.atnel.pl/images/smilies/icon_e_biggrin.gif" alt=":D" title="Bardzo szczęśliwy" /> <img src="https://forum.atnel.pl/images/smilies/icon_e_biggrin.gif" alt=":D" title="Bardzo szczęśliwy" /> <img src="https://forum.atnel.pl/images/smilies/icon_e_biggrin.gif" alt=":D" title="Bardzo szczęśliwy" /><br /><br /><strong><span style="color: #808000">------------------------ [ Dodano po: 10 minutach ]</span></strong><br /><br />Trochę wolno mi to chodzi, ale działa super!!! Ale chyba wolno chodzi sama inicjalizacja otwarcia portu RS232. Jak otworzy się port RS232 to chyba będzie to szybciej smigało, samo wysyłanie komend <img src="https://forum.atnel.pl/images/smilies/icon_e_smile.gif" alt=":)" title="Szczęśliwy" /><br /><br />Jutro jak wrócę z pracy będę miał się czym bawić <img src="https://forum.atnel.pl/images/smilies/icon_e_biggrin.gif" alt=":D" title="Bardzo szczęśliwy" /> Jeszcze raz wielkie dzięki <strong>Villentre</strong> za pomoc <img src="https://forum.atnel.pl/images/smilies/icon_e_smile.gif" alt=":)" title="Szczęśliwy" /> Spadam spać, bo trochę późno <img src="https://forum.atnel.pl/images/smilies/icon_e_wink.gif" alt=";)" title="Puszcza oko" /> Dobranoc <img src="https://forum.atnel.pl/images/smilies/icon_e_biggrin.gif" alt=":D" title="Bardzo szczęśliwy" /><p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=94">IUVOit</a> — 8 sty 2014, o 02:46</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Villentre]]></name></author>
<updated>2014-01-08T02:35:53+01:00</updated>
<published>2014-01-08T02:35:53+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64265#p64265</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64265#p64265"/>
<title type="html"><![CDATA[Re: Sterowanie RS232 z serwera WWW- problem]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64265#p64265"><![CDATA[
W tej blibliotece jest metoda &quot;confCharacterLength&quot; do wywołania z parametrem 8 - uwaga! działa (u mnie) tylko po wywołaniu na samym końcu konfiguracji!<br />[syntax=php]$serial = new phpSerial;<br />$serial-&gt;deviceSet(&quot;COM1&quot;);<br />$serial-&gt;confBaudRate(9600);<br />$serial-&gt;confParity(&quot;none&quot;);<br />$serial-&gt;confFlowControl(&quot;none&quot;);<br />$serial-&gt;confStopBits(1);<br />$serial-&gt;confCharacterLength(8);[/syntax]<br /><br /><br />Ewentualnie w uC to różnica jednego bitu w konfiguracji UARTu.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=517">Villentre</a> — 8 sty 2014, o 02:35</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[IUVOit]]></name></author>
<updated>2014-01-08T02:25:55+01:00</updated>
<published>2014-01-08T02:25:55+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64264#p64264</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64264#p64264"/>
<title type="html"><![CDATA[Re: Sterowanie RS232 z serwera WWW- problem]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64264#p64264"><![CDATA[
AHA!!! i jakoś to trzeba na 8 bitów zamienic????<br /><br /><strong><span style="color: #808000">------------------------ [ Dodano po: 6 minutach ]</span></strong><br /><br />Przy inicjalizacji portu nie dodałem:<br />$serial-&gt;confCharacterLength(8);<br />Ale i tak to nic nie zmiania <img src="https://forum.atnel.pl/images/smilies/icon_e_sad.gif" alt=":(" title="Smutny" /><p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=94">IUVOit</a> — 8 sty 2014, o 02:25</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Villentre]]></name></author>
<updated>2014-01-08T02:23:51+01:00</updated>
<published>2014-01-08T02:23:51+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64263#p64263</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64263#p64263"/>
<title type="html"><![CDATA[Re: Sterowanie RS232 z serwera WWW- problem]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64263#p64263"><![CDATA[
O. Już wiem gdzie błąd - skrypt wysyła znaki w wersji najprostszej ASCII - siedmiobitowe. (:<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=517">Villentre</a> — 8 sty 2014, o 02:23</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[IUVOit]]></name></author>
<updated>2014-01-08T02:12:29+01:00</updated>
<published>2014-01-08T02:12:29+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64262#p64262</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64262#p64262"/>
<title type="html"><![CDATA[Re: Sterowanie RS232 z serwera WWW- problem]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64262#p64262"><![CDATA[
O dzięki!!! tak myślałem, że następuje jakieś przekłamanie. Tylko nie wiem dlaczego:( To nie jest moja biblioteka, znalazłem ją w sieci (@author Rémy Sanchez &lt;thenux@gmail.com&gt;). Może gdzieś w ustawianiach, serwera należy zmienić kodowanie z ANSI na UTF8 itd ?  Nad tym się w sumie nie zastanowiłem. Ale dziwnie zamiania te znaki. Przy kodowaniu są raczej ogonki poucinane, brak polskich liter itp a tu jakoś dziwnie to zamienia ...<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=94">IUVOit</a> — 8 sty 2014, o 02:12</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Villentre]]></name></author>
<updated>2014-01-08T02:03:51+01:00</updated>
<published>2014-01-08T02:03:51+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64261#p64261</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64261#p64261"/>
<title type="html"><![CDATA[Re: Sterowanie RS232 z serwera WWW- problem]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64261#p64261"><![CDATA[
Racja, zapomniałem, że blokuje port... A z tym odbieraniem przez serwer tak bym się nie spieszył:<br />[syntax=php]function readPort ($count = 0)<br />        {<br />                //(...)<br />                elseif ($this-&gt;_os === &quot;windows&quot;)<br />                {<br />                        /* Do nohting : not implented yet */<br />                }<br /> <br />                trigger_error(&quot;Reading serial port is not implemented for Windows&quot;, E_USER_WARNING);<br />                return false;<br />        }[/syntax]<br /><br /><br />Twój kod uruchomiłem u siebie... Rzeczywiście przesyła... Ale praktycznie na każdym znaku jest przekłamanie... <br />Tzn. część znaków przesyła poprawnie (c, e, f, l, o, w, x, A, B, D, G, H, ...) a inne zamienia na jakieś dialektyczne (np. 'd' na 'ä' czy 'h' na 'ç') - i zawsze tak przesyła, więc wykluczam błędy z doborem prędkości (a przetestowałem to na kilku różnych, efekt ten sam). <br /><br />Kodowanie pliku też kilkukrotnie zmieniałem, bez efektów...<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=517">Villentre</a> — 8 sty 2014, o 02:03</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[IUVOit]]></name></author>
<updated>2014-01-08T01:09:34+01:00</updated>
<published>2014-01-08T01:09:34+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64260#p64260</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64260#p64260"/>
<title type="html"><![CDATA[Re: Sterowanie RS232 z serwera WWW- problem]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64260#p64260"><![CDATA[
Jak przeglądarka otwiera port, to nie mogę otworzyć tego portu za pomocą terminala. <br /><br />Zastanawiałem się aby wykorzystać ATMega644p, na UART1 wchodzą informacje z serwera www, uP przesyła ją dalej na UART2, UART2 wysyłą dalej na PC. Ale na razie nie mam 2 przejściówki RS232-&gt;USB. W sumie mam Mirkowy moduł BTM który bym mógł wykorzystać. <br /><br />Nie mam łatwiejszego pomysłu jak bym mógł podsłuchać co się pojawia na tym UART.<br /><br /><strong><span style="color: #808000">------------------------ [ Dodano po: 3 minutach ]</span></strong><br /><br />Hmmm... Na samym serwerze też można za pomocą tej biblioteki odbierać łańcuchy. Jutro to wypróbuje...<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=94">IUVOit</a> — 8 sty 2014, o 01:09</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[Villentre]]></name></author>
<updated>2014-01-08T00:59:05+01:00</updated>
<published>2014-01-08T00:59:05+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64259#p64259</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64259#p64259"/>
<title type="html"><![CDATA[Re: Sterowanie RS232 z serwera WWW- problem]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64259#p64259"><![CDATA[
Otwórz terminal na kompie z tymi samymi parametrami co masz na uC, na przejściówce zewrzyj/połącz Rx i Tx i patrz co się wyświetla... Teoretycznie uC powinien dostawać to samo.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=517">Villentre</a> — 8 sty 2014, o 00:59</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[IUVOit]]></name></author>
<updated>2014-01-08T00:47:02+01:00</updated>
<published>2014-01-08T00:47:02+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64258#p64258</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64258#p64258"/>
<title type="html"><![CDATA[Sterowanie RS232 z serwera WWW- problem]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=5473&amp;p=64258#p64258"><![CDATA[
Witam, tak jak w temacie, mam problem z wysterowaniem portu RS232 z serwera www.<br /><br />Sprawa wygląda następująco:<br />Pogrzebałem trochę po internecie i znalazłem bibliotekę która umożliwia wysyłanie komend na port RS232. <br /><a href="http://www.phpclasses.org/browse/file/17926.html"  class="postlink">http://www.phpclasses.org/browse/file/17926.html</a> Jest to dość popularna biblioteka i chyba jedyna ogólnie dostępna do konfiguracji portu RS232.<br />[syntax=php]&lt;?php<br />define (&quot;SERIAL_DEVICE_NOTSET&quot;, 0);<br />define (&quot;SERIAL_DEVICE_SET&quot;, 1);<br />define (&quot;SERIAL_DEVICE_OPENED&quot;, 2);<br /><br />/**<br /> * Serial port control class<br /> *<br /> * THIS PROGRAM COMES WITH ABSOLUTELY NO WARANTIES !<br /> * USE IT AT YOUR OWN RISKS !<br /> *<br /> * @author Rémy Sanchez &lt;thenux@gmail.com&gt;<br /> * @thanks Aurélien Derouineau for finding how to open serial ports with windows<br /> * @thanks Alec Avedisyan for help and testing with reading<br /> * @copyright under GPL 2 licence<br /> */<br />class phpSerial<br />{<br />var $_device = null;<br />var $_windevice = null;<br />var $_dHandle = null;<br />var $_dState = SERIAL_DEVICE_NOTSET;<br />var $_buffer = &quot;&quot;;<br />var $_os = &quot;&quot;;<br /><br />/**<br /> * This var says if buffer should be flushed by sendMessage (true) or manualy (false)<br /> *<br /> * @var bool<br /> */<br />var $autoflush = true;<br /><br />/**<br /> * Constructor. Perform some checks about the OS and setserial<br /> *<br /> * @return phpSerial<br /> */<br />function phpSerial ()<br />{<br />setlocale(LC_ALL, &quot;en_US&quot;);<br /><br />$sysname = php_uname();<br /><br />if (substr($sysname, 0, 5) === &quot;Linux&quot;)<br />{<br />$this-&gt;_os = &quot;linux&quot;;<br /><br />if($this-&gt;_exec(&quot;stty --version&quot;) === 0)<br />{<br />register_shutdown_function(array($this, &quot;deviceClose&quot;));<br />}<br />else<br />{<br />trigger_error(&quot;No stty availible, unable to run.&quot;, E_USER_ERROR);<br />}<br />}<br />elseif(substr($sysname, 0, 7) === &quot;Windows&quot;)<br />{<br />$this-&gt;_os = &quot;windows&quot;;<br />register_shutdown_function(array($this, &quot;deviceClose&quot;));<br />}<br />else<br />{<br />trigger_error(&quot;Host OS is neither linux nor windows, unable tu run.&quot;, E_USER_ERROR);<br />exit();<br />}<br />}<br /><br />//<br />// OPEN/CLOSE DEVICE SECTION -- {START}<br />//<br /><br />/**<br /> * Device set function : used to set the device name/address.<br /> * -&gt; linux : use the device address, like /dev/ttyS0<br /> * -&gt; windows : use the COMxx device name, like COM1 (can also be used<br /> *     with linux)<br /> *<br /> * @param string $device the name of the device to be used<br /> * @return bool<br /> */<br />function deviceSet ($device)<br />{<br />if ($this-&gt;_dState !== SERIAL_DEVICE_OPENED)<br />{<br />if ($this-&gt;_os === &quot;linux&quot;)<br />{<br />if (preg_match(&quot;@^COM(\d+):?$@i&quot;, $device, $matches))<br />{<br />$device = &quot;/dev/ttyS&quot; . ($matches&#91;1&#93; - 1);<br />}<br /><br />if ($this-&gt;_exec(&quot;stty -F &quot; . $device) === 0)<br />{<br />$this-&gt;_device = $device;<br />$this-&gt;_dState = SERIAL_DEVICE_SET;<br />return true;<br />}<br />}<br />elseif ($this-&gt;_os === &quot;windows&quot;)<br />{<br />if (preg_match(&quot;@^COM(\d+):?$@i&quot;, $device, $matches) and $this-&gt;_exec(exec(&quot;mode &quot; . $device)) === 0)<br />{<br />$this-&gt;_windevice = &quot;COM&quot; . $matches&#91;1&#93;;<br />$this-&gt;_device = &quot;\\.\com&quot; . $matches&#91;1&#93;;<br />$this-&gt;_dState = SERIAL_DEVICE_SET;<br />return true;<br />}<br />}<br /><br />trigger_error(&quot;Specified serial port is not valid&quot;, E_USER_WARNING);<br />return false;<br />}<br />else<br />{<br />trigger_error(&quot;You must close your device before to set an other one&quot;, E_USER_WARNING);<br />return false;<br />}<br />}<br /><br />/**<br /> * Opens the device for reading and/or writing.<br /> *<br /> * @param string $mode Opening mode : same parameter as fopen()<br /> * @return bool<br /> */<br />function deviceOpen ($mode = &quot;r+b&quot;)<br />{<br />if ($this-&gt;_dState === SERIAL_DEVICE_OPENED)<br />{<br />trigger_error(&quot;The device is already opened&quot;, E_USER_NOTICE);<br />return true;<br />}<br /><br />if ($this-&gt;_dState === SERIAL_DEVICE_NOTSET)<br />{<br />trigger_error(&quot;The device must be set before to be open&quot;, E_USER_WARNING);<br />return false;<br />}<br /><br />if (!preg_match(&quot;@^&#91;raw&#93;\+?b?$@&quot;, $mode))<br />{<br />trigger_error(&quot;Invalid opening mode : &quot;.$mode.&quot;. Use fopen() modes.&quot;, E_USER_WARNING);<br />return false;<br />}<br /><br />$this-&gt;_dHandle = @fopen($this-&gt;_device, $mode);<br /><br />if ($this-&gt;_dHandle !== false)<br />{<br />stream_set_blocking($this-&gt;_dHandle, 0);<br />$this-&gt;_dState = SERIAL_DEVICE_OPENED;<br />return true;<br />}<br /><br />$this-&gt;_dHandle = null;<br />trigger_error(&quot;Unable to open the device&quot;, E_USER_WARNING);<br />return false;<br />}<br /><br />/**<br /> * Closes the device<br /> *<br /> * @return bool<br /> */<br />function deviceClose ()<br />{<br />if ($this-&gt;_dState !== SERIAL_DEVICE_OPENED)<br />{<br />return true;<br />}<br /><br />if (fclose($this-&gt;_dHandle))<br />{<br />$this-&gt;_dHandle = null;<br />$this-&gt;_dState = SERIAL_DEVICE_SET;<br />return true;<br />}<br /><br />trigger_error(&quot;Unable to close the device&quot;, E_USER_ERROR);<br />return false;<br />}<br /><br />//<br />// OPEN/CLOSE DEVICE SECTION -- {STOP}<br />//<br /><br />//<br />// CONFIGURE SECTION -- {START}<br />//<br /><br />/**<br /> * Configure the Baud Rate<br /> * Possible rates : 110, 150, 300, 600, 1200, 2400, 4800, 9600, 38400,<br /> * 57600 and 115200.<br /> *<br /> * @param int $rate the rate to set the port in<br /> * @return bool<br /> */<br />function confBaudRate ($rate)<br />{<br />if ($this-&gt;_dState !== SERIAL_DEVICE_SET)<br />{<br />trigger_error(&quot;Unable to set the baud rate : the device is either not set or opened&quot;, E_USER_WARNING);<br />return false;<br />}<br /><br />$validBauds = array (<br />110    =&gt; 11,<br />150    =&gt; 15,<br />300    =&gt; 30,<br />600    =&gt; 60,<br />1200   =&gt; 12,<br />2400   =&gt; 24,<br />4800   =&gt; 48,<br />9600   =&gt; 96,<br />19200  =&gt; 19,<br />38400  =&gt; 38400,<br />57600  =&gt; 57600,<br />115200 =&gt; 115200<br />);<br /><br />if (isset($validBauds&#91;$rate&#93;))<br />{<br />if ($this-&gt;_os === &quot;linux&quot;)<br />{<br />$ret = $this-&gt;_exec(&quot;stty -F &quot; . $this-&gt;_device . &quot; &quot; . (int) $rate, $out);<br />}<br />elseif ($this-&gt;_os === &quot;windows&quot;)<br />{<br />$ret = $this-&gt;_exec(&quot;mode &quot; . $this-&gt;_windevice . &quot; BAUD=&quot; . $validBauds&#91;$rate&#93;, $out);<br />}<br />else return false;<br /><br />if ($ret !== 0)<br />{<br />trigger_error (&quot;Unable to set baud rate: &quot; . $out&#91;1&#93;, E_USER_WARNING);<br />return false;<br />}<br />}<br />}<br /><br />/**<br /> * Configure parity.<br /> * Modes : odd, even, none<br /> *<br /> * @param string $parity one of the modes<br /> * @return bool<br /> */<br />function confParity ($parity)<br />{<br />if ($this-&gt;_dState !== SERIAL_DEVICE_SET)<br />{<br />trigger_error(&quot;Unable to set parity : the device is either not set or opened&quot;, E_USER_WARNING);<br />return false;<br />}<br /><br />$args = array(<br />&quot;none&quot; =&gt; &quot;-parenb&quot;,<br />&quot;odd&quot;  =&gt; &quot;parenb parodd&quot;,<br />&quot;even&quot; =&gt; &quot;parenb -parodd&quot;,<br />);<br /><br />if (!isset($args&#91;$parity&#93;))<br />{<br />trigger_error(&quot;Parity mode not supported&quot;, E_USER_WARNING);<br />return false;<br />}<br /><br />if ($this-&gt;_os === &quot;linux&quot;)<br />{<br />$ret = $this-&gt;_exec(&quot;stty -F &quot; . $this-&gt;_device . &quot; &quot; . $args&#91;$parity&#93;, $out);<br />}<br />else<br />{<br />$ret = $this-&gt;_exec(&quot;mode &quot; . $this-&gt;_windevice . &quot; PARITY=&quot; . $parity{0}, $out);<br />}<br /><br />if ($ret === 0)<br />{<br />return true;<br />}<br /><br />trigger_error(&quot;Unable to set parity : &quot; . $out&#91;1&#93;, E_USER_WARNING);<br />return false;<br />}<br /><br />/**<br /> * Sets the length of a character.<br /> *<br /> * @param int $int length of a character (5 &lt;= length &lt;= 8)<br /> * @return bool<br /> */<br />function confCharacterLength ($int)<br />{<br />if ($this-&gt;_dState !== SERIAL_DEVICE_SET)<br />{<br />trigger_error(&quot;Unable to set length of a character : the device is either not set or opened&quot;, E_USER_WARNING);<br />return false;<br />}<br /><br />$int = (int) $int;<br />if ($int &lt; 5) $int = 5;<br />elseif ($int &gt; 8) $int = 8;<br /><br />if ($this-&gt;_os === &quot;linux&quot;)<br />{<br />$ret = $this-&gt;_exec(&quot;stty -F &quot; . $this-&gt;_device . &quot; cs&quot; . $int, $out);<br />}<br />else<br />{<br />$ret = $this-&gt;_exec(&quot;mode &quot; . $this-&gt;_windevice . &quot; DATA=&quot; . $int, $out);<br />}<br /><br />if ($ret === 0)<br />{<br />return true;<br />}<br /><br />trigger_error(&quot;Unable to set character length : &quot; .$out&#91;1&#93;, E_USER_WARNING);<br />return false;<br />}<br /><br />/**<br /> * Sets the length of stop bits.<br /> *<br /> * @param float $length the length of a stop bit. It must be either 1,<br /> * 1.5 or 2. 1.5 is not supported under linux and on some computers.<br /> * @return bool<br /> */<br />function confStopBits ($length)<br />{<br />if ($this-&gt;_dState !== SERIAL_DEVICE_SET)<br />{<br />trigger_error(&quot;Unable to set the length of a stop bit : the device is either not set or opened&quot;, E_USER_WARNING);<br />return false;<br />}<br /><br />if ($length != 1 and $length != 2 and $length != 1.5 and !($length == 1.5 and $this-&gt;_os === &quot;linux&quot;))<br />{<br />trigger_error(&quot;Specified stop bit length is invalid&quot;, E_USER_WARNING);<br />return false;<br />}<br /><br />if ($this-&gt;_os === &quot;linux&quot;)<br />{<br />$ret = $this-&gt;_exec(&quot;stty -F &quot; . $this-&gt;_device . &quot; &quot; . (($length == 1) ? &quot;-&quot; : &quot;&quot;) . &quot;cstopb&quot;, $out);<br />}<br />else<br />{<br />$ret = $this-&gt;_exec(&quot;mode &quot; . $this-&gt;_windevice . &quot; STOP=&quot; . $length, $out);<br />}<br /><br />if ($ret === 0)<br />{<br />return true;<br />}<br /><br />trigger_error(&quot;Unable to set stop bit length : &quot; . $out&#91;1&#93;, E_USER_WARNING);<br />return false;<br />}<br /><br />/**<br /> * Configures the flow control<br /> *<br /> * @param string $mode Set the flow control mode. Availible modes :<br /> * -&gt; &quot;none&quot; : no flow control<br /> * -&gt; &quot;rts/cts&quot; : use RTS/CTS handshaking<br /> * -&gt; &quot;xon/xoff&quot; : use XON/XOFF protocol<br /> * @return bool<br /> */<br />function confFlowControl ($mode)<br />{<br />if ($this-&gt;_dState !== SERIAL_DEVICE_SET)<br />{<br />trigger_error(&quot;Unable to set flow control mode : the device is either not set or opened&quot;, E_USER_WARNING);<br />return false;<br />}<br /><br />$linuxModes = array(<br />&quot;none&quot;     =&gt; &quot;clocal -crtscts -ixon -ixoff&quot;,<br />&quot;rts/cts&quot;  =&gt; &quot;-clocal crtscts -ixon -ixoff&quot;,<br />&quot;xon/xoff&quot; =&gt; &quot;-clocal -crtscts ixon ixoff&quot;<br />);<br />$windowsModes = array(<br />&quot;none&quot;     =&gt; &quot;xon=off octs=off rts=on&quot;,<br />&quot;rts/cts&quot;  =&gt; &quot;xon=off octs=on rts=hs&quot;,<br />&quot;xon/xoff&quot; =&gt; &quot;xon=on octs=off rts=on&quot;,<br />);<br /><br />if ($mode !== &quot;none&quot; and $mode !== &quot;rts/cts&quot; and $mode !== &quot;xon/xoff&quot;) {<br />trigger_error(&quot;Invalid flow control mode specified&quot;, E_USER_ERROR);<br />return false;<br />}<br /><br />if ($this-&gt;_os === &quot;linux&quot;)<br />$ret = $this-&gt;_exec(&quot;stty -F &quot; . $this-&gt;_device . &quot; &quot; . $linuxModes&#91;$mode&#93;, $out);<br />else<br />$ret = $this-&gt;_exec(&quot;mode &quot; . $this-&gt;_windevice . &quot; &quot; . $windowsModes&#91;$mode&#93;, $out);<br /><br />if ($ret === 0) return true;<br />else {<br />trigger_error(&quot;Unable to set flow control : &quot; . $out&#91;1&#93;, E_USER_ERROR);<br />return false;<br />}<br />}<br /><br />/**<br /> * Sets a setserial parameter (cf man setserial)<br /> * NO MORE USEFUL !<br /> * -&gt; No longer supported<br /> * -&gt; Only use it if you need it<br /> *<br /> * @param string $param parameter name<br /> * @param string $arg parameter value<br /> * @return bool<br /> */<br />function setSetserialFlag ($param, $arg = &quot;&quot;)<br />{<br />if (!$this-&gt;_ckOpened()) return false;<br /><br />$return = exec (&quot;setserial &quot; . $this-&gt;_device . &quot; &quot; . $param . &quot; &quot; . $arg . &quot; 2&gt;&amp;1&quot;);<br /><br />if ($return{0} === &quot;I&quot;)<br />{<br />trigger_error(&quot;setserial: Invalid flag&quot;, E_USER_WARNING);<br />return false;<br />}<br />elseif ($return{0} === &quot;/&quot;)<br />{<br />trigger_error(&quot;setserial: Error with device file&quot;, E_USER_WARNING);<br />return false;<br />}<br />else<br />{<br />return true;<br />}<br />}<br /><br />//<br />// CONFIGURE SECTION -- {STOP}<br />//<br /><br />//<br />// I/O SECTION -- {START}<br />//<br /><br />/**<br /> * Sends a string to the device<br /> *<br /> * @param string $str string to be sent to the device<br /> * @param float $waitForReply time to wait for the reply (in seconds)<br /> */<br />function sendMessage ($str, $waitForReply = 0.1)<br />{<br />$this-&gt;_buffer .= $str;<br /><br />if ($this-&gt;autoflush === true) $this-&gt;flush();<br /><br />usleep((int) ($waitForReply * 1000000));<br />}<br /><br />/**<br /> * Reads the port until no new datas are availible, then return the content.<br /> *<br /> * @pararm int $count number of characters to be read (will stop before<br /> * if less characters are in the buffer)<br /> * @return string<br /> */<br />function readPort ($count = 0)<br />{<br />if ($this-&gt;_dState !== SERIAL_DEVICE_OPENED)<br />{<br />trigger_error(&quot;Device must be opened to read it&quot;, E_USER_WARNING);<br />return false;<br />}<br /><br />if ($this-&gt;_os === &quot;linux&quot;)<br />{<br />$content = &quot;&quot;; $i = 0;<br /><br />if ($count !== 0)<br />{<br />do {<br />if ($i &gt; $count) $content .= fread($this-&gt;_dHandle, ($count - $i));<br />else $content .= fread($this-&gt;_dHandle, 128);<br />} while (($i += 128) === strlen($content));<br />}<br />else<br />{<br />do {<br />$content .= fread($this-&gt;_dHandle, 128);<br />} while (($i += 128) === strlen($content));<br />}<br /><br />return $content;<br />}<br />elseif ($this-&gt;_os === &quot;windows&quot;)<br />{<br />/* Do nohting : not implented yet */<br />}<br /><br />trigger_error(&quot;Reading serial port is not implemented for Windows&quot;, E_USER_WARNING);<br />return false;<br />}<br /><br />/**<br /> * Flushes the output buffer<br /> *<br /> * @return bool<br /> */<br />function flush ()<br />{<br />if (!$this-&gt;_ckOpened()) return false;<br /><br />if (fwrite($this-&gt;_dHandle, $this-&gt;_buffer) !== false)<br />{<br />$this-&gt;_buffer = &quot;&quot;;<br />return true;<br />}<br />else<br />{<br />$this-&gt;_buffer = &quot;&quot;;<br />trigger_error(&quot;Error while sending message&quot;, E_USER_WARNING);<br />return false;<br />}<br />}<br /><br />//<br />// I/O SECTION -- {STOP}<br />//<br /><br />//<br />// INTERNAL TOOLKIT -- {START}<br />//<br /><br />function _ckOpened()<br />{<br />if ($this-&gt;_dState !== SERIAL_DEVICE_OPENED)<br />{<br />trigger_error(&quot;Device must be opened&quot;, E_USER_WARNING);<br />return false;<br />}<br /><br />return true;<br />}<br /><br />function _ckClosed()<br />{<br />if ($this-&gt;_dState !== SERIAL_DEVICE_CLOSED)<br />{<br />trigger_error(&quot;Device must be closed&quot;, E_USER_WARNING);<br />return false;<br />}<br /><br />return true;<br />}<br /><br />function _exec($cmd, &amp;$out = null)<br />{<br />$desc = array(<br />1 =&gt; array(&quot;pipe&quot;, &quot;w&quot;),<br />2 =&gt; array(&quot;pipe&quot;, &quot;w&quot;)<br />);<br /><br />$proc = proc_open($cmd, $desc, $pipes);<br /><br />$ret = stream_get_contents($pipes&#91;1&#93;);<br />$err = stream_get_contents($pipes&#91;2&#93;);<br /><br />fclose($pipes&#91;1&#93;);<br />fclose($pipes&#91;2&#93;);<br /><br />$retVal = proc_close($proc);<br /><br />if (func_num_args() == 2) $out = array($ret, $err);<br />return $retVal;<br />}<br /><br />//<br />// INTERNAL TOOLKIT -- {STOP}<br />//<br />}<br />?&gt;[/syntax]<br /><br />Do testowania stworzyłem plik index.php<br />[syntax=php]&lt;title&gt;Tytuł&lt;/title&gt;<br /><br />&lt;/head&gt;<br /><br />&lt;body&gt;<br /><br />&lt;B&gt;Test HTML&lt;/B&gt;&lt;BR&gt;<br /><br /><br />&lt;?php<br />include &quot;php_serial.class.php&quot;;<br /><br /><br />$serial = new phpSerial;<br /><br />$serial-&gt;deviceSet(&quot;COM1&quot;);<br /><br />$serial-&gt;confBaudRate(9600);<br />$serial-&gt;confParity(&quot;none&quot;);<br />$serial-&gt;confFlowControl(&quot;none&quot;);<br />$serial-&gt;confStopBits(1);<br /><br /> // Then we need to open it<br />$serial-&gt;deviceOpen();<br /><br />$serial-&gt;sendMessage(&quot;AT&quot;.chr(13));<br />$serial-&gt;sendMessage(&quot;AT\r\n&quot;);<br />$serial-&gt;sendMessage('AT\r\n');<br /><br />$serial-&gt;deviceClose();<br /><br />?&gt;<br /><br />&lt;/body&gt;<br />&lt;/html&gt;[/syntax]<br /><br /><br />Do laptopa na którym postawiłem serwer mam podłączoną przejściówkę USB-&gt;RS232. Piny RX,TX,GND. Od strony elektrycznej jest wszystko OK, ponieważ jak wysyłam z terminala to wszystko działa. Zmiania się stan diody na przeciwny, oraz jest odpowiedz &quot;OK&quot;.<br /><br />Jak próbuję wysłać komendę poprzez stronę index.php Widzę, że coś z tego portu wylatuje diody na przejściówce mi mrugają, czyli leci jakaś komenda do uP. Tylko jest brak reakcji uP ??<br /><br />Parametry transmisji: COM1,8,0,1 <br /><br />Skrypt PHP wykonuje się bez błędów hmmm coś jest wysyłane na port COM ale nie wiem co?<br /><br />Musze coś zmieniać w ustawieniach serwera?  Mam postawiony serwer XAMPP na swoim laptopie Windows 7.<br /><br />Biblioteka najprawdopodobniej działa, ponieważ jest dosyć popularna w necie, ja coś muszę źle robić :/<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=94">IUVOit</a> — 8 sty 2014, o 00:47</p><hr />
]]></content>
</entry>
</feed>