2008年7月9日 星期三

ARM-Linux下的Thread

在嵌入式系統上進行多執行緒開發時,如果明明Compiler可以過
可是卻連最簡單的多執行緒Sample都會踏到記憶體去當掉,這時候可以在pthread_create之前先呼叫pthread_mutex_init。另外,多執行緒在Compiler時請務必加入-lpthread的指令。

(此問題在arm-linux-gcc時不會遇到,在arm-linux-g++時才會出現,一樣的程式碼。)



#include <pthread.h&rt;
#include <iostream&rt;
using namespace std;

pthread_mutex_t mutex;
void *MyThread(void *dammy);
int main(){
   pthread_t thread;
   pthread_mutex_init(&mutex,NULL);
   pthread_create(&thread,NULL,MyThread,NULL);
   while(1){
       //printf("main\n");
       cout << "main" << endl;
       sleep(3);
   }
}
void *MyThread(void *dammy){
   while(1){
      //printf("Threah");
      cout << "Thread" << endl;
      sleep(1);     
   } 
}

2008年4月14日 星期一

mini_httpd的安裝

mini httpd是linux上一套小巧好用的web service
還支援SSL與CGI 有必要的話安裝php套件也可以支援到 這邊附上簡單的教學

在哪個目錄下操作的沒差,只是自己要知道路徑的位置
我這邊是在/usr下進行操作

STEP 1 :下載套件
[Shell]# wget http://www.acme.com/software/mini_httpd/mini_httpd-1.19.tar.gz
STEP 2 將套件解壓縮
[Shell]# tar zxvf mini_httpd-1.19.tar.gz
STEP 3 編譯並安裝套件
[Shell]# cd mini_httpd-1.19 <=進入解壓縮後產生的資料夾的資料
[Shell]# make <=編譯套件
[Shell]# make install <=安裝套件
STEP 4 查詢是否安裝成功
[Shell]# /usr/local/sbin/mini_httpd -V <= 執行安裝好的程式 參數 -V 表示顯示版本資訊
mini_httpd/1.19 19dec2003 <= 執行後的結果
STEP 5 建立存放網頁的資料夾
[Shell]# mkdir usr/mini_httpd
[Shell]# mkdir usr/mini_httpd/www
[Shell]# mkdir usr/mini_httpd/www/cgi-bin

or

[Shell]# mkdir -p usr/mini_httpd/www/cgi-bin
STEP 6 新增一個user, mini , 管理網頁資料夾
[Shell]# useradd mini
[Shell]# chown -R mini:mini usr/mini_httpd
STEP 7 撰寫mini-httpd的設定檔
[Shell]# su - mini
[Shell]#vi usr/mini_httpd/mini_httpd.conf
port=80
dir=/usr/mini_httpd/www
cgipat=cgi-bin/*
user=nobody
pidfile=/usr/mini_httpd/mini_httpd.pid
logfile=/usr/mini_httpd/mini_httpd.log
STEP 8 編輯index.htm
pico /usr/mini_httpd/www/index.htm
Hello world
STEP 9 啟動Web Server
[Shell]# /usr/local/sbin/mini_httpd -C /usr/mini_httpd/mini_httpd.conf
STEP 10 使用CGI
pico /usr/mini_httpd/www/cgi-bin/hello.c

#include <stdio.h>
int main(){
printf("Content-type: text/html\n\n");
printf(" \n");
printf(" CGI Output \n");
printf(" \n");
printf(" Hello, world. \n");
printf(" \n");
printf(" \n");
}
編輯好的檔案使用gcc hello.c -o hello.cgi

STEP 11 啟用帳號密碼認證
首先要先建立.htpasswd檔案
執行
htpasswd -c .htpasswd 帳號
然後會要你輸入密碼
完成後把.htpasswd這個檔案copy到mini_httpd的www資料夾下
就可以進行帳密認證

如果要讓mini_httpd在開機時能自動啟動
請到/etc/rc.local加上一行
/usr/local/sbin/mini_httpd -C /usr/mini_httpd/mini_httpd.conf


追加一點
mini_httpd預設的編碼是ISO-8859-1
奇怪的地方是,一般瀏覽器應該都會認meta內的charset
可是mini_httpd是不會的..
於是在mini_httpd.conf內寫上一行設定
charset=big5
就可以自動選擇編碼了
(當然你也可以用utf-8或者其他的編碼)

2008年3月22日 星期六

修改自動撥放時的動作清單

其實是我自己的撥放清單不知道為啥多了一些奇怪的東西(是亂碼)

所以龜毛心切的我就找出他的位置囉~

使用登錄編輯程式修改以下位置內的資料就好了

KEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers\Handlers\

2008年3月6日 星期四

撰寫網頁時Submit的技巧

在某些情況下不斷的點擊Submit可能會造成重複的新增資料,這時候就可以把Submit的按鈕進行以下的動作來達到disable的作用
在</head>跟<body>之間加上

<script language="ja<!>vascript">
function submitclick(obj)
{
obj.disabled=true;
this.document.post.submit();
}
</script>

之後,把Submot按鈕改成這樣↓

<input type="submit" value="送出" on<!>click="submitclick(this)">

或者直接一點<script>那邊不用打
直接把按鈕改成

<input type="submit" name="Submit" value="送出" on<!>click="this.disabled=true;document.post.submit();">


再把<form>加上name="post"
就可以了

2007年7月18日 星期三

如何用.NET發mail


'這裡需要一個Button

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim newMail As New System.Net.Mail.MailMessage
Dim ToAddress(,) As String = {{"to@yahoo.com.tw", "to"}, {"to@msa.hinet.net", "to"}}
Dim CCAddress(,) As String = {{"cc@yahoo.com.tw", "cc"}, {"cc@msa.hinet.net", "cc"}}
Dim BccAddress(,) As String = {{"bcc@yahoo.com.tw", "bcc"}, {"bcc@msa.hinet.net", "bcc"}}
Dim AttachFile() As String = {"C:\temp\123.xls", "C:\temp\456.xls"}
Dim smtpMail As New System.Net.Mail.SmtpClient

With newMail
.From = New System.Net.Mail.MailAddress("from@msa.hinet.net", "from") '寄件者
.Body = "Hello Every Body!!" '內文
.Subject = "測試資料!!" '主旨
.BodyEncoding = System.Text.Encoding.GetEncoding("BIG5") '編碼方式

For i As Int32 = 0 To ToAddress.GetUpperBound(1) '收信人
.To.Add(New System.Net.Mail.MailAddress(ToAddress(i, 0), ToAddress(i, 1)))
Next
For i As Int32 = 0 To CCAddress.GetUpperBound(1) '副本
.CC.Add(New System.Net.Mail.MailAddress(CCAddress(i, 0), CCAddress(i, 1)))
Next
For i As Int32 = 0 To BccAddress.GetUpperBound(1) '密件副本
.Bcc.Add(New System.Net.Mail.MailAddress(BccAddress(i, 0), BccAddress(i, 1)))
Next
For i As Int32 = 0 To BccAddress.GetUpperBound(1) '夾檔
.Attachments.Add(New System.Net.Mail.Attachment(AttachFile(i)))
Next
.IsBodyHtml = True '是否為HTML格式
.Priority = Net.Mail.MailPriority.Normal '優先權
End With
Try
smtpMail.Host = "msa.hinet.net"
smtpMail.SendAsync(newMail, "TEST")
Catch ex As Exception
MsgBox(ex.InnerException)
End Try
End Sub