Jump to content

Nev

Members
  • Posts

    6
  • Joined

  • Last visited

Nev's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi all, I hope some one can shed some light for me as how to send a carriage return and newline inside a spring that is being sent to a serialport. then read back to browser. The new lines are not working. I've tried \n \r \r\n <br> PHP_EOL. I can get this to work via the echo command but not when sending the spring via serial port. Thanks in anticipation. $serial->sendMessage("The big Brown Fox jumped over the cold lazey dog") . "<br>"; $serial->sendMessage("Message 2"); // Or to read from $read = $serial->readPort(); echo $read; echo "line 1" . "<br>"; echo "line 2" . "<br>"; echo "line 3" . "<br>"; I get the Result below. The big Brown Fox jumped over the cold lazey dogMessage 2line 1 line 2 line 3
  2. Thanks kicken for your reply and information. I understand a bit better now. I did try the PHPserial Class earler and had no luck. Is this something I need to install or enable in the php.ini file. Thanks again for your help
  3. Hi, I'm wondering if someone could help please. I've been trawling the net and looking through forums. I'm having trouble with $objComport = new COM ( "AxSerial.ComPort" ); I get this responce Fatal error: Uncaught exception 'com_exception' with message 'Failed to create COM object `AxSerial.Comport': Invalid syntax ' in E:\ServerTest\htmldocs\Comport.php:3 Stack trace: #0 E:\ServerTest\htmldocs\Comport.php(3): com->com('AxSerial.Compor...') #1 {main} thrown in E:\ServerTest\htmldocs\Comport.php on line 3 Basically what I'm trying to do is open a com port and send a string "JOBS" This instruction tells my serial device what to do. If there is a better way of doing this I would really appreciate it. Thanks again Nev
  4. Cool, thanks for the tip. I've managed to get this to work now, I had to open the port on my server pc and my laptop. Now I can telenet into the server. When I type "shutdown" it it stops the server, if I type quit it disconnects but does not shut down the server, so unable to start as already running. Thanks again.
  5. Thanks for your reply, I'm a bit new to this and I was wondering if you could explain "cli". Currently I'm trying to run from my laptop's web browser, through my local intranet. How should I run this program. Thanks again.
  6. Hi all, I need a little help please. I've got some code that creates a socket and a echo server, but I'm not having any luck in getting it to run. I've got the socket created, and closes, but when I try to run the code inside the "Do" "While" section the web page just hangs. I can see the port created on my server. Can some please shed some light at to what I'm doing wrong or what settings I need to change. My server is Apache/2.0.64 (Win32) PHP/5.2.17 .code below. Thanks in anticipation. Nev <?php error_reporting(E_ALL); /* Allow the script to hang around waiting for connections. */ set_time_limit(0); /* Turn on implicit output flushing so we see what we're getting * as it comes in. */ ob_implicit_flush(); $address = '192.168.0.7'; $port = 10001; if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) { echo "socket_create() failed: reason:1 " . socket_strerror(socket_last_error()) . "\n"; } if (socket_bind($sock, $address, $port) === false) { echo "socket_bind() failed: reason:2 $address" . socket_strerror(socket_last_error($sock)) . "\n"; } echo '<p>Hello World</p>'; if (socket_listen($sock, 5) === false) { echo "socket_listen() failed: reason:3 " . socket_strerror(socket_last_error($sock)) . "\n"; } do { if (($msgsock = socket_accept($sock)) === false) { echo "socket_accept() failed: reason:4 " . socket_strerror(socket_last_error($sock)) . "\n"; break; } /* Send instructions. */ $msg = "\nWelcome to the PHP Test Server. \n" . "To quit, type 'quit'. To shut down the server type 'shutdown'.\n"; socket_write($msgsock, $msg, strlen($msg)); do { if (false === ($buf = socket_read($msgsock, 2048, PHP_NORMAL_READ))) { echo "socket_read() failed: reason: " . socket_strerror(socket_last_error($msgsock)) . "\n"; break 2; } if (!$buf = trim($buf)) { continue; } if ($buf == 'quit') { break; } if ($buf == 'shutdown') { socket_close($msgsock); break 2; } $talkback = "PHP: You said '$buf'.\n"; socket_write($msgsock, $talkback, strlen($talkback)); echo "$buf\n"; } while (true); socket_close($msgsock); } while (true); socket_close($sock); ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.