labwindowscvi5 数据格式化、文件读取和IO端口操作
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
9/11
size_t Number_of_Elements, FILE *Stream); num = fwrite (data, 4096, 1024, fp);
2013-8-26
6. 路径应用(Directory Utilities)
•
• • • • •
2013-8-26
GetDir
int GetDir (char Current_Directory[]); i = GetDir (dir);
LabWindows/CVI教程(5)
文件和端口操作
主讲:乔立岩
Email: qiaoliyan@hit.edu.cn (交作业) MSN: qiaoliyan@msn.com(在线交流) Tel: 86413532 ext. 8611 (逸夫楼611)
自动化测试与控制研究所
1. 字符串操作
• Formatting and I/O-String Manipulation
2013-8-26
6/11
5. 文件应用
• Utilities-File Utilities
DeleteFile • int DeleteFile (char File_Name[]); • i = DeleteFile ("*.doc"); RenameFile • int RenameFile (char Existing_File_Name[], char
StringLength • int StringLength (char String[]); • i = StringLength (str); StringLowerCase • void StringLowerCase (char String[]); • StringLowerCase (str); StringUpperCase CompareString • int CompareStrings (char String_#1[], int
8/11
2013-8-26
•
ANSI C-stdio.h fopen • FILE *fopen (const char File_Name[], const char Mode[]); • fp = fopen ("test.dat", "wb+"); fclose • int fclose (FILE *Stream); • i = fclose (fp); fread • size_t fread (void *Buffer, size_t Element_Size, size_t
New_File_Name[]); i = RenameFile ("test1.dat", "test2.dat");
2013-8-26
•
Formatting and I/O-File I/O
OpenFile • int OpenFile (char File_Name[], int Read/Write_Mode, int Action, int File_Type) • fp = OpenFile ("test.dat", VAL_READ_ONLY, VAL_OPEN_AS_IS, VAL_BINARY); CloseFile • int CloseFile (int File_Handle); ReadFile • int ReadFile (int File_Handle, char Buffer[], int Count); • ReadFile (fp, data, 8); WriteFile • int WriteFile (int File_Handle, char Buffer[], int Count); • WriteFile (fp, data, 8); ArrayToFile FileToArray
•
Scan 将一个源数据(item)格式化到一个或多个 目标数据变量中
int Scan (void *Source, char Format_String[], ...); Scan ("10", "%s>%d", &i); %s %d, %i %f %10f 字符串 整型 浮点型 浮点型数组
SetDir DeleteDir
int DeleteDir (char Directory_Name[]); i = DeleteDir ("d:\\test\\data"); int MakeDir (char Directory_Name[]); i = MakeDir ("d:\\test\\data");
2/11
• Programmer’s Toolbox-String Handling
AppendString • int AppendString (char
**Pointer_To_String_To_Append_To, const char String_To_Append[], int Num_Characters_To_Append); • AppendString (str1, str2, -1);
MakeDir
GetProjectDir
int GetProjectDir (char Directory_Name[]); i = GetProjectDir (dir);
……
10/11
7. IO端口(Port IO)
• inp
char inp (short Port_Number); i = inp (0x220+4); j = inp (0x220+5); k = j*256+i; k = inpw (0x220+4);
• CopyFile • int CopyFile (char Source_File_Name[], char • GetFileAttrs • int GetFileAttrs (char File_Name[], int *Read-Only, •
int *System, int *Hidden, int *Archive); i = GetFileAttrs ("test.dat", &read, &system, &hidden, &archive); 7/11 Target_File_Name[]); i = CopyFile (“test1.dat”, “test2.dat”);
Delay
•
SyncWait
4. 日期/时间(Date/Time)
•
• •
DateStr
char *DateStr (void); char *TimeStr (void); 格式:MM-DD-YYYY 格式:HH:MM:SS
TimeStr GetSystemTime
int GetSystemTime (int *Hours, int *Minutes, int *Seconds);
Scan(string,"%s>%s[t#]%f",str1,&value);
• Fmtwizard
2013-8-26 5/11
3. 定时/等待(Timer/Wait)
•
•
Timer
double Timer (void) void Delay (double Number_of_Seconds); Delay(3.0); void SyncWait (double Begin_Time, double Interval); SyncWait(mark, interval);
• fwrite • size_t fwrite (const void *Buffer, size_t Element_Size,
Number_of_Elements, FILE *Stream); num = fread (data, 4096, 1024, fp);
Βιβλιοθήκη Baidu
• ftell • long ftell (FILE *Stream); • pos = ftell (fp); fseek • int fseek (FILE *Stream, long Offset, int Origin); • i = fseek (fp, 256, SEEK_SET);
2013-8-26 3/11
2. 数据格式化(Data Formatting)
• Fmt 将一个或多个源数据(item)格式化到一个目 标数据变量中
int Fmt (void *Target, char Format_String[], ...); Fmt (str, "%s<%d %s %d", i,"plus",j);
StrDup • char *StrDup (const char String_To_Duplicate[]); • str = StrDup ("virtual instrumentation lesson"); RemoveSurroundingWhiteSpace • void RemoveSurroundingWhiteSpace (char String[]); • RemoveSurroundingWhiteSpace (str); SkipWhiteSpace StrICmpWithoutSurrWhiteSpace ……
String_#1_Index, char String_#2[], int String_#2_Index, int Case_Sensitive?); • i = CompareStrings (str1, ind1, str2, ind2, 0);
2013-8-26
CopyString ……
4/11
•
格式符
2013-8-26
• 修饰符
修饰符:[wn], [tn], [t#], [pn], [bn]… …
• 举例
int iData[100]; float fData[100]; Fmt(iData, ”%100d<%100f”, fData);
Fmt(string,"%s<%s%f[p2]","value is ",value);
• • • • •
inpw
inpd outp
char outp (short Port_Number, char Byte); i = outp (0x2c0+5, ch);
outpw outpd
11/11
2013-8-26
size_t Number_of_Elements, FILE *Stream); num = fwrite (data, 4096, 1024, fp);
2013-8-26
6. 路径应用(Directory Utilities)
•
• • • • •
2013-8-26
GetDir
int GetDir (char Current_Directory[]); i = GetDir (dir);
LabWindows/CVI教程(5)
文件和端口操作
主讲:乔立岩
Email: qiaoliyan@hit.edu.cn (交作业) MSN: qiaoliyan@msn.com(在线交流) Tel: 86413532 ext. 8611 (逸夫楼611)
自动化测试与控制研究所
1. 字符串操作
• Formatting and I/O-String Manipulation
2013-8-26
6/11
5. 文件应用
• Utilities-File Utilities
DeleteFile • int DeleteFile (char File_Name[]); • i = DeleteFile ("*.doc"); RenameFile • int RenameFile (char Existing_File_Name[], char
StringLength • int StringLength (char String[]); • i = StringLength (str); StringLowerCase • void StringLowerCase (char String[]); • StringLowerCase (str); StringUpperCase CompareString • int CompareStrings (char String_#1[], int
8/11
2013-8-26
•
ANSI C-stdio.h fopen • FILE *fopen (const char File_Name[], const char Mode[]); • fp = fopen ("test.dat", "wb+"); fclose • int fclose (FILE *Stream); • i = fclose (fp); fread • size_t fread (void *Buffer, size_t Element_Size, size_t
New_File_Name[]); i = RenameFile ("test1.dat", "test2.dat");
2013-8-26
•
Formatting and I/O-File I/O
OpenFile • int OpenFile (char File_Name[], int Read/Write_Mode, int Action, int File_Type) • fp = OpenFile ("test.dat", VAL_READ_ONLY, VAL_OPEN_AS_IS, VAL_BINARY); CloseFile • int CloseFile (int File_Handle); ReadFile • int ReadFile (int File_Handle, char Buffer[], int Count); • ReadFile (fp, data, 8); WriteFile • int WriteFile (int File_Handle, char Buffer[], int Count); • WriteFile (fp, data, 8); ArrayToFile FileToArray
•
Scan 将一个源数据(item)格式化到一个或多个 目标数据变量中
int Scan (void *Source, char Format_String[], ...); Scan ("10", "%s>%d", &i); %s %d, %i %f %10f 字符串 整型 浮点型 浮点型数组
SetDir DeleteDir
int DeleteDir (char Directory_Name[]); i = DeleteDir ("d:\\test\\data"); int MakeDir (char Directory_Name[]); i = MakeDir ("d:\\test\\data");
2/11
• Programmer’s Toolbox-String Handling
AppendString • int AppendString (char
**Pointer_To_String_To_Append_To, const char String_To_Append[], int Num_Characters_To_Append); • AppendString (str1, str2, -1);
MakeDir
GetProjectDir
int GetProjectDir (char Directory_Name[]); i = GetProjectDir (dir);
……
10/11
7. IO端口(Port IO)
• inp
char inp (short Port_Number); i = inp (0x220+4); j = inp (0x220+5); k = j*256+i; k = inpw (0x220+4);
• CopyFile • int CopyFile (char Source_File_Name[], char • GetFileAttrs • int GetFileAttrs (char File_Name[], int *Read-Only, •
int *System, int *Hidden, int *Archive); i = GetFileAttrs ("test.dat", &read, &system, &hidden, &archive); 7/11 Target_File_Name[]); i = CopyFile (“test1.dat”, “test2.dat”);
Delay
•
SyncWait
4. 日期/时间(Date/Time)
•
• •
DateStr
char *DateStr (void); char *TimeStr (void); 格式:MM-DD-YYYY 格式:HH:MM:SS
TimeStr GetSystemTime
int GetSystemTime (int *Hours, int *Minutes, int *Seconds);
Scan(string,"%s>%s[t#]%f",str1,&value);
• Fmtwizard
2013-8-26 5/11
3. 定时/等待(Timer/Wait)
•
•
Timer
double Timer (void) void Delay (double Number_of_Seconds); Delay(3.0); void SyncWait (double Begin_Time, double Interval); SyncWait(mark, interval);
• fwrite • size_t fwrite (const void *Buffer, size_t Element_Size,
Number_of_Elements, FILE *Stream); num = fread (data, 4096, 1024, fp);
Βιβλιοθήκη Baidu
• ftell • long ftell (FILE *Stream); • pos = ftell (fp); fseek • int fseek (FILE *Stream, long Offset, int Origin); • i = fseek (fp, 256, SEEK_SET);
2013-8-26 3/11
2. 数据格式化(Data Formatting)
• Fmt 将一个或多个源数据(item)格式化到一个目 标数据变量中
int Fmt (void *Target, char Format_String[], ...); Fmt (str, "%s<%d %s %d", i,"plus",j);
StrDup • char *StrDup (const char String_To_Duplicate[]); • str = StrDup ("virtual instrumentation lesson"); RemoveSurroundingWhiteSpace • void RemoveSurroundingWhiteSpace (char String[]); • RemoveSurroundingWhiteSpace (str); SkipWhiteSpace StrICmpWithoutSurrWhiteSpace ……
String_#1_Index, char String_#2[], int String_#2_Index, int Case_Sensitive?); • i = CompareStrings (str1, ind1, str2, ind2, 0);
2013-8-26
CopyString ……
4/11
•
格式符
2013-8-26
• 修饰符
修饰符:[wn], [tn], [t#], [pn], [bn]… …
• 举例
int iData[100]; float fData[100]; Fmt(iData, ”%100d<%100f”, fData);
Fmt(string,"%s<%s%f[p2]","value is ",value);
• • • • •
inpw
inpd outp
char outp (short Port_Number, char Byte); i = outp (0x2c0+5, ch);
outpw outpd
11/11
2013-8-26