2013年6月10日 星期一

How to install the NGO common library

1.  請下載兩個檔案

  • NGO_CL_Installer.msi
  • setup.exe

2. 安裝步驟如下:

2.1 啟動安裝精靈
    NGO_setup1

2.2 指定應用程式的根目錄 C:\rcm3app (請依實際目錄路徑)
    NGO_setup2

2.3 確認安裝
    NGO_setup3

2.4 安裝完成
    NGO_setup4

2.5 部置檔案目錄結構
    NGO_setup5

3. VC++專案, 請於專案屬性加入下述兩點路徑

  • Inlcude Path : c:\acl3app\src\common\inc
  • Library Path : c:\acl3app\lib

4. 即可進行專案編譯

2013年6月8日 星期六

How to pack NGO common library into a Installer

目前NGO common library完成度已接近80%, 起先顧及bug太多, 與方便修正的即時性,  皆先發佈source code給同仁編譯使用, 但這麼一來就容易造成版本的問題及維護整合的困難性

是該以library package的形式, 後續發佈給大家使用, 便想到以封裝成install檔案, 不知可行性如何??

經過實際試做後, 建議可以先針對下述兩點, 略做規劃:

第一. 要發佈哪些檔案??
1. common.lib              (NGO common library)
2. mqoa.dll                    (MSMQ library)
3. msado15.dll             (MS ADO library)
4. oncrpcms.dll            (ONC rpc library for MS)
5. oncrpc.dll                  (ONC rpc library)
6. head file

第二. 要如何配置目錄路徑
c:\rcm3app
                      ---> \lib                                  (存放*.dll and *.lib)
                      ---> \src\common\inc      (存放*.h)

Install_Directory

第三. 如何使用Visual Studio製作安裝檔?  (可以參考下列推薦網站連結唷!!)

2013年6月7日 星期五

手動設定 VS 2010 的 VC++ IncludePath/LibraryPath/OutputPath

在建立新專案時, 總是要逐一設定專案屬性的輸出目錄 / include目錄 / library目錄, 雖有複製貼上的神技, 但有沒有方法可以變成自行定義的預設初始化路徑...

只要編輯下述兩個檔案, 即可輕輕鬆鬆建立新專案

x86 (win32) : Microsoft.Cpp.Win32.v100.props
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32\PlatformToolsets\v100\Microsoft.Cpp.Win32.v100.props

x64 (win32) : Microsoft.Cpp.x64.v100.props
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Platforms\x64\PlatformToolsets\v100\Microsoft.Cpp.x64.v100.props

開啟編輯上述任一檔案時, 注意下面的文字結構, 黃色標示部份, 為自行定義加入的路徑變數, 存檔再重新開啟visual studio就可以看到, 已自動加入專案屬性的目錄路徑

<PropertyGroup>
<OutDir>$(AppBinPath)\</OutDir>
<IncludePath Condition="'$(IncludePath)' == ''">$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSdkDir)include;$(FrameworkSDKDir)\include;$(AppDirPath)\src\common\inc;$(AppDirPath)\src\inc;</IncludePath>
<LibraryPath Condition="'$(LibraryPath)' == ''">$(VCInstallDir)lib\amd64;$(VCInstallDir)atlmfc\lib\amd64;$(WindowsSdkDir)lib\x64;$(AppDirPath)\lib;$(AppDirPath)\src;$(AppDirPath)\src\common\dll;</LibraryPath>
</PropertyGroup>

參考來源 :: http://idaiwan.pixnet.net/blog/post/30789152

How to use IniHandler??

1. 作為讀取參數設定檔之用途

2. INI file format (內容嚴禁空白)
[SectionName]
key=value
[Host]
ipaddress=192.168.19.1
port=9999
[RCM3]
ipaddress=192.168.19.2
port=8888


PS: 將上述(2)內容存檔於C:\ipaddress.ini

ex:
#include “IniHandler.h”

main (void)
{
/* 建立 INI file handler */
IniHandler ini_hand;

/* 打開INI file */
ini_hand.open ("c:\\ipaddress.ini");

/* 讀取所有的Section Name */
vSectionNames_T names = ini_hand.readSectionNames ();

vSection_T section;
/* 逐一以Section Name, 讀取該Section內所有的key value */
for (int i=0; i<(int)names.size(); i++) {
    ap_log (DBUG, "get the tag %s", names[i].c_str());

    section.clear ();
    /* 帶入section name, 讀取 key-value */
    section = ini_hand.readKeyValues ((char *)names[i].c_str());

    /* 逐一印出key-value */
    for (int j=0; j<(int)section.size(); j++) {
        ap_log (DBUG, "key = %s, values = %s", section[j].key, section[j].value);
    }
}
/* 關閉 INI file */
ini_hand.close ();
}

2013年3月24日 星期日

Windows Server 2008 R2 無法安裝 Visual Studio 2010 : VC 9.0 runtime error code 1603


安裝好Windows Server 2008 R2後, 話不多說, 接著安裝Visual Studio 2010, 沒想到第一個組件 VC 9.0 runtime 就發生問題了, Google 前輩們的解決方法, 執行以下的動作, 終於安裝成功 (卻也花費了半天的早上)



  1. 於控制台中, 新增/移除程式的項目中, 卸除microsoft visual C++ 2008 redistributable
  2. 於執行中, 鍵入%temp%, 清除該資料夾的一切內容
  3. 啟用Windows Modules Installer服務, 於執行鍵入regedit, 移動於HKEY_LOCAL_MACHNE\System\CurrentControlSet\Control的目錄中, 查看右側內容, 有無RegistrySizeLimit, 若沒有, 則新增該值, 內容為16進位的0xFFFFFFFF
  4. 重新啟動Windows Modules Installer服務, 並改為自動


做完上述的動作後, 記得重新開機, 另注意Visual Studio 2010的原始安裝檔的權限, 建議以Administrators進行安裝



2013年1月29日 星期二

How to use TimerHandler ??

  1. 建議以process專屬的MQ, 設置定時器, 儘可能避免以外部process進行定時器的設置, 造成日後難以追查觸發的來源或控管不易
  2. 建議有限度地新增定時觸發事件, 以避免降低系統效能

#設置計時器, 以給定的MQ為觸發對象
TimerHandler::TimerHandler (char *mq_name);
  mq_name: process專屬的MQ名稱

ex:
TimerHandler timer (MQ_EDPLCRCV);

#新增定時觸發事件
TimerHandler::add (char *tm_name, int msec, int msg_id, void *msg, int msg_size);
  tm_name: 定時事件名稱
  msec : 間隔時間 (毫秒 milli-seconds)
  msg_id: 觸發事件代碼
  msg: 觸發資料
  msg_size: 觸發資料長度

ex:
timer.add (“Timer_AliveMsg”, 30000, MSG_TIMER_ALIVEMSG, 0, 0);
timer.add (“Timer_Hello”, 30000, MSG_TIMER_HELLO, "hello world", strlen("hello world"));

#啟動/停止/重置
TimerHandler::set_enable (char *tm_name, bool run_it);
  tm_name: 定時事件名稱
  run_it: 啟動/重置(enable), 停止(disable)

ex:
timer.set_enable (“Timer_AliveMsg”, true);
timer.set_enable (“Timer_AliveMsg”, false);

#移除定時觸發事件
TimerHandler::remove (char *tm_name);
  tm_name: 定時事件名稱

ex:
timer.remove ("Timer_AliveMsg");

#設置間隔時間 (milli-seconds)
TimerHandler::set_interval (char *tm_name, int msec);
  tm_name: 定時事件名稱
  msec: 間隔時間 (毫秒 milli-seconds)

ex:
timer.set_interval ("Timer_AliveMsg", 10000);

2013年1月5日 星期六

how to pass arguments to another process by using ApMsgHandler


鋼捲資料, ex:鋼捲號碼1830912, 厚度12mm, 重量3600kg

範例一.
試將參數化資料, 以MSMQ傳送至pdimgr

#將鋼捲資料, 以參數化方式送出至MSMQ
ApMsgHandler ApMQ = ApMsgHandler (MQ_SYS);
msginfo_body_T msg_body; memset (&msg_body, 0x00, sizeof(msginfo_body_T));
msg_body.argv[0].i16 = (short) 12;
msg_body.argv[1].i32 = (int) 3600
memcpy (msg_body.argv[2].chr, "1830912", 7);

ApMQ.send (MQ_PDIMGR, PdiMgrMsg::COILDATA, &msg_body);

#將鋼捲資料, 自MSMQ以參數化方式取出
ApMsgHandler ApMQ = ApMsgHandler (MQ_PDIMGR);
msginfo_body_T *pMsgData = (msginfo_body_T *)ApMQ.getMsgArg();

short thickness   = pMsgData->argv[0].i16;
int wgt = pMsgData->argv[1].i32;
char coilid[12] = "";
strcpy (coilid, pMsgData->argv[2].chr);

 

範例二.
試將連續性或結構性資料, 以MSMQ傳送至pdimgr

struct PDI {
    char coilid[12];   // 鋼捲號碼
    int     thk;            // 厚度
    int     wgt;           // 重量
};

#將鋼捲資料, 以結構性方式送出至MSMQ

ApMsgHandler ApMQ = ApMsgHandler (MQ_SYS);
struct PDI pdi_data;
memcpy (pdi_data.coilid, "1820912", 7);
pdi_data.thk = 12;
pdi_data.wgt = 3600;

ApMQ.send (MQ_PDIMGR, EP01, &pdi_data, sizeof(pdi_data));

#將鋼捲資料, 自MSMQ以結構性方式取出
ApMsgHandler ApMQ = ApMsgHandler (MQ_PDIMGR);
struct PDI *ptr = (struct PDI*)ApMQ.getMsgArg();

struct PDI pdi_data;
memcpy (&pdi_data, ptr, sizeof(pdi_data));