当前位置:网站首页>Several silly built-in functions about relative path / absolute path operation in CAPL script
Several silly built-in functions about relative path / absolute path operation in CAPL script
2022-07-06 09:48:00 【Ant soldier】
Related articles

Preface
- CAPL About relative paths in scripts , Several silly built-in functions of absolute path operation
- Demonstrate hardware and software environment Win10 x64 ; CANoe 11 SP2 x64

Catalog

getAbsFilePath
- .
long getAbsFilePath(char relPath[], char absPath[], long absPathLen) - According to the following
helpExplanation of the document , According to the relative path of input , Output absolute path . - So here comes the question , The absolute path of the output , What is the root directory ?
- If the dead end path of the output , This path does not exist on the hard disk , Will you make a mistake ?

- 1️⃣ Note the following file
userFilesTest.txtPath to file :D:\CANoe-Demo\TestModule\FilePathFunc

- 2️⃣ Let's execute the following script , Note that the script file name is :
filePathFuncTest.cananduserFilesTest.txtAt the same directory
on key 'e'
{
char absPath[256];
long retVal;
retVal = getAbsFilePath("userFilesTest.txt", absPath, 256);
write ("absPath: %s ", absPath);
write ("retVal: %d ", retVal);
}
- 3️⃣ The output result shows that the return value of the function is
31, This indicates the return valueThe string length of the absolute path; In addition, the range value isD:\CANoe-Demo\userFilesTest.txt, Not expectedD:\CANoe-Demo\TestModule\FilePathFunc\userFilesTest.txt - The key is coming. :
1: The path of the return value does not exist on this machine , No mistake. ;
2: The composition of the absolute root directory is not based on this script as a reference root directory , But with thiscfgThe folder where the file is located is the root directory

- 4️⃣ So we want to get the exact absolute pathname , It's going to take cfg The file is in the root directory , Then write the relative path , As shown in the following figure :
on key 'f'
{
char absPath[256];
long retVal;
retVal = getAbsFilePath("TestModule\\FilePathFunc\\userFilesTest.txt", absPath, 256);
write ("absPath: %s ", absPath);
write ("retVal: %d ", retVal);
}

setFilePath
- .
void setFilePath (char Path[],dword mode); - According to the following
helpExplanation of the document , That is, when there is an operation on a file, you should first set the file path to be operated - So here comes the question , When I read and write files , Is this function necessary ? What happens if you don't write ?

- 1️⃣ Look at the path and location of the following file

- 2️⃣ We won't add
setFilePathfunction , Directly operate thistest.iniWhat about the file ?
on key 'g'
{
long retVal;
// write in INI file function
retVal = writeProfileInt ("setting", "parameter_1", 8, "test.ini");
write ("retVal: %d ", retVal);
}
- 3️⃣ The output result shows that the return value of the function is
1, This indicates that the function was executed successfully , howevertest.iniThere is no information in the file - The key is coming. :
1: The path of the return value does not exist on this machine , No mistake. ;
2: The root directory that makes up the absolute path does not take this script as the reference root directory , But with thiscfgThe folder where the file is located is the root directory

- 4️⃣ stay The open cfg Found test.ini file , And write the value , This means that , If you enter the file name directly , If cfg There is no such file under the file , Then write will be created directly .

- 5️⃣ OK, Write the file name directly , No path found , Then I can fill in the absolute path
on key 'h'
{
long retVal;
// write in INI file function
// Write the absolute path directly ?
retVal = writeProfileInt ("setting", "parameter_1", 8, "D:\\CANoe-Demo\\TestModule\\FilePathFunc\\test.ini");
write ("retVal: %d ", retVal);
}
- 6️⃣ what ? The return value is 0, It's not going to work ; It turns out that if the path of the file to be operated is not set in advance , It has to be a relative path , Absolutely no way .


- 7️⃣ This time we set the relative path
on key 'j'
{
long retVal;
// write in INI file function
// If the file operation path is not set in advance , Relative paths must be used
retVal = writeProfileInt ("setting", "parameter_1", 8, "TestModule/FilePathFunc/test.ini");
write ("retVal: %d ", retVal);
}
- 8️⃣ It did , But if the file I want to operate is not there D disc , And also cfg There is no relative relationship between files , How to do that ?, It seems that it must be used
setFilePathperhapssetWritePath. Talent
- 9️⃣ I'm not convinced , Is there really no way to get it ? Must compromise first set
setFilePath? Look at the picture below , There's another way ,
Configuration|Options|Extensions|User Files Add the files to be operated ,
Note here , You cannot add a quotation with the same file name , Even if the path is different
- Then directly operate on the file name
on key 'l'
{
long retVal;
retVal = writeProfileInt ("setting", "parameter_1", 8, "test.ini");
write ("retVal: %d ", retVal);
}
- The test results are as follows , It can be successful ;

- 1️⃣1️⃣ After the trial and error of the previous steps , For the applicability of the code , Let's not struggle , It's better to add
setFilePathfunction
on key 'k'
{
long retVal;
setFilePath("E:\\FilePathFunc", 1);
retVal = writeProfileInt ("setting", "parameter_1", 8, "test.ini");
write ("retVal: %d ", retVal);
}
- 1️⃣2️⃣ The test results are as follows ;

setWritePath
setWritePath yes setFilePath A subset of functions
getUserFilePath
- . Look at the picture below help file

1️⃣ The sum of this function
getAbsFilePathThe function is very similar to , But it's different , For example, the following codegetUserFilePathFirst, in the user files Inside ( In the screenshot above , Added ) seek , eureka , Just return the absolute path of this file
Open it if you can't find it cfg Go to the price folder directory where the document is locatedgetAbsFilePathOpen it directly cfg Go to the price folder directory where the document is located , If you can't find it, you will report an error .
on key 'z'
{
char absPath[256];
long retVal;
retVal = getUserFilePath("test.ini", absPath, 256);
write ("getUserFilePath absPath: %s ", absPath);
write ("getUserFilePath retVal: %d ", retVal);
retVal = getAbsFilePath("test.ini", absPath, 256);
write ("getAbsFilePath absPath: %s ", absPath);
write ("getAbsFilePath retVal: %d ", retVal);
}
- 2️⃣ Look at the output , If you are free, you can user file stay option Take it out and try again to see what the result is

RegisterUserFile
- . Look at the picture below help file , Is in the form of code CANoe During operation, it can also be in user Files Add files to

- 1️⃣ Look directly at the code , Execute and see the results
on key 'x'
{
char absPath[256];
long retVal;
retVal = RegisterUserFile("E:\\FilePathFunc\\test2.ini",0);
write ("getUserFilePath retVal: %d ", retVal);
retVal = getUserFilePath("test2.ini", absPath, 256);
write ("getUserFilePath absPath: %s ", absPath);
write ("getUserFilePath retVal: %d ", retVal);
}
- 2️⃣ stop it
CANoeOperation of , Look at the output andUser FilesThe configuration has automatically settest2.iniFile added




summary

- Have the most simple life , The furthest dream , Even if it's freezing tomorrow , Lu Yao's horse died !
- Wechat partners can pay attention Langge on-board diagnosis , A small circle in the industry , In the group
SkyDrive data,Source code,There are all kinds of godsFree time communication technology , Talk about job opportunities .- If this blog is helpful to you , please “ give the thumbs-up ” “ Comment on ”“ Collection ” One key, three links Oh ! It's not easy to code words , Everyone's support is my driving force to stick to it .
边栏推荐
- Design and implementation of online shopping system based on Web (attached: source code paper SQL file)
- MapReduce instance (V): secondary sorting
- [untitled]
- Single chip microcomputer realizes modular programming: Thinking + example + system tutorial (the degree of practicality is appalling)
- Keep these four requirements in mind when learning single chip microcomputer with zero foundation and avoid detours
- June brush question 02 - string
- Redis connection redis service command
- CAPL 脚本打印函数 write ,writeEx ,writeLineEx ,writeToLog ,writeToLogEx ,writeDbgLevel 你真的分的清楚什么情况下用哪个吗?
- 018.有效的回文
- Oom happened. Do you know the reason and how to solve it?
猜你喜欢

Use of activiti7 workflow

If a university wants to choose to study automation, what books can it read in advance?

Mapreduce实例(八):Map端join

Selection of software load balancing and hardware load balancing

Regular expressions are actually very simple

Hero League rotation map automatic rotation

Mapreduce实例(六):倒排索引

How can I take a shortcut to learn C language in college

听哥一句劝,按这套嵌入式的课程内容和课程体系去学习

Keep these four requirements in mind when learning single chip microcomputer with zero foundation and avoid detours
随机推荐
Activiti7工作流的使用
Leetcode:608 树节点
MySQL数据库优化的几种方式(笔面试必问)
嵌入式中的合作开发--函数指针
为什么要数据分层
How can I take a shortcut to learn C language in college
Publish and subscribe to redis
为什么大学单片机课上51+汇编,为什么不直接来STM32
在CANoe中通过Panel面板控制Test Module 运行(高级)
Workflow - activiti7 environment setup
June brush question 01 - array
A wave of open source notebooks is coming
Research and implementation of hospital management inpatient system based on b/s (attached: source code paper SQL file)
英雄联盟轮播图手动轮播
CAPL 脚本对.ini 配置文件的高阶操作
Teach you how to write the first MCU program hand in hand
大学想要选择学习自动化专业,可以看什么书去提前了解?
一文读懂,DDD落地数据库设计实战
Detailed explanation of cookies and sessions
MapReduce instance (VI): inverted index
