顯示具有 ApMsgHandler 標籤的文章。 顯示所有文章
顯示具有 ApMsgHandler 標籤的文章。 顯示所有文章

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));

2012年12月31日 星期一

到底是誰殺了PDI??

到底是誰殺了PDI??
每當程控資料一有異常時, 系統工程員就要準備接受挑戰, 因為現場人員幾乎會先認定是系統問題, 當你查明確定是由HMI以人工作業方式觸發後, 現場人員又會挑釁你, 到底是哪台電腦動了殺機, 這下頭大了, 只能像福爾摩斯一樣, 逐一查明各個HMI的log, 找出所使用的殺人兇器  (重點是還會被疑犯案過程是造假的...)

圖一. 犯案流程
 
舉例: 在現有架構下,  當HMI下達刪除鋼捲PDI後 (如上圖一)
(1) 以~xxxxx^xxxxx^xxxxx^xxxxx&的訊息格式, 通知server (此時記錄著pc name)
(2) pccomm解譯上述(1)訊息格式後, 通知distribution (此時記錄著pc name)
(3) distribution依據訊息代碼, 決定分派至schmgr (此時記錄著pc name)
(4) schmgr確認該鋼捲PDI沒有被排程鎖定後, 通知pdimgr (此時抹滅掉pc name)
(5) pdimgr被通知殺了該鋼捲PDI (此時已無pc name)
(6) pdimgr將該犯案事件寫入資料庫, 但是誰殺的?? 演變成一齣懸案
 

原來是現有架構成了幫兇, 各個後端程式皆是以MSMQ進行作業流程的觸發點, pccomm & distribution是既定的公用程式, 故HMI的pc name皆得以保留記錄 (可以規範記錄兇手)

但schmgr & pdimgr仍由系統人員開發, 除非佛心來著, 每每要將HMI的pc name, 額外記錄於要通知其它程式的MSMQ, 若有一個疏忽, 毀了屍滅了跡, 就讓兇手逍遙法外了

現有架構各個程式的作業模式如下:
recieve from MSMQ >> do some activity >> send to MSMQ or not
當接收一個message後, 進行某些活動, 再傳送另一個message給其它程式
試想, 當傳送一個message時, 從已接收的message中, 將pc name擷取出來, 記錄於其中, 應該就可行囉!
 
最後, 哪到底是誰殺了PDI?? 請愛用ApMsgHandler::getClntName (), 因為兇手就藏在細節裡

changeset#4