Дополнительные команды AVR-DOS — различия между версиями

Материал из roboforum.ru Wiki
Перейти к: навигация, поиск
(ещё команды)
Строка 136: Строка 136:
 
|-
 
|-
 
| File(String)
 
| File(String)
| Полный или относительный(?) путь к файлу. Если путь не указан, выбирается путь к файлу, выбранному с помощью DIR()
+
| Полный или относительный(?) путь к файлу. Если не указан, параметром считается последний файл, выбранный с помощью DIR()
 
|}
 
|}
  
Строка 159: Строка 159:
 
|-
 
|-
 
| File(String)
 
| File(String)
| Полный или относительный(?) путь к файлу. Если путь не указан, выбирается путь к файлу, выбранному с помощью DIR()
+
| Полный или относительный(?) путь к файлу. Если не указан, параметром считается последний файл, выбранный с помощью DIR()
 
|}
 
|}
  
Строка 182: Строка 182:
 
|-
 
|-
 
| File(String)
 
| File(String)
| Полный или относительный(?) путь к файлу. Если путь не указан, выбирается путь к файлу, выбранному с помощью DIR()
+
| Полный или относительный(?) путь к файлу. Если не указан, параметром считается последний файл, выбранный с помощью DIR()
 
|}
 
|}
  
Строка 249: Строка 249:
 
{| class="wikitable"
 
{| class="wikitable"
 
| bAttr(Byte)
 
| bAttr(Byte)
| Атрибуты файла, совместимые с DOS-форматом. Байт расшифровывается как 00ADVSHR, где биты 5-0:
+
| Атрибуты файла, совместимые с DOS-форматом. Байт расшифровывается как 00ADVSHR, где биты 5-0:<br />
A=Archiv
+
A=Archiv<br />
D=Directory
+
D=Directory<br />
V=Volume ID
+
V=Volume ID<br />
S=System
+
S=System<br />
H=Hidden
+
H=Hidden<br />
R=Read Only
+
R=Read Only<br />
 
|-
 
|-
 
| File(String)
 
| File(String)
| Полный или относительный(?) путь к файлу. Если путь не указан, выбирается путь к файлу, выбранному с помощью DIR()
+
| Полный или относительный(?) путь к файлу. Если не указан, параметром считается последний файл, выбранный с помощью DIR()
 
|}
 
|}
  
Строка 271: Строка 271:
  
 
=== Name ===
 
=== Name ===
 +
Переименовывает файл в текущей директории.
 +
 +
<code>Name <strOldFilename> As <strNewFileName></code>
 +
 +
{| class="wikitable"
 +
| strOldFileName(String)
 +
| Старое имя файла
 +
|-
 +
| strNewFileName(String)
 +
| Новое имя файла
 +
|}
 +
 +
Пример вызова:
 +
 +
<pre>Dim strOldFileName as String * 12
 +
Dim strNewFileName as String * 12
 +
 +
strOldFileName = "Data.txt"
 +
strNewFileName = "Data.bak"
 +
Name strOldFilename As strNewFileName
 +
</pre>
 +
 +
 +
This command renames a file. A file with the new name may not exits in the directory, otherwise the commands ends with an error (check the AVR-DOS system variable gbDOSError
 +
 
=== ChDir ===
 
=== ChDir ===
 
=== MkDir ===
 
=== MkDir ===

Версия 12:26, 6 января 2009

Список команд AVR-DOS — нижеследующий список команд для операционной системы AVR-DOS.

Диск/Директория

InitFileSystem

Читает Master boot record и partition boot record (Sector) флэшкарты и инициализирует файловую систему.

Эта функция должна быть вызвана перед любым другим использованием системы!

bErrorCode = InitFileSystem (bPartitionNumber)

bErrorCode(Byte) Error Result from Routine, Returns 0 if no Error
bPartitionNumber(Byte) Partitionnumber on the Flashcard Drive (normally 1, but use 0 on mediums without Master boot record)

Пример вызова:

Dim bErrorCode as Byte
bErrorCode = InitFileSystem(1)
If bErrorCode > 0 then
Print "Error: " ; bErrorCode
Else
Print "Filesystem successfully initialized"
End If

DiskSize

Возвращает размер диска.

lSize = DiskSize ()

lSize(Long) Объем диска в КБайтах

Пример вызова:

Dim Gbtemp1 As Byte ' scratch byte
Gbtemp1 = Initfilesystem(1) ' we must init the filesystem once
If Gbtemp1 > 0 Then
Print #1 , "Error " ; Gbtemp1
Else
Print #1 , " OK"
Print "Disksize : " ; Disksize() ' show disk size in Kbytes
Print "Disk free: " ; Diskfree() ' show free space too
End If

DiskFree

Возвращает размер свободного пространства диска.

lFreeSize = DiskFree ()

lFreeSize(Long) Размер свободной области в КБайтах

Пример вызова:

Dim Gbtemp1 As Byte ' scratch byte
Gbtemp1 = Initfilesystem(1) ' we must init the filesystem once
If Gbtemp1 > 0 Then
Print #1 , "Error " ; Gbtemp1
Else
Print #1 , " OK"
Print "Disksize : " ; Disksize() ' show disk size in Kbytes
Print "Disk free: " ; Diskfree() ' show free space too
End If

Kill

Удаляет файл с диска. Открытый файл не может быть удален. Специальные символы(WildCards) в имени файла, маски не поддерживаются. Код ошибки хранится в глобальной переменной gDOSError.

Kill sFileName

sFileName(String) Полный или относительный(?) путь к файлу

Пример вызова:

'We can use the KILL statement to delete a file.
'A file mask is not supported
Print "Kill (delete) file demo"
Kill "test.txt"

Dir

Возвращает имя файла, удовлетворяющее маске.

Первый вызов функции содержит маску. Все последующие вызовы совершаются без маски. Фактически, когда вы хотите получить имя следующего файла в данной директории, удовлетворяющее маске, вы должны вызывать вариант функции без параметров после первого вызова.

sFile = Dir(mask)

sFile = Dir()

SFile(String) Имя файла. Строка пуста, если больше нет файлов, удовлетворяющих маске
Mask(String) Файловая маска, удовлетворяющая требованиям обычного DOS, напр. *.TXT. Маска *.* удовлетворяет всем файлам

Пример вызова:

'Lets have a look at the file we created
Print "Dir function demo"
S = Dir( "*.*")
'The first call to the DIR() function must contain a file mask
' The * means everything.
'
While Len(s) > 0 ' if there was a file found
Print S ; " " ; Filedate() ; " " ; Filetime() ; " " ; Filelen()
' print file , the date the fime was created/changed , the time and the size of the file
S = Dir() ' get next
Wend

FileLen

Возвращает размер файла.

lSize = FileLen ()

lSize = FileLen (file)

lSize(Long) Размер файла в Байтах
File(String) Полный или относительный(?) путь к файлу. Если не указан, параметром считается последний файл, выбранный с помощью DIR()

Пример вызова:

Print "File demo"
Print Filelen( "josef.img") ; " length" ' length of file
Print Filetime( "josef.img") ; " time" ' time file was changed
Print Filedate( "josef.img") ; " date" ' file date

FileDate

Возвращает дату создания или изменения(?) файла.

sDate = FileDate ()

sDate = FileDate (file)

sDate(String) Дата создания или изменения(?) файла
File(String) Полный или относительный(?) путь к файлу. Если не указан, параметром считается последний файл, выбранный с помощью DIR()

Пример вызова:

Print "File demo"
Print Filelen( "josef.img") ; " length" ' length of file
Print Filetime( "josef.img") ; " time" ' time file was changed
Print Filedate( "josef.img") ; " date" ' file date

FileTime

Возвращает время создания или изменения(?) файла.

sTime = FileTime ()

sTime = FileTime (file)

sTime(String) Время создания или изменения(?) файла
File(String) Полный или относительный(?) путь к файлу. Если не указан, параметром считается последний файл, выбранный с помощью DIR()

Пример вызова:

Print "File demo"
Print Filelen( "josef.img") ; " length" ' length of file
Print Filetime( "josef.img") ; " time" ' time file was changed
Print Filedate( "josef.img") ; " date" ' file date

FileDateTime

Возвращает дату и время создания или изменения(?) файла.

Var = FileDateTime ()

Var = FileDateTime (file)

Var(String) Время создания или изменения(?) файла
File(String) When the target variable is a string, it must be dimensioned with a length of at least 17 bytes.
File(Byte array) When the target variable is a byte array, the array size must be at least 6 bytes.
File(Numeric) When you use a numeric variable, the internal file date and time format will be used.

Пример вызова:

' Read and print Directory and show Filename, Date, Time, Size
' for all files matching pStr1 and create/update younger than pDays
Sub Directorylist(pstr1 As String , Byval Pdays As Word)
Local lFileName as String * 12 ' hold file name for print
Local lwCounter as Word , lFileSizeSum as Long ' for summary
Local lwNow as Word , lwDays as Word
Local lSec as Byte , lMin as Byte , lHour as byte , lDay as byte , lMonth as byte , lYear as byte
print "Listing of all Files matching " ; pStr1 ; " and create/last update date within " ; pdays ; " days"
lwNow = SysDay()
lwCounter = 0 : lFileSizeSum = 0
lFileName = Dir(pStr1)
While lFileName <> ""
lsec = FileDateTime()
lwDays = lwNow - SysDay(lDay) ' Days between Now and last File Update; uses lDay, lMonth, lYear
if lwDays <= pDays then ' days smaller than desired with parameter
print lFileName ; FileDate() ; " " ; FileTime() ; " " ; filelen()
incr lwCounter : lFileSizeSum = FileLen() + lFileSizeSum
end if
lFileName = Dir()
WEnd
print lwCounter ; " File(s) found with " ; lFileSizeSum ; " Byte(s)"
End Sub

GetAttr

Возвращает атрибуты файла.

bAttr = FileDate ()

bAttr = FileDate (file)

bAttr(Byte) Атрибуты файла, совместимые с DOS-форматом. Байт расшифровывается как 00ADVSHR, где биты 5-0:

A=Archiv
D=Directory
V=Volume ID
S=System
H=Hidden
R=Read Only

File(String) Полный или относительный(?) путь к файлу. Если не указан, параметром считается последний файл, выбранный с помощью DIR()

Пример вызова:

Print "File demo"
Print Filelen( "josef.img") ; " length" ' length of file
Print Filetime( "josef.img") ; " time" ' time file was changed
Print Filedate( "josef.img") ; " date" ' file date
Print Bin(GetAttr(“Josef.img”)) ; “Attributes” ‘ DOS Attributes

Name

Переименовывает файл в текущей директории.

Name <strOldFilename> As <strNewFileName>

strOldFileName(String) Старое имя файла
strNewFileName(String) Новое имя файла

Пример вызова:

Dim strOldFileName as String * 12
Dim strNewFileName as String * 12

strOldFileName = "Data.txt"
strNewFileName = "Data.bak"
Name strOldFilename As strNewFileName


This command renames a file. A file with the new name may not exits in the directory, otherwise the commands ends with an error (check the AVR-DOS system variable gbDOSError

ChDir

MkDir

RmDir

Файлы

FreeFile

Open

Открывает устройство

OPEN "device" for MODE As #channel

OPEN file FOR MODE as #channel

Device The default device is COM1 and you don't need to open a channel to use INPUT/OUTPUT on this device.

With the implementation of the software UART, the compiler must know to which pin/device you will send/receive the data. So that is why the OPEN statement must be used. It tells the compiler about the pin you use for the serial input or output and the baud rate you want to use. COMB.0:9600,8,N,2 will use PORT B.0 at 9600 baud with 2 stopbits.

The format for COM1 and COM2 is : COM1: or COM2:

There is no speed/baud rate parameter since the default baud rate will be used that is specified with $BAUD or $BAUD1

The format for the software UART is: COMpin:speed,8,N,stopbits[,INVERTED] Where pin is the name of the PORT-pin. Speed must be specified and stop bits can be 1 or 2. 7 bit data or 8 bit data may be used. For parity N, O or E can be used.

An optional parameter ,INVERTED can be specified to use inverted RS-232. Open "COMD.1:9600,8,N,1,INVERTED" For Output As #1 , will use pin PORTD.1 for output with 9600 baud, 1 stop bit and with inverted RS-232.


For the AVR-DOS filesystem, Device can also be a string or filename constant like

"readme.txt" or sFileName

Mode You can use BINARY or RANDOM for COM1 and COM2, but for the software UART pins, you must specify INPUT or OUTPUT.

For the AVR-DOS filesystem, MODE may be INPUT, OUTPUT, APPEND or BINARY.

Channel The number of the channel to open. Must be a positive constant >0.

For the AVR-DOS filesystem, the channel may be a positive constant or a numeric variable. Note that the AVD-DOS filesystem uses real filehandles. The software UART does not use real file handles.

Пример вызова:

OPEN "com1:" for binary as #1
Call test
End
Sub test
Print #1, "test" 
End Sub
Close #1

Close

Flush

Print

Write

Input

Line Input

Get

Put

Seek

Свойства файла

EOF

LOC

LO

FileAttr

Другие

Bload

Bsave

См. также