Hiển thị code dạng highlight trên wordpress.com

Chi tiết tại http://en.support.wordpress.com/code/posting-source-code/

Ta sẽ đặt dòng code trong shortcode …. Chú ý nếu sử dụng Window Live Writer thì thêm tag <pre></pre> bao lấy tất cả.

Các ngôn ngữ được hỗ trợ gồm có

  • actionscript3
  • bash
  • coldfusion
  • cpp
  • csharp
  • css
  • delphi
  • erlang
  • fsharp
  • diff
  • groovy
  • html
  • javascript
  • java
  • javafx
  • matlab (keywords only)
  • objc
  • perl
  • php
  • text
  • powershell
  • python
  • r
  • ruby
  • scala
  • sql
  • vb
  • xml
/*
 * WheelsSpeedGUIApp.java
 */

package wheelsspeedgui;

import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;

/**
 * The main class of the application.
 */
public class WheelsSpeedGUIApp extends SingleFrameApplication {  
    /**
     * Main method launching the application.
     */
    public static void main(String[] args) {
        launch(WheelsSpeedGUIApp.class, args);
    }
}

Sửa lỗi “The File or Directory Is Corrupt…”

http://support.microsoft.com/kb/176646

  1. Click Start, and then click Run.
  2. In the Open box, type chkdsk /f <drive>:, where <drive> is the letter of the drive on which the damaged file, folder or file system index exists.
  3. Click OK.

Giao tiếp SerialPort(COM)-PC sử dụng thư viện rxtx trong Java

Ngôn ngữ Java mặc định không hỗ trợ các giao tiếp cụ thể như SerialPort, USB… vì lý do đa nền tảng. Ví dụ PC hầu hết có cổng COM, USB nhưng các thiết bị di động như điện thoại chưa chắc có những cổng này. Tuy nhiên có rất nhiều thư viện mã mở giúp cho công việc giao tiếp trong java được thuận tiện hơn. Ví dụ trong đó là package javax.comm, rxtx. Javax.comm đã thử trên win7 nhưng không hoạt động Winking smile, chuyển sang rxtx thấy cũng hay và đáp ứng được những yêu cầu đặt ra.

Rxtx có thể được download tại http://rxtx.qbang.org/wiki/index.php/Download . Sau khi dowload về máy tính, ta lần lượt coppy các file của thư viện vào thư mục hệ thống của jdk:

  • rxtxSerial.dll tới thư mục <jdk_install>jrebin
  • RXTXcomm.jar tới thư mục <jdk_install>jrelibext

đồng thời không quên add RXTXcomm.jar tới project và thêm import gnu.io.*;.

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wheelsspeedgui;

/**
 *
 * @author ThanhBinh
 */
import java.util.*;
import gnu.io.*;

import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;

///
public class SerialCommunication extends Observable {
    private SerialPort serialPort;
    private OutputStream outStream;
    private InputStream inStream;
    private IDataSerial main;
    
    public SerialCommunication(IDataSerial mainFrm){
        main = mainFrm;
    }
    public String[] listSerialPorts() {
        Enumeration ports = CommPortIdentifier.getPortIdentifiers();
        ArrayList portList = new ArrayList();
        String portArray[] = null;
        while (ports.hasMoreElements()) {
            CommPortIdentifier port = (CommPortIdentifier) ports.nextElement();
            if (port.getPortType() == CommPortIdentifier.PORT_SERIAL) {
                portList.add(port.getName());
            }
        }
        portArray = (String[]) portList.toArray(new String[0]);
        return portArray;
    }
    public boolean Connect(String portName) throws IOException, TooManyListenersException {
        try {
            // Obtain a CommPortIdentifier object for the port you want to open
            CommPortIdentifier portId =
                    CommPortIdentifier.getPortIdentifier(portName);

            // Get the port's ownership
            serialPort = (SerialPort) portId.open("Demo application", 5000);

            // Set the parameters of the connection.
            setSerialPortParameters();

            // Open the input and output streams for the connection.
            // If they won't open, close the port before throwing an
            // exception.
            outStream = serialPort.getOutputStream();
            inStream = serialPort.getInputStream();
            addDataAvailableListener(new SerialPortEventListener(){
                public void serialEvent(SerialPortEvent spe) {
                    switch (spe.getEventType()) {
                    case SerialPortEvent.DATA_AVAILABLE:
                   // readSerial();
                       // System.out.println("new datan");
                        HasData_Event();
                    }
                    throw new UnsupportedOperationException("Not supported yet.");
                }
                });
            return true;
        } catch (NoSuchPortException e) {
            return false;
           // throw new IOException(e.getMessage());            
        } catch (PortInUseException e) {
            //throw new IOException(e.getMessage());
            return false;
        } catch (IOException e) {
            serialPort.close();
            return false;
            //throw e;
        }
    }
    protected void setSerialPortParameters() throws IOException {

        final int baudRate = 9600; // 9600bps
        try {
            // Set serial port to 57600bps-8N1..my favourite
            serialPort.setSerialPortParams(
                    baudRate,
                    SerialPort.DATABITS_8,
                    SerialPort.STOPBITS_1,
                    SerialPort.PARITY_NONE);
            serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
        } catch (UnsupportedCommOperationException ex) {
            throw new IOException("Unsupported serial port parameter");
        }
    }
    public void Disconnect() {
        if (serialPort != null) {
            try {
                // close the i/o streams.
                outStream.close();
                inStream.close();
            } catch (IOException ex) {
                // don't care
            }
            // Close the port.
            serialPort.removeEventListener();
            serialPort.close();
            serialPort = null;
        }
    }
    
    public boolean WriteBytes(byte[] data){
        boolean success = false;
        try {
            outStream.write(data);
            success = true;
        } catch (IOException ex) {
            
        }
        return success;
    }

    private void addDataAvailableListener(SerialPortEventListener dataAvailableListener)
            throws TooManyListenersException {
        // Add the serial port event listener
        serialPort.addEventListener(dataAvailableListener);
        serialPort.notifyOnDataAvailable(true);
    }
    private byte[] GetBytes(){
        byte[] empty={};
        try {
            int availableBytes = inStream.available();
            if (availableBytes > 0) {
                    // Read the serial port
              byte[] readBuffer = new byte[availableBytes];
              inStream.read(readBuffer, 0, availableBytes);
              return readBuffer;
            }
         } catch (IOException e) {
             return empty;
         }
        return empty;
    }
    public void HasData_Event(){
           byte[] data = GetBytes();
           main.HasData_Event(data);
    }

}
 

Tổng quan về ngôn ngữ VHDL

VHDL là viết tắt của Very high speed integrated cricuit Hardware description language – ngôn ngữ miêu tả phần cứng. Phiên bản thường dùng là VHDL-87.

VHDL sử dụng kiểu tư duy top-down để thiết kế các hệ thống số. Một hệ thống lớn được phân tích thành nhiều thành phần nhỏ có thể dễ dàng thiết kế và kiểm thử. Việc mô tả hệ thống trở thành mô tả mối quan hệ giữa các thành phần nhỏ gọi là entity và hành vi của các entity đó.

Mỗi entity giống như một class trong ngôn ngữ lập trình cấp cao(giống cú pháp nesC). Một entity bao gồm một khai báo và phần mô tả hành vi của entity.

Khai báo hành vi của entity có thể theo ba cách, structure, dataflow và behavioral. trong đó structure mô tả các kết nối phần cứng của mạch điện tử, dataflow mô tả các hàm logic và behavioral mô tả tư duy giống như các ngôn ngữ lập trình khác.

VHDL có ba cách khai báo dữ liệu là :

  1. Signal: mô hình hóa tín hiệu trong mạch.
  2. Variable: biến được dụng trong process
  3. Constant

Với các kiểu dữ liệu bit, std_logic, integer, float…

By ngothanhbinh.pfiev Posted in FPGA Thẻ

Giới thiệu về Xilinx ISE Design Suite 13.2

Xilinx ISE là một môi trường phát triển cho FPGA và GPLD của hãng Xilinx. Phần mềm được download tại trang chủ (http://www.xilinx.com/support/download/index.htm), bản full window có dung lượng 4.57 GB (Link trực tiếp). Nên lựa chọn cài đặt bản Webpack với file license lấy tại http://www.xilinx.com/getlicense (yêu cầu đăng nhập), với dung lượng sau khi cài khoảng 10GB.

Phần mềm hỗ trợ ngôn ngữ VHDL-87 và VHDL-2x với công cụ mô phỏng.

Thao tác đóng cổng kết nối SerialPort trong C#

Lớp SerialPort cung cấp phương thức Close() có nhiệm vụ đóng kết nối tới cổng COM trên máy tính. Tuy nhiên do sự hoạt động của lớp này sẽ được thi hành trên một luồng riêng biệt nên dễ gây những lỗi dẫn đến treo chương trình. Đoạn mã sau giải quyết vấn đề trên:

   1: private void CloseSerialPortInWorkerThread()

   2:     {

   3:         ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc));

   4:     }

   5: private void ThreadProc(Object stateInfo)

   6:     {

   7:         if (this._mySerialPort.IsOpen == true)

   8:             this._mySerialPort.Close();// Attempt to close serial port

   9:     }