jQuery + PHP +串行通信

am facing trouble getting a return value through the below ajax call the function is sending the parameters to the php file and working fine but this is not getting a return value

        $(document).ready(function(){


            $state = "greenoff";
            $('input[type="checkbox"]').click(function()
                {
                    if($(this).is(":checked")){
                     $state = "greenon";
                }
                else if($(this).is(":not(:checked)")){
                        $state = "greenoff";

                }
                $.ajax({
                    type: "POST",
                    url: "led.php",
                    data: { 'action': $state }
                })
                .done(function(msg) {
                    alert( "Data Saved: " + msg );
                });

            }); 

            }


);

my php code is as follows

<?php 

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

    require("php_serial.class.php"); 
    $serial = new phpSerial(); 
    $serial->deviceSet("/dev/ttyACM0");  
    $serial->confBaudRate(9600); //Baud rate: 9600
    $serial->confParity("none");  //Parity (this is the "N" in "8-N-1")
    $serial->confCharacterLength(8); //Character length     (this is the "8" in "8-N-1")
    $serial->confStopBits(1);  //Stop bits (this is the "1" in "8-N-1")
    $serial->confFlowControl("none");
    $serial->deviceOpen(); 
    sleep(2);
    if ($_POST['action'] == "greenon") { 
        $serial->sendMessage("H"); 
        $read = $serial->readPort();
        echo $read;         
    } else if ($_POST['action'] == "greenoff") { 
        $serial->sendMessage("L"); 
        $read = $serial->readPort();
        echo $read;

    }
        } 


?>

Break your PHP file up into sections, and abend it with die('I am here 01') etc at various points in your PHP file.

That will allow you to see how far you are getting, and to identify the exact point where the trouble starts.

The first test is just to replace your PHP code with:

<?php
die('Got to here');

Your AJAX code block should echo that message. If it does not, then ajax isn't even happening.