Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


kicken last won the day on October 17

kicken had the most liked content!

1 Follower

About kicken

Contact Methods

  • Website URL

Profile Information

  • Gender
  • Location
    Bonita, FL
  • Age

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

kicken's Achievements

Prolific Member

Prolific Member (5/5)




Community Answers

  1. Alternatively, as I mentioned in another thread of yours, stop trying to manipulate the styles directly like that and just apply/remove a class. js: function toggleResponseArea(){ document.getElementById('comment-area').classList.toggle('removed'); } css: .removed { display: none; }
  2. I change the fwrite you had to be followed by "\n" instead of "\r", did you try changing that back? If that doesn't help, you'll have to do some debugging locally and try to figure it out. Works ok for me with my ardiuno loaded with a quick test program to read the analog pins. kicken@ubuntu-dev:/Workspace/serial$ php serial_linux.php read_a0 string(32) "readLength=7 cmd=read_a0 793 "
  3. This code worked for me using a VM with ubuntu on it. When reading the results after sending the command it will hang for at least as long as the timeout period before returning results since there's no way to determine when the serial device is done sending data otherwise. <?php $cmd = implode(' ', array_slice($argv, 1)); $device = serialSetup('/dev/ttyS0', 115200, 8); var_dump(serial($device, $cmd ?: 'uname -a')); fclose($device); function serialSetup($device, $baud, $data){ $cmd = sprintf('stty -F %s %d cs%d -echo raw', $device, $baud, $data); exec($cmd, $output, $ret); if ($ret !== 0){ var_dump($output); throw new \RuntimeException('Unable to configure serial device'); } $f = fopen($device, "w+"); if (!$f){ throw new \RuntimeException('Unable to open serial device.'); } stream_set_blocking($f, false); return $f; } function serial($device, $cmd){ fwrite($device, $cmd . "\n"); $result = ''; do { try { $result .= serialRead($device, 5); $timeout = false; } catch (RuntimeException $ex){ $timeout = true; } } while (!$timeout); return $result; } function serialRead($device, $timeout = 30){ $r = [$device]; $w = $e = []; $n = stream_select($r, $w, $e, $timeout, 0); if ($n === 1){ $line = fgets($device) ?: ''; if ($line !== ''){ return $line; } } throw new \RuntimeException('Timeout reading from serial device'); } For the curious, this also sort of works on windows. The timeout cannot be controlled on windows, so you're stuck with the default (around 120 seconds). The stty call needs to be replaced with the following call to mode and of course use the appropriate device name (ie, COM1). The important bit seems to be the to=on parameter in the call to mode, without it windows seems to never timeout on a read and the script would hang indefinitely. $cmd = sprintf('mode %s BAUD=%d PARITY=n DATA=%d to=on', $device, $baud, $data);
  4. Have you tried using a library instead of diy? I haven't done much work with serial devices and PHP but I do have stuff I could setup and try to generate an example. If I have time later tonight and you haven't resolved the issue already maybe I will dig it out and give it a try.
  5. Option 1, yes just a SQL view. You could create a query that will left join the account_settings table and generate a result set that contains each setting and the value from the account_settings table if set, or the default value from the setting if not. You could then map that view to a read-only entity and add it as a relation to your account entity. Option 2, yes a service i just some class that you use to perform some task which is accessible via the container/dependency injection. Most things are "just normal php code", they just get categorized based their purpose. In general Services are code that generally implement your business logic; Controllers handle the your HTTP requests, generating responses and collecting input data; Entities/Data objects are simple data structures for moving data around the system in an organized way (vs just array's everywhere for example). Not really sure what you mean by the new wrinkle, so no advice there I guess.
  6. Your script is probably getting stuck here: $dataOut = fgets($f); It's waiting for data from your serial device but the device isn't sending any data so the script just hangs there waiting indefinitely. You'll have to add some debug logging or something to figure out why or if that's actually the case. You could also try implementing non-blocking IO and a timeout.
  7. The structure seems fine to me. For the doctrine/symfony integration I see two possible approaches. Create a view that you can query against to get the configured value for a setting (either the value in account_setting or the default value) and then make a read-only entity based on that view. Changing a setting would require creating/updating an entity for the underlying account settings table rather than the read-only entity. Create a service that you can use to query for a setting. The service would check for a account setting first, then fall back. You could have the service load all the relevant data on the first inquiry rather than run separate queries on each inquiry. The service could also include the code needed to create/update account settings. I'd probably go with option #2. It keeps the code for settings more centralized and consistent.
  8. You need your join on the second table to be a LEFT JOIN, but right now you're just making it a regular (INNER) JOIN. An inner join excludes the row from the result if no match is found in the second table. A left join will include the row, but with all the fields from the second table set to NULL. I don't know code igniter, but a simple search for code igniter left join suggests you want to write your join as: $this->db->join('crm_clients_users c','t.agent_id = c.id', 'left');
  9. If someone decides to be funny and set $_GET['page'] to "-42" you don't end up with messed up calculations. Using max, any number <= 0 will get ignored and $page will get set to 1 instead. If you calculate your total page count you should do a min($totalPageCount, $page) as well so that $page doesn't get set to something larger than $totalPageCount.
  10. Rather than passing two variables in the URL, just pass one called 'page'. You can use that to calculate your $to/$from variables. $recordsPerPage = 10; $page = max($_GET['page'], 1); $from = ($page - 1) * $recordsPerPage; $to = $from + $recordsPerPage; For the previous button, disable it if $page == 1. To handle your next button, you need to do a query to count the total possible results. Take the same query you'd use to obtain your paginated data and remove the LIMIT clause and replace the selected columns with CEIL(COUNT(*)/10) as totalPages. Once you have the total page count you can compare it to $page to determine whether or not to enable the next button.
  11. For future reference, rather changing the value of display directly like that, it's easier to just add/remove a class which will apply display: none; Doing it that way, you don't have to worry about whether it should be 'block', 'inline', 'table-cell', 'grid', etc. You just apply display: none; with a class to hide it, then remove the class so display: none; gets removed and it falls back to whatever the previous value was.
  12. PHPStorm is what I use, but the price may put it out of consideration for any non-professional. Editplus is what I used to use before PHPStorm. I still keep it around as it's a nice general-purpose text editor. The price is low and it's one time payment for the most part. Might have to pay again for a future version if you want to upgrade years down the road (minor versions and next major version upgrade are included with original purchase). Notepad++ is what I tend to use if I just need to download an editor for a short period of time.
  13. Have a look at the composer's documentation for vendor binaries and maybe scripts. By adding a script to your project, you could run your command via something like composer attribute-validator. If you add the vendor/bin path to your PATH then you could just run attribute-validator directly.
  14. Your composer.json file defines two require keys. The first one has your intended requirements, the second later on is empty. The empty one overrides your first one.
  15. Your foreach loop will run to completion (ie, print every row) before your while loop condition gets re-evaluated. In pseudo-code, what you wrote is this: while $counter < 8 for each result $row print $row increment $counter end end Where as what you want to write, is while $counter < 8 fetch next result $row if $row exists print $row end increment $counter end There are multiple ways to write that. One way is to fetch a row at a time rather than everything. Another is to fetch it all like you are now, but break; after the 8th row.
  • 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.