PHP comm port checker

in #utopian-io7 years ago (edited)

Hello to everyone my name is eresbos,

Coded for ;

  • I encoded it so that port errors could be resolved faster.

Comm port checker coded for your computer ports testing.If an error occurs when a device is added.You can solve it more quickly. If port is off you see this mesagge 'Your comm-port not active.Check your connection'. You can check the following port list :

  • '2400',
  • '4800',
  • '9600',
  • '19200',
  • '38400',
  • '57600',
  • '115200',
  • '230400',


-Used functions ;

  • shell_exec : Execute command via shell and return the complete output as a string
  • substr_count : Count the number of substring occurrences
  • explode : Split a string by string
  • count : Count all elements in an array, or something in an object
  • str_replace : Replace all occurrences of the search string with the replacement string
  • substr : Return part of a string
  • implode : Join array elements with a string
  • trim : Strip whitespace (or other characters) from the beginning and end of a string
  • isset : Determine if a variable is set and is not NULL


  • index.php
<?php

function comm_list() {

        $commport = shell_exec('mode');

        if(substr_count($commport,'COM')<1) {
            $commport_list[0] = 'None';
        } else {

            $conn = explode(' ',$commport);
            $count = count($conn);
            for($i=0;$i<$count;$i++) {
                if(substr_count($conn[$i],'COM')<1) {
                    $commport_list[$i] = '';
                } else {
                    $commport_list[$i] = str_replace(':','',substr($conn[$i],0,5)).'-';
                }
            }

        }

        $commport = implode('',$commport_list);
        $commport = trim($commport);
        $commport = trim(str_replace('-',' ',$commport));
        $commport_list = explode(' ',$commport);

        return $commport_list;
    }

    function baud_list() {

        $baud_list = array(
            '2400',
            '4800',
            '9600',
            '19200',
            '38400',
            '57600',
            '115200',
            '230400',
        );

        return $baud_list;
    }

if(isset($_POST['comm'])) {

    if($_POST['comm']=='None') {
        echo 'Your comm-port not active.Check your connection<br />
        (My computer right click - Properties - Hardware - Device Manager - Ports (COM & LPT))<br />
        If your comm-port is active make sure that it is not being used';
    } else {
        echo 'Port = '.$_POST['comm'].'<br /> Baud Rate = '.$_POST['baud']."<br/>Port Open.";

    }


} else {

    $commport_list = comm_list();
    $baud_list = baud_list();

    $count = count($commport_list);
    $count2 = count($baud_list);

    echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">
    Port <select name="comm">';
    for($i=0;$i<$count;$i++) {
        echo '<option value="'.$commport_list[$i].'">'.$commport_list[$i].'</option>';  
    }
    echo '</select> Baud Rate <select name="baud">';
    for($i=0;$i<$count2;$i++) {
        echo '<option value="'.$baud_list[$i].'">'.$baud_list[$i].'</option>';  
    }
    echo '</select> <input type="submit" value="Select" />
    </form>
    <hr />';

}

?>
  • Controllable port list

1.png

  • If port 2400 is open

2.png

  • If port 4800 is open

3.png

  • If port 9600 is open

4.png

  • If pot 19200 is open

5.png

  • If port 38400 is open

6.png

  • If port 57600 is open

7.png

  • If port 115200 is open

8.png

  • If port 230400 is open

9.png

Github url : https://github.com/eresbos/commportchecker



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Your contribution cannot be approved yet. See the Utopian Rules. Please edit your contribution to reapply for approval.

You are required to write the description of the project or the work you have done. Submitting the code is not enough.

You may edit your post here, as shown below:

You can contact us on Discord.
[utopian-moderator]

You say edited but I do not see a visible change in the length of the description. It appears to me that nothing changed. You also repeat yourself in the text.

If an error occurs when a device is added, if an error occurs when a device is added.You can solve it more quickly.

sorry, edited again.

Congratulations @eresbos! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

You made your First Comment
You got a First Vote

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

Approved. This is your first contribution. The development contributions should be for active projects that are active and are valuable for the open-source community. Well documented and it should be seen why it is useful. Short snippets and common codes that could be found on Internet are not welcome and may be rejected.

You can contact us on Discord.
[utopian-moderator]

Hey @eresbos I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • This is your first accepted contribution here in Utopian. Welcome!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x