Satu cara kilat ngebuffer serial dari BOE

Trik ini saya pakai untuk mengambil / membuat buffer agar bisa mengetahui input yang di berikan Boe ke PC.

Hasil dari pengambilan di masukkan ke TextBox1.Text agar dapat di baca. CR harus di konversikan menjadi CRLF agar lebih bagus tampilannya.

 

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Dim Buffer As String
    Dim temp As String
    If SerialPort1.IsOpen Then
        temp = StrConv(SerialPort1.ReadExisting, VbStrConv.ProperCase)

        Buffer = Buffer + temp

        Buffer = Replace(Buffer, Chr(13), Chr(13) + Chr(10), 1, Len(Buffer))

        TextBox1.Text = TextBox1.Text + Buffer

    End If
End Sub

Rakitan Board of Education

Project programming ke mikrokontroller yang pertama.

boe

so fun to implement, photoresistor sensor, IR detection and some sound generating.. hmm fun.

create some small Visual studio application to control the bot connecting the bot with EB500 bluetooth module, this is the result.

Memakai visual studio untuk interface ke komputer tanpa melalui serial cable. Dapat menampilkan hasil pembacaan dari mikrocontroller ke PC melalui media bluetooth EB500

inface

Mengambil informasi user pada komponen Auth 1.2.xx

kalau anda menggunakan auth pada cake 1.2.xx anda bisa mengambil informasi user dengan cara.

$this->Auth->user()

untuk mengambil seluruh data atau:

$this->Auth->user('field_name')

untuk mengetahui satu field saja

gunakan juga

$session->read('Auth.UserModelName') untuk mengambil data tsb

(gantu UserModelName sesuai kebutuhan)

atau $session->read('Auth.UserModelName.field_name')

khusus mengambil satu data

Controller tanpa model

 

Apabila ingin menggunakan controller tanpa menyentuh model apapun.. coba tips di bawah ini.

// tested with CakePHP r1892


class MyController extends AppController


{


    // var $uses = null; works too


    var $uses = array();


 


    function index()


    {


    }


}



kalau tidak akan keluar "missing model error"

Auth component in cake 1.2.6311

 

di User model di tambahkan baris seperti ini.

 

function validLogin($data)
   {

       $user = $this->find(array('username' => $data['User']['username'], 'password' => ($data['User']['password'])), array('id', 'username', 'password'));
       if(!empty($user)){
           $this->user = $user['User'];
           return TRUE;
       }
       else {
           return FALSE;
       }

   }

 

Di atas user_controller.php di tambahkan

var $components = array('Auth','Session');
var $layout = "login";

dan di bawah index tambahkan prosedur login.

   function login()
    {
        //user already logged in?
        //checking if session has been written
        $user_id = $this->Auth->user('id');
        if (!empty($user_id) && $this->Session->valid())
        {
            $this->Session->setFlash('You are already logged in');
            $this->redirect(array('action'=>''), null, true);
        }
        else
        {
            if(!empty($this->data))
            {
                //calling login validation validLogin() in model
                if($this->User->validLogin($this->data))
                {
                    if($this->Auth->login($this->User->user))
                    {
                        $this->Session->setFlash('You have successfully logged in');
                           $this->Session->write('LoggedIn',$this->Auth->user());

                        $this->redirect('/projects');
                    }

                } else {
                $this->Session->setFlash('Invalid login, try again!');
                $this->set('auth_msg', 'Invalid login, try again!');
                $this->set('password', null);                   
                }
            }
            else
            {
                $this->Session->setFlash('Please enter your username and password!');
                $this->set('auth_msg', 'Please enter your username and password');
                $this->set('password', null);
            }
        }

    }

    function logout()
    {
        $this->Session->destroy('user');
        $this->Session->setFlash('You\'ve successfully logged out.');
        $this->redirect('/users/login');
    }    
    function view($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid User.', true));
            $this->redirect(array('action'=>'index'));
        }
        $this->set('user', $this->User->read(null, $id));
    }

 

Pada view tambahkan satu file lagi. login.ctp

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>
        <?php __('Please Log-In'); ?>
        <?php echo $title_for_layout;?>
    </title>
    <?php
        echo $html->charset();
        echo $html->meta('icon');

        echo $html->css('cake.generic');

        echo $scripts_for_layout;
    ?>
</head>
<body>
    <div id="container">
        <div id="header">
            <h1><?php echo $html->link(__('Please Log-In', true), '');?></h1>
        </div>
        <div id="content">
            <?php
                if ($session->check('Message.flash')):
                        $session->flash();
                endif;
            ?>

            <?php echo $content_for_layout;?>

        </div>
        <div id="footer">
            <?php echo $html->link(
                            $html->image('cake.power.gif', array('alt'=> __("CakePHP: the rapid development php framework", true), 'border'=>"0")),
                            'http://www.cakephp.org/',
                            array('target'=>'_new'), null, false
                        );
            ?>
        </div>
    </div>
    <?php echo $cakeDebug?>
</body>
</html>

 

file ini di modifikasi dari default.ctp pada cake template skel

 

pada app_controller.php ada prosedur-prosedur yang membantu proses login. saya masukkan juga yang lainnya terutama untuk hal-hal yang membantu dalam penanganan session.

 

class AppController extends Controller {

    var $helper = array('Form','Session','Ajax','Javascript','Html');
    var $components = array('Auth','Session');

        function beforeFilter()
    {
        //actions we allow without authentication, you can also put them in the app_controller.php
       $this->Auth->allow('register', 'login', 'logout','add');
       $this->Session->write('params',$this->params);
       $this->set('mysession',$this->Session->read());  //this is for the ACL phpGACL
       $this->set('username',$this->Auth->user('username'));
       $this->set('controller_action',$this->params['controller'].'_'.$this->params['action'])        ;
       $this->set('refer',Controller::referer()); //referer

       $username = $this->Auth->user('username');
       $controller_action = $this->params['controller'].'_'.$this->params['action'];
    }
}

Merubah isi dari SELECT tag.

Di controller di tambahkan di bagian atas…

var $uses = array('Employee','Entry');

di dalam function controllernya menggunakan standard php trick aja.. kayaknya lebih gampang.

$tmpentry = $this->Entry->find('all');

$test = array('0'=>""); // untuk mengosongkan field no. 0 (karena id = 1)

foreach ($tmpentry as $item){

array_push($test, $item['Entry']['entry_name']);

}

$this->set('entry',$test);

Di View bisa di panggil dengan:

Echo $form->select(‘field_name’, $entry);

Sorry ini hanya akal-akalan untuk mempercepat proses design

Another Select Tag

Ini Juga bisa di pakai dalam controller apabila kepepet harus me-load model yang tidak berhubungan dengan yang seharusnya di pakai controller

App::import('Model', 'Entry');

$tmpEntry = new Entry();

$this->set('test',$tmpEntry->findAll());