上篇文章写到了如何在CAN OE上联动Pico Scope,属于手动操作。这边文章写如何使用Capl自动化调用Pico Scope。
建立Capl节点,不要建立net节点,会有很多函数用不了。
下面是代码,可以调用Pico Scope并且检查CAN H,CAN L和CAN Diff。
includes
{
}
variables
{
}
MainTest()
{
testcase01();
}
testcase testcase01()
{
dword arraySize = 2000;
message NM msg;//选择你要监控的报文
long res;
long evtNo;
ScopeBitData data1[200];
ScopeBitData data2[200];
ScopeBitData data3[200];
ScopeAnalysisSetup setupAnalyse;
//------------------------------
//Connect to scope
//------------------------------
res = scopeConnect();
res = testWaitForScopeEvent(eScopeConnected, 8000);
if(res > 0)
{
testStep("Wait For Event", "Waiting for NM Message");
testJoinMessageEvent(msg.id);
evtNo = TestWaitForAnyJoinedEvent(2000);
res = TestGetWaitEventMsgData(msg);
if(res != 0)
{
testStepFail("Wait For Event", "No event received");
res = scopeDisconnect();
res =testWaitForScopeEvent(eScopeDisconnected, 8000);
return;
}
else
{
testStepPass("Wait For Event", "Event received");
}
res = scopeTriggerNow();
if(res > 0)
{
res =(testWaitForScopeEvent(eScopeTriggered, 5000));
if(res > 0)
{
testStepPass("","test Wait For ScopeEvent success");
setupAnalyse.samplePoint = 80;
res = testWaitScopeGetMessageBits(msg, setupAnalyse, arraySize, data1, data2, data3);
write("testWaitScopeGetMessageBits=%d",res);
if(res > 0 || res == -105)
{
int i;
for(i = 0; i < arraySize;++i)
{
write("%d",i);
write("CANH: StarTime%.9f s, Type: %d, TypeExt: %d, BitLength: %d, Voltage: %.6f, BitValue: %d", data1[i].StartTime /1000000000., data1[i].type, data1[i].typeEx, data1[i].bitLength, data1[i].signalVoltage,data1[i].bitValue);
write("CANL: StarTime%.9f s, Type: %d, TypeExt: %d, BitLength: %d, Voltage: %.6f, BitValue: %d", data2[i].StartTime /1000000000., data2[i].type, data2[i].typeEx, data2[i].bitLength, data2[i].signalVoltage,data2[i].bitValue);
write("CANDiff: StarTime%.9f s, Type: %d, TypeExt: %d, BitLength: %d, Voltage: %.6f, BitValue: %d", data3[i].StartTime /1000000000., data3[i].type, data3[i].typeEx, data3[i].bitLength, data3[i].signalVoltage,data3[i].bitValue);
if(i > 5) //write only first 5 results
break; }
}
else
{
testStepFail("wait message","fail");
}
}
else
{
testStepFail("","test Wait For ScopeEvent Fail");
}
}
res = scopeDisconnect();
res =testWaitForScopeEvent(eScopeDisconnected, 8000);
}
}