2015年3月26日 星期四

USBeacon Sample by Android Studio

Ref: USBeacon Demo Sample

Import non-Android studio project and make a copy into work space.
匯入Android Studio Project,須依據Android studio架構處理,在Java目錄下的Layout非有效目錄,請在res目錄下調整。



2015年3月25日 星期三

錯誤1907。Error 1907. Could not register font. Verify that you have sufficient permissions to install font.

Ref:http://answers.microsoft.com/en-us/windows/forum/windows_7-windows_programs/error-1907-could-not-register-font-verify-that-you/57f3a671-feec-4dc7-873c-bb2a7de9521f

1. ASUS X450J Windows 10 Preview
2. 2015-3-26 更新後開啟 Access 2010 發生錯誤 1907。
3. 參考ref,sfc /scannow  by administrator 失敗。
4. Office2010安裝光碟(iso檔)解壓縮ProPsWW/ProPsWW2 @ xH:\x86\ProPlus.WW
5. Copy *.TTF into C:\Windows\Fonts

2015年3月22日 星期日

Android Bluetooth Le Gatt - Show RSSI

1. Add RSSI Textview @ listitem_device.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="wrap_content">
    <TextView android:id="@+id/device_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="24dp"/>
    <TextView android:id="@+id/device_address"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="12dp"/>
    <TextView android:id="@+id/device_RSSI"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="12dp"/>
</LinearLayout>
2. Add java code in DeviceScanActivity.java
2-1 Add RSSIV as a global variable.
2-2 Add set RSSIV as global var and show it.
3. Result:




Android Bluetooth Le Gatt Testing

Ref:
1. Android Studio example Bluetooth Le Gatt
2. Hardware:
    ASUS X450J (Windows 10 Preview, Android Studio 1.0)
    ASUS Zenfone 6
Test procedure
1. Import sample

2. Check the main_activity

3. Run the example

4. Show the results on Zenfone 6.



2015年3月1日 星期日

Lego C#

Ref: http://legoev3.codeplex.com/documentation#References
1. Hardware:
    ASUS X450J (Windows 10 Preview)
    Lego EV3 (PortA : Left wheel, PortB: Right wheel

2. MainWindow.xaml
<Window x:Class="WPFLego1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" Closing="Window_Closing">
    <Grid Margin="0,0,340,237">
        <Button Name="前進" MouseEnter="前進_MouseEnter" MouseLeave="前進_MouseLeave" Content="前進" Margin="172,10,-172,-10" />
        <Button x:Name="後退" MouseEnter="後退_MouseEnter" MouseLeave="後退_MouseLeave" Content="後退" Margin="172,158,-172,-158" />
        <Button x:Name="左轉" MouseEnter="左轉_MouseEnter" MouseLeave="左轉_MouseLeave" Content="左轉" Margin="-10,85,10,-85" />
        <Button x:Name="右轉" MouseEnter="右轉_MouseEnter" MouseLeave="右轉_MouseLeave" Content="右轉" Margin="354,85,-354,-85" />
    </Grid>
</Window>

3. MainWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Lego.Ev3.Core;
using Lego.Ev3.Desktop;
using System.Threading.Tasks;

namespace WPFLego1
{
    /// <summary>
    /// MainWindow.xaml 的互動邏輯
    /// </summary>
   
   
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            // Settings
            EV3B = new Brick(new BluetoothCommunication("COM7"));
            EV3B.BrickChanged += EV3B_BrickChanged;
            EV3B.ConnectAsync();
        }

        void EV3B_BrickChanged(object sender, BrickChangedEventArgs e)
        {
            for (int i = 0; i < e.Ports.Count; i++)
            {
                //this.Title += e.Ports[InputPort.A].SIValue.ToString();
            }
        }

        Brick EV3B;
        private void 前進_MouseEnter(object sender, MouseEventArgs e)
        {
            this.Title = "前進";
            EV3B.DirectCommand.TurnMotorAtPowerAsync(OutputPort.All, 50);

        }

        private void 前進_MouseLeave(object sender, MouseEventArgs e)
        {
            this.Title = "停止前進";
            EV3B.DirectCommand.TurnMotorAtPowerAsync(OutputPort.All, 0);
        }

        private void 後退_MouseEnter(object sender, MouseEventArgs e)
        {
            this.Title = "後退";
            EV3B.DirectCommand.TurnMotorAtPowerAsync(OutputPort.All, -50);

        }

        private void 後退_MouseLeave(object sender, MouseEventArgs e)
        {
            this.Title = "停止後退";
            EV3B.DirectCommand.TurnMotorAtPowerAsync(OutputPort.All, 0);
        }

        private void 左轉_MouseEnter(object sender, MouseEventArgs e)
        {
            this.Title = "左轉";
            EV3B.DirectCommand.TurnMotorAtPowerAsync(OutputPort.A, 50);
            EV3B.DirectCommand.TurnMotorAtPowerAsync(OutputPort.B, -50);

        }

        private void 左轉_MouseLeave(object sender, MouseEventArgs e)
        {
            this.Title = "停止左轉";
            EV3B.DirectCommand.TurnMotorAtPowerAsync(OutputPort.All, 0);
        }
        private void 右轉_MouseEnter(object sender, MouseEventArgs e)
        {
            this.Title = "右轉";
            EV3B.DirectCommand.TurnMotorAtPowerAsync(OutputPort.A, -50);
            EV3B.DirectCommand.TurnMotorAtPowerAsync(OutputPort.B, 50);

        }

        private void 右轉_MouseLeave(object sender, MouseEventArgs e)
        {
            this.Title = "停止右轉";
            EV3B.DirectCommand.TurnMotorAtPowerAsync(OutputPort.All, 0);
        }
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            EV3B.DirectCommand.StopMotorAsync(OutputPort.All, true);
            EV3B.Disconnect();

        }
    }
}

2015年2月18日 星期三

Python play a video file

Ref:http://www.thecodingforums.com/threads/python-help-sending-a-play-command-to-quicktime-or-playing-amovie-in-python.702701/

1.
import subprocess
subprocess.Popen(["open", "path/to/the/movie.file"])

2. Quicktimeplayer can not auto play
refhttp://www.defaults-write.com/quicktime-player-x-enable-auto-play-feature/#.VOWJ6bCUf6Y

defaults write com.apple.QuickTimePlayerX MGPlayMovieOnOpen 1

Disable autoplay

defaults write com.apple.QuickTimePlayerX MGPlayMovieOnOpen 0


Android tcp client (Send data from client and get server response) - II

This example show the interactive action between server and client.
1. tcpserver : Add print c.recv(1024) before send response in server side as follows
#!/usr/bin/python           # This is server.py file

import socket               # Import socket module

s = socket.socket()         # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12345                # Reserve a port for your service.
s.bind((host, port))        # Bind to the port

s.listen(5)                 # Now wait for client connection.
while True:
   c, addr = s.accept()     # Establish connection with client.
   print 'Got connection from', addr
   print c.recv(1024)
   c.send('Thank you for connecting')
   c.close()                # Close the connection  

2. tcpclient: Add send data before get response from server side.
Socket socket = null;

            try {
                socket = new Socket(dstAddress, dstPort);

                ByteArrayOutputStream byteArrayOutputStream =
                        new ByteArrayOutputStream(1024);
                byte[] buffer = new byte[1024];

                int bytesRead;
                DataOutputStream DOS = new DataOutputStream(socket.getOutputStream());
                DOS.writeUTF("手機送出訊息");
                InputStream inputStream = socket.getInputStream();

    /*
     * notice:
     * inputStream.read() will block if no data return
     */
                while ((bytesRead = inputStream.read(buffer)) != -1){
                    byteArrayOutputStream.write(buffer, 0, bytesRead);
                    response += byteArrayOutputStream.toString("UTF-8");
                }

            } catch (UnknownHostException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                response = "UnknownHostException: " + e.toString();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                response = "IOException: " + e.toString();
            }finally{
                if(socket != null){
                    try {
                        socket.close();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }