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
(My computer right click - Properties - Hardware - Device Manager - Ports (COM & LPT))
If your comm-port is active make sure that it is not being used';
} else {
echo 'Port = '.$_POST['comm'].'
Baud Rate = '.$_POST['baud']."
Port Open.";
}
} else {
$commport_list = comm_list();
$baud_list = baud_list();
$count = count($commport_list);
$count2 = count($baud_list);
echo '.$_SERVER['PHP_SELF'].'" method="post">
Port ';
for($i=0;$i<$count;$i++) {
echo '.$commport_list[$i].'">'.$commport_list[$i].'';
}
echo ' Baud Rate ';
for($i=0;$i<$count2;$i++) {
echo '.$baud_list[$i].'">'.$baud_list[$i].'';
}
echo '
';
}
?>
- Controllable port list
- If port 2400 is open
- If port 4800 is open
- If port 9600 is open
- If pot 19200 is open
- If port 38400 is open
- If port 57600 is open
- If port 115200 is open
- If port 230400 is open
Github url : https://github.com/eresbos/commportchecker
Posted on Utopian.io - Rewarding Open Source Contributors