当前位置:网站首页>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
help
Explanation 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.txt
Path to file :D:\CANoe-Demo\TestModule\FilePathFunc
- 2️⃣ Let's execute the following script , Note that the script file name is :
filePathFuncTest.can
anduserFilesTest.txt
At 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 thiscfg
The 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
help
Explanation 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
setFilePath
function , Directly operate thistest.ini
What 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.ini
There 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 thiscfg
The 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
setFilePath
perhapssetWritePath
. 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
setFilePath
function
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
getAbsFilePath
The function is very similar to , But it's different , For example, the following codegetUserFilePath
First, 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 locatedgetAbsFilePath
Open 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
CANoe
Operation of , Look at the output andUser Files
The configuration has automatically settest2.ini
File 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 gods
Free 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 .
边栏推荐
- Interview shock 62: what are the precautions for group by?
- 手把手教您怎么编写第一个单片机程序
- A wave of open source notebooks is coming
- [Yu Yue education] Wuhan University of science and technology securities investment reference
- Design and implementation of online snack sales system based on b/s (attached: source code paper SQL file)
- Take you back to spark ecosystem!
- leetcode-14. Longest common prefix JS longitudinal scanning method
- Global and Chinese markets for modular storage area network (SAN) solutions 2022-2028: Research Report on technology, participants, trends, market size and share
- [deep learning] semantic segmentation - source code summary
- What you have to know about network IO model
猜你喜欢
Mapreduce实例(四):自然排序
[deep learning] semantic segmentation: paper reading: (CVPR 2022) mpvit (cnn+transformer): multipath visual transformer for dense prediction
嵌入式开发比单片机要难很多?谈谈单片机和嵌入式开发设计经历
CANoe下载地址以及CAN Demo 16的下载与激活,并附录所有CANoe软件版本
51单片机进修的一些感悟
Redis distributed lock implementation redison 15 questions
Selection of software load balancing and hardware load balancing
Nc17 longest palindrome substring
tn-c为何不可用2p断路器?
[deep learning] semantic segmentation - source code summary
随机推荐
MySQL数据库优化的几种方式(笔面试必问)
MapReduce instance (IV): natural sorting
一大波开源小抄来袭
嵌入式开发中的防御性C语言编程
MapReduce working mechanism
How can I take a shortcut to learn C language in college
Can I learn PLC at the age of 33
Scoped in webrtc_ refptr
Redis分布式锁实现Redisson 15问
O & M, let go of monitoring - let go of yourself
Use of activiti7 workflow
硬件工程师的真实前途我说出来可能你们不信
One article read, DDD landing database design practice
在CANoe中通过Panel面板控制Test Module 运行(高级)
有软件负载均衡,也有硬件负载均衡,选择哪个?
Redis distributed lock implementation redison 15 questions
Why can't TN-C use 2p circuit breaker?
[Yu Yue education] reference materials of complex variable function and integral transformation of Shenyang University of Technology
Meituan Er Mian: why does redis have sentinels?
Global and Chinese markets for hardware based encryption 2022-2028: Research Report on technology, participants, trends, market size and share