1.自定义指令发送和处理
发送自定义指令
| 函数 | RcResult CSecsEquip::SendSecsMsgAsync(int nStream, int nFunction, bool bReply, std::string pData, int64& nMsgID) |
| 用途 | 发送SECS消息 |
| 参数 | nStream:SECS消息的流编号。例如S1F1 |
| nFunction:SECS消息的功能编号。例如S1F1 | |
| bReply:是否需要答复消息 | |
| nMsgID:用于判断对方答复的标识位 | |
| pDdata:发送的数据 |
1.主动发送SECS消息,构造消息体的例子
string Code_1 = “L”;
string cData1_1 = listJoin(“A”, “2”);
string cData2_1 = listJoin(“A”, “4”);
string L12_1 = listJoin(Code_1.c_str(), cData1_1.c_str(), cData2_1.c_str());//最里层L2
string Code_2 = “L”;
string cData1_2 = listJoin(“A”, “2”);
string cData2_2 = listJoin(“A”, “4”);
string L12_2 = listJoin(Code_2.c_str(), cData1_2.c_str(), cData2_2.c_str());//最里层L2
string Code_3 = “L”;
string cData1_3 = listJoin(“A”, “2”);
string cData2_3 = listJoin(“A”, “4”);
string L12_3 = listJoin(Code_3.c_str(), cData1_3.c_str(), cData2_3.c_str());//最里层L2
string Code_4 = “L”;
string stringData = listJoin(Code_4.c_str(), L12_1.c_str(), L12_2.c_str(), L12_3.c_str());
int64 mesID = 0;
string Code_5 = “L”;
string stringData_1 = listJoin(Code_5.c_str(), stringData.c_str());
string pResult = “”;
string Code1 = “L”;
string A1 = listJoin(“A”, “2”);
string A2 = listJoin(“A”, “200”);
2.把整体的结构组合成字符串赋值给变量pResult
pResult = listJoin(Code1.c_str(), A1.c_str(), A2.c_str(), stringData_1.c_str());//最外层L3
3.把pValue赋值到变量pData中
m_pSecs->SendSecsMsgAsync(6, 3, true, pResult, mesID);
4.当发送该条指令时,会发送以下数据

2.回复自定义指令
特殊地,Host(MES/EAP)端会对标准指令格式进行增减操作,以符合实际作业要求,或发送自定义的SxFy,此时Equip端需要对非标格式解析、处理和回复。具体流程如下:
1.添加需要回复的指令
| 函数 | RcResult CSecsEquip::MessageTypeAdd(int nStream, int nFunction, SecsMessageReceiveProc pCallback, void* pClientData) |
| 用途 | SECS消息类型处理添加 |
| 参数 | stream:SECS消息的流编号。例如S1F1 |
| function:SECS消息的功能编号。例如S1F1 | |
| pCallback:SecsMessageReceiveProc委托 SecsMessageReceiveProc参数: Stream:SECS消息的流编号。例如S1F1 Function:SECS消息的功能编号。例如S1F1 send_reply:是否需要回复 transactionID: TSN_data:Host发来的数据 Header: | |
| pClientData |
使用MessageTypeAdd添加需要接收的指令,例如添加“S5F3”
MessageTypeAdd(5, 3, OnS5F3Proc, this)
2.声明回调函数:
示例:static void OnS5F3Proc(IMCHandle *, int64 stream, int64 function, bool send_reply, int64 transactionID, const char* TSN_data, const char* header, void *clientData)
3.定义回调函数:
示例:void CTianmaHandle::OnS5F3Proc(IMCHandle *, int64 stream, int64 function, bool send_reply, int64 transactionID, const char* TSN_data, const char* header, void *clientData) {
if (clientData != NULL)
{
CTianmaHandle* pTianmaeHandle = (CTianmaHandle*)clientData; pTianmaeHandle->OnS5F3Proc(stream, function, send_reply, transactionID, TSN_data, header);
}
}
4.处理回调函数内容:
示例: void CTianmaHandle::OnS5F3Proc(int64 stream, int64 function, bool send_reply, int64 transactionID, const char* TSN_data, const char* header)