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

Материал из roboforum.ru Wiki
Перейти к: навигация, поиск
м (заключил примеры в тег <source lang="vb"> </source>)
Строка 1: Строка 1:
 
[[Категория:AVR-DOS]]
 
[[Категория:AVR-DOS]]
'''Список команд AVR-DOS''' — список функций библиотеки [[AVR-DOS]].
+
'''Список команд AVR-DOS''' — список функций библиотеки  
 +
 
 +
[[AVR-DOS]].
  
 
== Диск/Директория ==
 
== Диск/Директория ==
 
=== InitFileSystem ===
 
=== InitFileSystem ===
Читает Master boot record и partition boot record (Sector) диска(флэш-карты) и инициализирует файловую систему.
+
Читает Master boot record и partition boot record  
  
'''Эта функция должна быть вызвана перед любым другим использованием системы!'''
+
(Sector) диска(флэш-карты) и инициализирует файловую
  
<code>bErrorCode = InitFileSystem (bPartitionNumber)</code>
+
систему.
 +
 
 +
'''Эта функция должна быть вызвана перед любым другим
 +
 
 +
использованием системы!'''
 +
 
 +
<code>bErrorCode = InitFileSystem  
 +
 
 +
(bPartitionNumber)</code>
  
 
{| class="wikitable"
 
{| class="wikitable"
 
| bErrorCode(Byte)
 
| bErrorCode(Byte)
| Код ошибки, возвращает 0 если система успешно запущена.
+
| Код ошибки, возвращает 0 если система успешно  
 +
 
 +
запущена.
 
|-
 
|-
 
| bPartitionNumber(Byte)
 
| bPartitionNumber(Byte)
| Partitionnumber on the Flashcard Drive (normally 1, but use 0 on mediums without Master boot record)
+
| Partitionnumber on the Flashcard Drive (normally 1,  
 +
 
 +
but use 0 on mediums without Master boot record)
 
|}
 
|}
  
 
Пример вызова:
 
Пример вызова:
  
<pre>Dim bErrorCode as Byte
+
<source lang="vb">Dim bErrorCode as Byte
 
bErrorCode = InitFileSystem(1)
 
bErrorCode = InitFileSystem(1)
 
If bErrorCode > 0 then
 
If bErrorCode > 0 then
Строка 27: Строка 41:
 
Print "Filesystem successfully initialized"
 
Print "Filesystem successfully initialized"
 
End If
 
End If
</pre>
+
</source>
  
 
=== DiskSize ===
 
=== DiskSize ===
Строка 41: Строка 55:
 
Пример вызова:
 
Пример вызова:
  
<pre>Dim Gbtemp1 As Byte ' scratch byte
+
<source lang="vb">Dim Gbtemp1 As Byte ' scratch byte
Gbtemp1 = Initfilesystem(1) ' we must init the filesystem once
+
Gbtemp1 = Initfilesystem(1) ' we must init the  
 +
 
 +
filesystem once
 
If Gbtemp1 > 0 Then
 
If Gbtemp1 > 0 Then
 
Print #1 , "Error " ; Gbtemp1
 
Print #1 , "Error " ; Gbtemp1
 
Else
 
Else
 
Print #1 , " OK"
 
Print #1 , " OK"
Print "Disksize : " ; Disksize() ' show disk size in Kbytes
+
Print "Disksize : " ; Disksize() ' show disk size in  
 +
 
 +
Kbytes
 
Print "Disk free: " ; Diskfree() ' show free space too
 
Print "Disk free: " ; Diskfree() ' show free space too
 
End If
 
End If
</pre>
+
</source>
  
 
=== DiskFree ===
 
=== DiskFree ===
Строка 64: Строка 82:
 
Пример вызова:
 
Пример вызова:
  
<pre>Dim Gbtemp1 As Byte ' scratch byte
+
<source lang="vb">Dim Gbtemp1 As Byte ' scratch byte
Gbtemp1 = Initfilesystem(1) ' we must init the filesystem once
+
Gbtemp1 = Initfilesystem(1) ' we must init the  
 +
 
 +
filesystem once
 
If Gbtemp1 > 0 Then
 
If Gbtemp1 > 0 Then
 
Print #1 , "Error " ; Gbtemp1
 
Print #1 , "Error " ; Gbtemp1
 
Else
 
Else
 
Print #1 , " OK"
 
Print #1 , " OK"
Print "Disksize : " ; Disksize() ' show disk size in Kbytes
+
Print "Disksize : " ; Disksize() ' show disk size in  
 +
 
 +
Kbytes
 
Print "Disk free: " ; Diskfree() ' show free space too
 
Print "Disk free: " ; Diskfree() ' show free space too
 
End If
 
End If
</pre>
+
</source>
  
 
=== Kill ===
 
=== Kill ===
Удаляет файл с диска. Открытый файл не может быть удален. Специальные символы(WildCards) в имени файла, применение масок не поддерживаются. Код ошибки хранится в глобальной переменной gDOSError<ref name="OkrDOS">Подробнее [[Окружение AVR-DOS]]</ref>.
+
Удаляет файл с диска. Открытый файл не может быть  
 +
 
 +
удален. Специальные символы(WildCards) в имени файла,  
 +
 
 +
применение масок не поддерживаются. Код ошибки хранится  
 +
 
 +
в глобальной переменной gDOSError<ref  
 +
 
 +
name="OkrDOS">Подробнее [[Окружение AVR-DOS]]</ref>.
  
 
<code>Kill sFileName</code>
 
<code>Kill sFileName</code>
Строка 87: Строка 117:
 
Пример вызова:
 
Пример вызова:
  
<pre>'We can use the KILL statement to delete a file.
+
<source lang="vb">'We can use the KILL statement to delete a file.
 
'A file mask is not supported
 
'A file mask is not supported
 
Print "Kill (delete) file demo"
 
Print "Kill (delete) file demo"
 
Kill "test.txt"
 
Kill "test.txt"
</pre>
+
</source>
  
 
=== Dir ===
 
=== Dir ===
 
Возвращает имя файла, удовлетворяющее маске.
 
Возвращает имя файла, удовлетворяющее маске.
  
Первый вызов функции содержит маску. Все последующие вызовы совершаются без маски. Фактически, когда вы хотите получить имя следующего файла в данной директории, удовлетворяющее маске, вы должны вызывать вариант функции без параметров после первого вызова.
+
Первый вызов функции содержит маску. Все последующие  
 +
 
 +
вызовы совершаются без маски. Фактически, когда вы  
 +
 
 +
хотите получить имя следующего файла в данной  
 +
 
 +
директории, удовлетворяющее маске, вы должны вызывать  
 +
 
 +
вариант функции без параметров после первого вызова.
  
 
<code>sFile = Dir(mask)</code>
 
<code>sFile = Dir(mask)</code>
Строка 104: Строка 142:
 
{| class="wikitable"
 
{| class="wikitable"
 
| SFile(String)
 
| SFile(String)
| Имя файла. Строка пуста, если больше нет файлов, удовлетворяющих маске
+
| Имя файла. Строка пуста, если больше нет файлов,  
 +
 
 +
удовлетворяющих маске
 
|-
 
|-
 
| Mask(String)
 
| Mask(String)
| Файловая маска, удовлетворяющая требованиям обычного DOS, напр. *.TXT. Маска *.* удовлетворяет всем файлам
+
| Файловая маска, удовлетворяющая требованиям обычного  
 +
 
 +
DOS, напр. *.TXT. Маска *.* удовлетворяет всем файлам
 
|}
 
|}
  
 
Пример вызова:
 
Пример вызова:
  
<pre>'Lets have a look at the file we created
+
<source lang="vb">'Lets have a look at the file we created
 
Print "Dir function demo"
 
Print "Dir function demo"
 
S = Dir( "*.*")
 
S = Dir( "*.*")
'The first call to the DIR() function must contain a file mask
+
'The first call to the DIR() function must contain a  
 +
 
 +
file mask
 
' The * means everything.
 
' The * means everything.
 
'
 
'
 
While Len(s) > 0 ' if there was a file found
 
While Len(s) > 0 ' if there was a file found
Print S ; " " ; Filedate() ; " " ; Filetime() ; " " ; Filelen()
+
Print S ; " " ; Filedate() ; " " ; Filetime() ; " " ;  
' print file , the date the fime was created/changed , the time and the size of the file
+
 
 +
Filelen()
 +
' print file , the date the fime was created/changed ,  
 +
 
 +
the time and the size of the file
 
S = Dir() ' get next
 
S = Dir() ' get next
 
Wend
 
Wend
</pre>
+
</source>
  
 
=== FileLen ===
 
=== FileLen ===
Строка 137: Строка 185:
 
|-
 
|-
 
| File(String)
 
| File(String)
| Имя файла в текущей директории. Если не указано, параметром считается последний файл, выбранный с помощью DIR()
+
| Имя файла в текущей директории. Если не указано,  
 +
 
 +
параметром считается последний файл, выбранный с помощью  
 +
 
 +
DIR()
 
|}
 
|}
  
 
Пример вызова:
 
Пример вызова:
  
<pre>Print "File demo"
+
<source lang="vb">Print "File demo"
 
Print Filelen( "josef.img") ; " length" ' length of file
 
Print Filelen( "josef.img") ; " length" ' length of file
Print Filetime( "josef.img") ; " time" ' time file was changed
+
Print Filetime( "josef.img") ; " time" ' time file was  
 +
 
 +
changed
 
Print Filedate( "josef.img") ; " date" ' file date
 
Print Filedate( "josef.img") ; " date" ' file date
</pre>
+
</source>
  
 
=== FileDate ===
 
=== FileDate ===
Строка 160: Строка 214:
 
|-
 
|-
 
| File(String)
 
| File(String)
| Имя файла в текущей директории. Если не указано, параметром считается последний файл, выбранный с помощью DIR()
+
| Имя файла в текущей директории. Если не указано,  
 +
 
 +
параметром считается последний файл, выбранный с помощью  
 +
 
 +
DIR()
 
|}
 
|}
  
 
Пример вызова:
 
Пример вызова:
  
<pre>Print "File demo"
+
<source lang="vb">Print "File demo"
 
Print Filelen( "josef.img") ; " length" ' length of file
 
Print Filelen( "josef.img") ; " length" ' length of file
Print Filetime( "josef.img") ; " time" ' time file was changed
+
Print Filetime( "josef.img") ; " time" ' time file was  
 +
 
 +
changed
 
Print Filedate( "josef.img") ; " date" ' file date
 
Print Filedate( "josef.img") ; " date" ' file date
</pre>
+
</source>
  
 
=== FileTime ===
 
=== FileTime ===
Строка 183: Строка 243:
 
|-
 
|-
 
| File(String)
 
| File(String)
| Имя файла в текущей директории. Если не указано, параметром считается последний файл, выбранный с помощью DIR()
+
| Имя файла в текущей директории. Если не указано,  
 +
 
 +
параметром считается последний файл, выбранный с помощью  
 +
 
 +
DIR()
 
|}
 
|}
  
 
Пример вызова:
 
Пример вызова:
  
<pre>Print "File demo"
+
<source lang="vb">Print "File demo"
 
Print Filelen( "josef.img") ; " length" ' length of file
 
Print Filelen( "josef.img") ; " length" ' length of file
Print Filetime( "josef.img") ; " time" ' time file was changed
+
Print Filetime( "josef.img") ; " time" ' time file was  
 +
 
 +
changed
 
Print Filedate( "josef.img") ; " date" ' file date
 
Print Filedate( "josef.img") ; " date" ' file date
</pre>
+
</source>
  
 
=== FileDateTime ===
 
=== FileDateTime ===
Строка 206: Строка 272:
 
|-
 
|-
 
| File(String)
 
| File(String)
| When the target variable is a string, it must be dimensioned with a length of at least 17 bytes.
+
| When the target variable is a string, it must be  
 +
 
 +
dimensioned with a length of at least 17 bytes.
 
|-
 
|-
 
| File(Byte array)
 
| File(Byte array)
| When the target variable is a byte array, the array size must be at least 6 bytes.
+
| When the target variable is a byte array, the array  
 +
 
 +
size must be at least 6 bytes.
 
|-
 
|-
 
| File(Numeric)
 
| File(Numeric)
| When you use a numeric variable, the internal file date and time format will be used.
+
| When you use a numeric variable, the internal file  
 +
 
 +
date and time format will be used.
 
|}
 
|}
  
 
Пример вызова:
 
Пример вызова:
  
<pre>' Read and print Directory and show Filename, Date, Time, Size
+
<source lang="vb">' Read and print Directory and show Filename, Date,  
' for all files matching pStr1 and create/update younger than pDays
+
 
 +
Time, Size
 +
' for all files matching pStr1 and create/update younger  
 +
 
 +
than pDays
 
Sub Directorylist(pstr1 As String , Byval Pdays As Word)
 
Sub Directorylist(pstr1 As String , Byval Pdays As Word)
Local lFileName as String * 12 ' hold file name for print
+
Local lFileName as String * 12 ' hold file name for  
Local lwCounter as Word , lFileSizeSum as Long ' for summary
+
 
 +
print
 +
Local lwCounter as Word , lFileSizeSum as Long ' for  
 +
 
 +
summary
 
Local lwNow as Word , lwDays as Word
 
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
+
Local lSec as Byte , lMin as Byte , lHour as byte , lDay  
print "Listing of all Files matching " ; pStr1 ; " and create/last update date within " ; pdays ; " days"
+
 
 +
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()
 
lwNow = SysDay()
 
lwCounter = 0 : lFileSizeSum = 0
 
lwCounter = 0 : lFileSizeSum = 0
Строка 230: Строка 314:
 
While lFileName <> ""
 
While lFileName <> ""
 
lsec = FileDateTime()
 
lsec = FileDateTime()
lwDays = lwNow - SysDay(lDay) ' Days between Now and last File Update; uses lDay, lMonth, lYear
+
lwDays = lwNow - SysDay(lDay) ' Days between Now and  
if lwDays <= pDays then ' days smaller than desired with parameter
+
 
print lFileName ; FileDate() ; " " ; FileTime() ; " " ; filelen()
+
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
 
incr lwCounter : lFileSizeSum = FileLen() + lFileSizeSum
 
end if
 
end if
 
lFileName = Dir()
 
lFileName = Dir()
 
WEnd
 
WEnd
print lwCounter ; " File(s) found with " ; lFileSizeSum ; " Byte(s)"
+
print lwCounter ; " File(s) found with " ; lFileSizeSum  
 +
 
 +
; " Byte(s)"
 
End Sub
 
End Sub
</pre>
+
</source>
  
 
=== GetAttr ===
 
=== GetAttr ===
Строка 250: Строка 342:
 
{| class="wikitable"
 
{| class="wikitable"
 
| bAttr(Byte)
 
| bAttr(Byte)
| Атрибуты файла, совместимые с DOS-форматом. Байт расшифровывается как '''00ADVSHR''', где биты 5-0:
+
| Атрибуты файла, совместимые с DOS-форматом. Байт  
 +
 
 +
расшифровывается как '''00ADVSHR''', где биты 5-0:
 
'''A''' - Архивный<br/>
 
'''A''' - Архивный<br/>
 
'''D''' - Директория<br/>
 
'''D''' - Директория<br/>
Строка 259: Строка 353:
 
|-
 
|-
 
| File(String)
 
| File(String)
| Имя файла в текущей директории. Если не указано, параметром считается последний файл, выбранный с помощью DIR()
+
| Имя файла в текущей директории. Если не указано,  
 +
 
 +
параметром считается последний файл, выбранный с помощью  
 +
 
 +
DIR()
 
|}
 
|}
  
 
Пример вызова:
 
Пример вызова:
  
<pre>Print "File demo"
+
<source lang="vb">Print "File demo"
 
Print Filelen( "josef.img") ; " length" ' length of file
 
Print Filelen( "josef.img") ; " length" ' length of file
Print Filetime( "josef.img") ; " time" ' time file was changed
+
Print Filetime( "josef.img") ; " time" ' time file was  
 +
 
 +
changed
 
Print Filedate( "josef.img") ; " date" ' file date
 
Print Filedate( "josef.img") ; " date" ' file date
Print Bin(GetAttr(“Josef.img”)) ; “Attributes” ‘ DOS Attributes
+
Print Bin(GetAttr(“Josef.img”)) ; “Attributes” ‘ DOS  
</pre>
+
 
 +
Attributes
 +
</source>
  
 
=== Name ===
 
=== Name ===
Переименовывает файл в текущей директории. Файл с новым именем не должен существовать в текущей директории, иначе команда вернет ошибку. Код ошибки можно посмотреть в глобальной переменной gbDOSError<ref name="OkrDOS">Подробнее [[Окружение AVR-DOS]]</ref>.
+
Переименовывает файл в текущей директории. Файл с новым  
 +
 
 +
именем не должен существовать в текущей директории,  
 +
 
 +
иначе команда вернет ошибку. Код ошибки можно посмотреть  
 +
 
 +
в глобальной переменной gbDOSError<ref  
 +
 
 +
name="OkrDOS">Подробнее [[Окружение AVR-DOS]]</ref>.
  
 
<code>Name <strOldFilename> As <strNewFileName></code>
 
<code>Name <strOldFilename> As <strNewFileName></code>
Строка 286: Строка 396:
 
Пример вызова:
 
Пример вызова:
  
<pre>Dim strOldFileName as String * 12
+
<source lang="vb">Dim strOldFileName as String * 12
 
Dim strNewFileName as String * 12
 
Dim strNewFileName as String * 12
  
Строка 292: Строка 402:
 
strNewFileName = "Data.bak"
 
strNewFileName = "Data.bak"
 
Name strOldFilename As strNewFileName
 
Name strOldFilename As strNewFileName
</pre>
+
</source>
  
 
=== ChDir ===
 
=== ChDir ===
 
Изменяет текущую директорию.<br />
 
Изменяет текущую директорию.<br />
'''Функции Kill, Dir, ChDir, MkDir, RmDir, Name, FileLen, FileDateTime, FileDate, FileTime, GetAttr, Open, BLoad и BSave работают только в текущей директории. Обращаться к файлу с помощью составного пути запрещается!'''
+
'''Функции Kill, Dir, ChDir, MkDir, RmDir, Name,  
 +
 
 +
FileLen, FileDateTime, FileDate, FileTime, GetAttr,  
 +
 
 +
Open, BLoad и BSave работают только в текущей  
 +
 
 +
директории. Обращаться к файлу с помощью составного пути  
 +
 
 +
запрещается!'''
  
 
<code>ChDIR (strDirectoryName)</code>
 
<code>ChDIR (strDirectoryName)</code>
Строка 302: Строка 420:
 
{| class="wikitable"
 
{| class="wikitable"
 
| strDirectoryName(String)
 
| strDirectoryName(String)
| Путь к новой директории, длина не более 8 символов. Допускаются следующие спецсимволы:<br />
+
| Путь к новой директории, длина не более 8 символов.  
 +
 
 +
Допускаются следующие спецсимволы:<br />
 
"." - на директорию выше<br />
 
"." - на директорию выше<br />
 
"\" - в корень диска
 
"\" - в корень диска
Строка 309: Строка 429:
 
Пример вызова:
 
Пример вызова:
  
<pre>Dim strDirectory as String * 12
+
<source lang="vb">Dim strDirectory as String * 12
  
 
ChDir "SubDir"
 
ChDir "SubDir"
Строка 321: Строка 441:
 
strDirectory = "\"
 
strDirectory = "\"
 
ChDir strDirectory
 
ChDir strDirectory
</pre>
+
</source>
  
 
=== MkDir ===
 
=== MkDir ===
Строка 335: Строка 455:
 
Пример вызова:
 
Пример вызова:
  
<pre>Dim strDirectory as String * 12
+
<source lang="vb">Dim strDirectory as String * 12
 
MkDir "NewDir"
 
MkDir "NewDir"
 
' or
 
' or
 
strDirectory = "NewDir"
 
strDirectory = "NewDir"
 
MkDir strDirectory
 
MkDir strDirectory
</pre>
+
</source>
  
 
=== RmDir ===
 
=== RmDir ===
Строка 354: Строка 474:
 
Пример вызова:
 
Пример вызова:
  
<pre>Dim strDirectory as String * 12
+
<source lang="vb">Dim strDirectory as String * 12
 
MkDir "NewDir"
 
MkDir "NewDir"
 
' or
 
' or
 
strDirectory = "NewDir"
 
strDirectory = "NewDir"
 
MkDir strDirectory
 
MkDir strDirectory
</pre>
+
</source>
  
 
== Файлы ==
 
== Файлы ==
 
=== FreeFile ===
 
=== FreeFile ===
Возвращает свободный файловый номер(filenumber). Функция обеспечивает совместимость с QB.
+
Возвращает свободный файловый номер(filenumber). Функция  
 +
 
 +
обеспечивает совместимость с QB.
  
 
<code>bFileNumber = FreeFile()</code>
 
<code>bFileNumber = FreeFile()</code>
Строка 369: Строка 491:
 
{| class="wikitable"
 
{| class="wikitable"
 
| bFileNumber(Byte)
 
| bFileNumber(Byte)
| Свободный файловый номер, который может использоваться для открытия новых файлов. В отличие от QB, этот файловый номер начинается с 128  и заканчивается 255. Используйте числа 1..127 для пользовательских номеров, чтобы избежать конфликтов номеров при использованиии функции.
+
| Свободный файловый номер, который может использоваться  
 +
 
 +
для открытия новых файлов. В отличие от QB, этот  
 +
 
 +
файловый номер начинается с 128  и заканчивается 255.  
 +
 
 +
Используйте числа 1..127 для пользовательских номеров,  
 +
 
 +
чтобы избежать конфликтов номеров при использованиии  
 +
 
 +
функции.
 
|}
 
|}
  
 
Пример вызова:
 
Пример вызова:
  
<pre>Ff = Freefile() ' get file handle
+
<source lang="vb">Ff = Freefile() ' get file handle
Open "test.txt" For Input As #ff ' we can use a constant for the file too
+
Open "test.txt" For Input As #ff ' we can use a constant  
 +
 
 +
for the file too
 
Print Lof(#ff) ; " length of file"
 
Print Lof(#ff) ; " length of file"
Print Fileattr(#ff) ; " file mode" ' should be 1 for input
+
Print Fileattr(#ff) ; " file mode" ' should be 1 for  
 +
 
 +
input
 
Do
 
Do
 
Line Input #ff , S ' read a line
 
Line Input #ff , S ' read a line
Строка 383: Строка 519:
 
Print S ' print on terminal emulator
 
Print S ' print on terminal emulator
 
Loop Until Eof(ff) <> 0
 
Loop Until Eof(ff) <> 0
'The EOF() function returns a non-zero number when the end of the file is reached
+
'The EOF() function returns a non-zero number when the  
 +
 
 +
end of the file is reached
 
'This way we know that there is no more data we can read
 
'This way we know that there is no more data we can read
 
Close #ff
 
Close #ff
</pre>
+
</source>
  
 
=== Open ===
 
=== Open ===
Строка 397: Строка 535:
 
{| class="wikitable"
 
{| class="wikitable"
 
| Device
 
| Device
| The default device is COM1 and you don't need to open a channel to use INPUT/OUTPUT on this device.
+
| The default device is COM1 and you don't need to open  
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.
+
a channel to use INPUT/OUTPUT on this device.
COMB.0:9600,8,N,2 will use PORT B.0 at 9600 baud with 2 stopbits.
+
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:
 
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
+
There is no speed/baud rate parameter since the default  
  
The format for the software UART is: COMpin:speed,8,N,stopbits[,INVERTED]
+
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.
 
Where pin is the name of the PORT-pin.
 
Speed must be specified and stop bits can be 1 or 2.
 
Speed must be specified and stop bits can be 1 or 2.
Строка 412: Строка 568:
 
For parity N, O or E can be used.
 
For parity N, O or E can be used.
  
An optional parameter ,INVERTED can be specified to use inverted RS-232.
+
An optional parameter ,INVERTED can be specified to use  
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.
+
 
 +
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
  
For the AVR-DOS filesystem, Device can also be a string or filename constant like  
+
or filename constant like  
  
 
"readme.txt" or sFileName
 
"readme.txt" or sFileName
 
|-
 
|-
 
| Mode
 
| Mode
| You can use BINARY or RANDOM for COM1 and COM2, but for the software UART pins, you must specify INPUT or OUTPUT
+
| You can use BINARY or RANDOM for COM1 and COM2, but  
  
For the AVR-DOS filesystem, MODE may be INPUT, OUTPUT, APPEND or BINARY
+
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
 
| Channel
| The number of the channel to open. Must be a positive constant >0
+
| 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
  
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.
+
UART does not use real file handles.
 
|}
 
|}
  
 
Пример вызова:
 
Пример вызова:
  
<pre>OPEN "com1:" for binary as #1
+
<source lang="vb">OPEN "com1:" for binary as #1
 
Call test
 
Call test
 
End
 
End
Строка 439: Строка 617:
 
End Sub
 
End Sub
 
Close #1
 
Close #1
</pre>
+
</source>
  
 
=== Close ===
 
=== Close ===
 
Освобождает открытое устройство.
 
Освобождает открытое устройство.
The statements that support the device are PRINT , INPUT and INPUTHEX , INKEY, WAITKEY.
+
The statements that support the device are PRINT , INPUT  
Every opened device must be closed using the CLOSE #channel statement. Of course, you must use the same channel number.
+
 
The best place for the CLOSE statement is at the end of your program.
+
and INPUTHEX , INKEY, WAITKEY.
The INPUT statement in combination with the software UART, will not echo characters back because there is no default associated pin for this.
+
Every opened device must be closed using the CLOSE  
For the AVR-DOS filesystem, you may place the CLOSE at any place in your program. This because the filesystem supports real file handles.  
+
 
 +
#channel statement. Of course, you must use the same  
 +
 
 +
channel number.
 +
The best place for the CLOSE statement is at the end of  
 +
 
 +
your program.
 +
The INPUT statement in combination with the software  
 +
 
 +
UART, will not echo characters back because there is no  
 +
 
 +
default associated pin for this.
 +
For the AVR-DOS filesystem, you may place the CLOSE at  
 +
 
 +
any place in your program. This because the filesystem  
 +
 
 +
supports real file handles.  
  
 
<code>OPEN "device" for MODE As #channel<br />
 
<code>OPEN "device" for MODE As #channel<br />
Строка 455: Строка 649:
 
{| class="wikitable"
 
{| class="wikitable"
 
| Device
 
| Device
| The default device is COM1 and you don't need to open a channel to use INPUT/OUTPUT on this device.
+
| The default device is COM1 and you don't need to open  
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.
+
a channel to use INPUT/OUTPUT on this device.
COMB.0:9600,8,N,2 will use PORT B.0 at 9600 baud with 2 stop bits.
+
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  
 +
 
 +
stop bits.
  
 
The format for COM1 is : COM1:
 
The format for COM1 is : COM1:
  
Some chips have 2 UARTS. You can use COM2: to open the second HW UART.
+
Some chips have 2 UARTS. You can use COM2: to open the  
 +
 
 +
second HW UART.
 +
 
 +
The format for the software UART is:
  
The format for the software UART is: COMpin:speed,8,N,stop bits[,INVERTED]
+
COMpin:speed,8,N,stop bits[,INVERTED]
 
Where pin is the name of the PORT-pin.
 
Where pin is the name of the PORT-pin.
 
Speed must be specified and stop bits can be 1 or 2.
 
Speed must be specified and stop bits can be 1 or 2.
An optional parameter ,INVERTED can be specified to use inverted RS-232.
+
An optional parameter ,INVERTED can be specified to use  
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
+
 
 +
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
 
|-
 
|-
 
|MODE
 
|MODE
|You can use BINARY or RANDOM for COM1 and COM2, but for the software UART pins, you must specify INPUT or OUTPUT
+
|You can use BINARY or RANDOM for COM1 and COM2, but for  
 +
 
 +
the software UART pins, you must specify INPUT or OUTPUT
 
|-
 
|-
 
|Channel
 
|Channel
|The number of the channel to open. Must be a positive constant >0
+
|The number of the channel to open. Must be a positive  
 +
 
 +
constant >0
 
|}
 
|}
  
 
Пример вызова:
 
Пример вызова:
  
<pre>$crystal = 10000000 'change to the value of the XTAL you have installed
+
<source lang="vb">$crystal = 10000000 'change to the value of the  
 +
 
 +
XTAL you have installed
  
 
Dim B As Byte
 
Dim B As Byte
Строка 486: Строка 708:
 
'Why would you want to do that?
 
'Why would you want to do that?
 
'Because chips that have an internal oscillator may not
 
'Because chips that have an internal oscillator may not
'run at the speed specified. This depends on the voltage, temp etc.
+
'run at the speed specified. This depends on the  
 +
 
 +
voltage, temp etc.
 
'You can either change $CRYSTAL or you can use
 
'You can either change $CRYSTAL or you can use
 
'BAUD #1,9610
 
'BAUD #1,9610
  
'In this example file we use the DT006 from www.simmstick.com
+
'In this example file we use the DT006 from  
 +
 
 +
www.simmstick.com
 
'This allows easy testing with the existing serial port
 
'This allows easy testing with the existing serial port
 
'The MAX232 is fitted for this example.
 
'The MAX232 is fitted for this example.
'Because we use the hardware UART pins we MAY NOT use the hardware UART
+
'Because we use the hardware UART pins we MAY NOT use  
'The hardware UART is used when you use PRINT, INPUT or other related statements
+
 
 +
the hardware UART
 +
'The hardware UART is used when you use PRINT, INPUT or  
 +
 
 +
other related statements
 
'We will use the software UART.
 
'We will use the software UART.
 
Waitms 100
 
Waitms 100
Строка 505: Строка 735:
 
'Now open a pin for input
 
'Now open a pin for input
 
Open "comd.0:19200,8,n,1" For Input As #2
 
Open "comd.0:19200,8,n,1" For Input As #2
'since there is no relation between the input and output pin
+
'since there is no relation between the input and output  
 +
 
 +
pin
 
'there is NO ECHO while keys are typed
 
'there is NO ECHO while keys are typed
 
Print #1 , "Number"
 
Print #1 , "Number"
Строка 515: Строка 747:
 
'now loop until ESC is pressed
 
'now loop until ESC is pressed
 
'With INKEY() we can check if there is data available
 
'With INKEY() we can check if there is data available
'To use it with the software UART you must provide the channel
+
'To use it with the software UART you must provide the  
 +
 
 +
channel
 
Do
 
Do
 
'store in byte
 
'store in byte
Строка 531: Строка 765:
  
 
'OPTIONAL you may use the HARDWARE UART
 
'OPTIONAL you may use the HARDWARE UART
'The software UART will not work on the hardware UART pins
+
'The software UART will not work on the hardware UART  
 +
 
 +
pins
 
'so you must choose other pins
 
'so you must choose other pins
 
'use normal hardware UART for printing
 
'use normal hardware UART for printing
Строка 537: Строка 773:
  
  
'When you dont want to use a level inverter such as the MAX-232
+
'When you dont want to use a level inverter such as the  
 +
 
 +
MAX-232
 
'You can specify ,INVERTED :
 
'You can specify ,INVERTED :
 
'Open "comd.0:300,8,n,1,inverted" For Input As #2
 
'Open "comd.0:300,8,n,1,inverted" For Input As #2
'Now the logic is inverted and there is no need for a level converter
+
'Now the logic is inverted and there is no need for a  
 +
 
 +
level converter
 
'But the distance of the wires must be shorter with this
 
'But the distance of the wires must be shorter with this
 
End
 
End
</pre>
+
</source>
  
 
=== Flush ===
 
=== Flush ===
Write current buffer of File to Card and updates Directory. This function writes all information of an open file, which is not saved yet to the Disk. Normally the Card is updated, if a file will be closed or changed to another sector. When no filenumber is specified, all open files will be flushed.
+
Write current buffer of File to Card and updates  
 +
 
 +
Directory. This function writes all information of an  
 +
 
 +
open file, which is not saved yet to the Disk. Normally  
 +
 
 +
the Card is updated, if a file will be closed or changed  
 +
 
 +
to another sector. When no filenumber is specified, all  
 +
 
 +
open files will be flushed.
  
 
<code>Flush #bFileNumber</code>
 
<code>Flush #bFileNumber</code>
Строка 554: Строка 804:
 
{| class="wikitable"
 
{| class="wikitable"
 
| BFileNumber(Byte)
 
| BFileNumber(Byte)
| Filenumber, which identifies an opened file such as #1 or #ff
+
| Filenumber, which identifies an opened file such as #1  
 +
 
 +
or #ff
 
|}
 
|}
  
 
Пример вызова:
 
Пример вызова:
  
<pre>$include "startup.inc"
+
<source lang="vb">$include "startup.inc"
  
 
'open the file in BINARY mode
 
'open the file in BINARY mode
Строка 567: Строка 819:
 
Put #2 , L ' write a long
 
Put #2 , L ' write a long
 
Ltemp = Loc(#2) + 1 ' get the position of the next byte
 
Ltemp = Loc(#2) + 1 ' get the position of the next byte
Print Ltemp ; " LOC" ' store the location of the file pointer
+
Print Ltemp ; " LOC" ' store the location of the file  
 +
 
 +
pointer
 
Print Lof(#2) ; " length of file"
 
Print Lof(#2) ; " length of file"
Print Fileattr(#2) ; " file mode" ' should be 32 for binary
+
Print Fileattr(#2) ; " file mode" ' should be 32 for  
 +
 
 +
binary
 
Put #2 , Sn ' write a single
 
Put #2 , Sn ' write a single
 
Put #2 , Stxt ' write a string
 
Put #2 , Stxt ' write a string
Строка 575: Строка 831:
 
Flush #2 ' flush to disk
 
Flush #2 ' flush to disk
 
Close #2
 
Close #2
</pre>
+
</source>
  
 
=== Print ===
 
=== Print ===
Send output to the RS-232 port. Writes a string to a file. You can use a semicolon (;) to print more than one variable at one line.
+
Send output to the RS-232 port. Writes a string to a  
When you end a line with a semicolon, no linefeed will be added. The PRINT routine can be used when you have a RS-232 interface on your uP. The RS-232 interface can be connected to a serial communication port of your computer. This way you can use a terminal emulator as an output device. You can also use the build in terminal emulator. The AVR-DOS filesystem also supports PRINT. But in that case, only strings can be written to disk.  
+
 
 +
file. You can use a semicolon (;) to print more than one  
 +
 
 +
variable at one line.
 +
When you end a line with a semicolon, no linefeed will  
 +
 
 +
be added. The PRINT routine can be used when you have a  
 +
 
 +
RS-232 interface on your uP. The RS-232 interface can be  
 +
 
 +
connected to a serial communication port of your  
 +
 
 +
computer. This way you can use a terminal emulator as an  
 +
 
 +
output device. You can also use the build in terminal  
 +
 
 +
emulator. The AVR-DOS filesystem also supports PRINT.  
 +
 
 +
But in that case, only strings can be written to disk.  
  
 
<code>PRINT var ; " constant" </code>
 
<code>PRINT var ; " constant" </code>
Строка 590: Строка 864:
 
Пример вызова:
 
Пример вызова:
  
<pre>Dim A As Byte , B1 As Byte , C As Integer , S As String * 4
+
<source lang="vb">Dim A As Byte , B1 As Byte , C As Integer , S As  
 +
 
 +
String * 4
 
A = 1
 
A = 1
 
Print "print variable a " ; A
 
Print "print variable a " ; A
Строка 608: Строка 884:
 
Rem Note That Integers Range From -32767 To 32768
 
Rem Note That Integers Range From -32767 To 32768
 
End
 
End
</pre>
+
</source>
  
 
=== Write ===
 
=== Write ===
Writes data to a sequential file. When you write a variables value, you do not write the binary representatrion but the ASCII representation. When you look in a file it contains readable text. When you use PUT, to write binary info, the files are not readable or contain unreadable characters. Strings written are surrounded by string delimeters "". Multiple variables written are separated by a comma. Look to this example:
+
Writes data to a sequential file. When you write a  
<pre>Dim S as String * 10 , W as Word
+
 
 +
variables value, you do not write the binary  
 +
 
 +
representatrion but the ASCII representation. When you  
 +
 
 +
look in a file it contains readable text. When you use  
 +
 
 +
PUT, to write binary info, the files are not readable or  
 +
 
 +
contain unreadable characters. Strings written are  
 +
 
 +
surrounded by string delimeters "". Multiple variables  
 +
 
 +
written are separated by a comma. Look to this example:
 +
<source lang="vb">Dim S as String * 10 , W as Word
 
S="hello" : W = 100
 
S="hello" : W = 100
 
OPEN "test.txt" For OUTPUT as #1
 
OPEN "test.txt" For OUTPUT as #1
 
WRITE #1, S , W
 
WRITE #1, S , W
CLOSE #1</pre>
+
CLOSE #1</source>
The file content will look like this : "hello",100. Use INPUT to read the values from value.  
+
The file content will look like this : "hello",100. Use  
 +
 
 +
INPUT to read the values from value.  
  
 
<code>Write #ch , data [,data1]</code>
 
<code>Write #ch , data [,data1]</code>
Строка 623: Строка 915:
 
{| class="wikitable"
 
{| class="wikitable"
 
| Ch(...)
 
| Ch(...)
| A channel number, which identifies an opened file. This can be a hard coded constant or a variable
+
| A channel number, which identifies an opened file.  
 +
 
 +
This can be a hard coded constant or a variable
 
|-
 
|-
 
| Data , data1
 
| Data , data1
Строка 631: Строка 925:
 
Пример вызова:
 
Пример вызова:
  
<pre>Dim S As string * 10 , W As Word ,L As Long
+
<source lang="vb">Dim S As string * 10 , W As Word ,L As Long
 
S = "write"
 
S = "write"
 
Open "write.dmo" For Output As #2
 
Open "write.dmo" For Output As #2
Строка 640: Строка 934:
 
Close #2
 
Close #2
 
Print S ; " " ; W ; " " ; L
 
Print S ; " " ; W ; " " ; L
</pre>
+
</source>
  
 
=== Input ===
 
=== Input ===
Read a Line from an opened File. Only valid for files opened in mode INPUT. Line INPUT works only with strings. It is great for working on text files.  
+
Read a Line from an opened File. Only valid for files  
 +
 
 +
opened in mode INPUT. Line INPUT works only with  
 +
 
 +
strings. It is great for working on text files.  
  
 
<code>LineInput #bFileNumber, sLineText</code>
 
<code>LineInput #bFileNumber, sLineText</code>
Строка 652: Строка 950:
 
|-
 
|-
 
| SlineText(String)
 
| SlineText(String)
| A string, which is assigned with the next line from the file
+
| A string, which is assigned with the next line from  
 +
 
 +
the file
 
|}
 
|}
  
 
Пример вызова:
 
Пример вызова:
  
<pre>'Ok we want to check if the file contains the written lines
+
<source lang="vb">'Ok we want to check if the file contains the  
 +
 
 +
written lines
 
Ff = Freefile() ' get file handle
 
Ff = Freefile() ' get file handle
Open "test.txt" For Input As #ff ' we can use a constant for the file too
+
Open "test.txt" For Input As #ff ' we can use a constant  
 +
 
 +
for the file too
 
Print Lof(#ff) ; " length of file"
 
Print Lof(#ff) ; " length of file"
Print Fileattr(#ff) ; " file mode" ' should be 1 for input
+
Print Fileattr(#ff) ; " file mode" ' should be 1 for  
 +
 
 +
input
 
Do
 
Do
 
Line Input #ff , S ' read a line
 
Line Input #ff , S ' read a line
Строка 667: Строка 973:
 
Print S ' print on terminal emulator
 
Print S ' print on terminal emulator
 
Loop Until Eof(ff) <> 0
 
Loop Until Eof(ff) <> 0
'The EOF() function returns a non-zero number when the end of the file is reached
+
'The EOF() function returns a non-zero number when the  
 +
 
 +
end of the file is reached
 
'This way we know that there is no more data we can read
 
'This way we know that there is no more data we can read
 
Close #ff
 
Close #ff
</pre>
+
</source>
  
 
=== Line Input ===
 
=== Line Input ===
Read a Line from an opened File. Only valid for files opened in mode INPUT. Line INPUT works only with strings. It is great for working on text files.  
+
Read a Line from an opened File. Only valid for files  
 +
 
 +
opened in mode INPUT. Line INPUT works only with  
 +
 
 +
strings. It is great for working on text files.  
  
 
<code>LineInput #bFileNumber, sLineText</code>
 
<code>LineInput #bFileNumber, sLineText</code>
Строка 682: Строка 994:
 
|-
 
|-
 
| SlineText(String)
 
| SlineText(String)
| A string, which is assigned with the next line from the file.
+
| A string, which is assigned with the next line from  
 +
 
 +
the file.
 
|}
 
|}
  
 
Пример вызова:
 
Пример вызова:
  
<pre>'Ok we want to check if the file contains the written lines
+
<source lang="vb">'Ok we want to check if the file contains the  
 +
 
 +
written lines
 
Ff = Freefile() ' get file handle
 
Ff = Freefile() ' get file handle
Open "test.txt" For Input As #ff ' we can use a constant for the file too
+
Open "test.txt" For Input As #ff ' we can use a constant  
 +
 
 +
for the file too
 
Print Lof(#ff) ; " length of file"
 
Print Lof(#ff) ; " length of file"
Print Fileattr(#ff) ; " file mode" ' should be 1 for input
+
Print Fileattr(#ff) ; " file mode" ' should be 1 for  
 +
 
 +
input
 
Do
 
Do
 
Line Input #ff , S ' read a line
 
Line Input #ff , S ' read a line
Строка 697: Строка 1017:
 
Print S ' print on terminal emulator
 
Print S ' print on terminal emulator
 
Loop Until Eof(ff) <> 0
 
Loop Until Eof(ff) <> 0
'The EOF() function returns a non-zero number when the end of the file is reached
+
'The EOF() function returns a non-zero number when the  
 +
 
 +
end of the file is reached
 
'This way we know that there is no more data we can read
 
'This way we know that there is no more data we can read
 
Close #ff
 
Close #ff
</pre>
+
</source>
  
 
=== Get ===
 
=== Get ===
Reads a byte from the hardware or software UART. Reads data from a file opened in BINARY mode.  
+
Reads a byte from the hardware or software UART. Reads  
 +
 
 +
data from a file opened in BINARY mode.  
 +
 
 +
GET in combination with the software/hardware UART is
  
GET in combination with the software/hardware UART is provided for compatibility with BASCOM-8051. It reads one byte.
+
provided for compatibility with BASCOM-8051. It reads  
GET in combination with the AVR-DOS filesystem is very flexible and versatile. It works on files opened in BINARY mode and you can reads all data types.
+
 
By default you only need to provide the variable name. When the variable is a byte, 1 byte wil be read. When the variable is a word or integer, 2 bytes will be read. When the variable is a long or single, 4 bytes will be read. When the variable is a string, the number of bytes that will be read is equal to the dimensioned size of the string. DIM S as string * 10 , would read 10 bytes.
+
one byte.
Note that when you specify the length for a string, the maximum length is 255. The maximum length for a non-string array is 65535.
+
GET in combination with the AVR-DOS filesystem is very  
<pre>Example :  
+
 
GET #1 , var ,,2 ‘ read 2 bytes, start at current position
+
flexible and versatile. It works on files opened in  
 +
 
 +
BINARY mode and you can reads all data types.
 +
By default you only need to provide the variable name.  
 +
 
 +
When the variable is a byte, 1 byte wil be read. When  
 +
 
 +
the variable is a word or integer, 2 bytes will be read.  
 +
 
 +
When the variable is a long or single, 4 bytes will be  
 +
 
 +
read. When the variable is a string, the number of bytes  
 +
 
 +
that will be read is equal to the dimensioned size of  
 +
 
 +
the string. DIM S as string * 10 , would read 10 bytes.
 +
Note that when you specify the length for a string, the  
 +
 
 +
maximum length is 255. The maximum length for a  
 +
 
 +
non-string array is 65535.
 +
<source lang="vb">Example :  
 +
GET #1 , var ,,2 ‘ read 2 bytes, start at current  
 +
 
 +
position
 
GET #1, var , PS ‘ start at position stored in long PS
 
GET #1, var , PS ‘ start at position stored in long PS
GET #1, var , PS, 2 ‘ start at position stored in long PS and read 2 bytes</pre>
+
GET #1, var , PS, 2 ‘ start at position stored in long  
 +
 
 +
PS and read 2 bytes</source>
  
 
<code>GET #channel, var</code>
 
<code>GET #channel, var</code>
Строка 720: Строка 1072:
 
{| class="wikitable"
 
{| class="wikitable"
 
| #channel(...)
 
| #channel(...)
| A channel number, which identifies an opened file. This can be a hard coded constant or a variable
+
| A channel number, which identifies an opened file.  
 +
 
 +
This can be a hard coded constant or a variable
 
|-
 
|-
 
| Var(...)
 
| Var(...)
| The variable or variable array that will be assigned with the data from the file
+
| The variable or variable array that will be assigned  
 +
 
 +
with the data from the file
 
|-
 
|-
 
| Pos(...)
 
| Pos(...)
| This is an optional parameter that may be used to specify the postion where the reading must start from. This must be a long variable
+
| This is an optional parameter that may be used to  
 +
 
 +
specify the postion where the reading must start from.  
 +
 
 +
This must be a long variable
 
|-
 
|-
 
| Length(...)
 
| Length(...)
| This is an optional parameter that may be used to specify how many bytes must be read from the file.
+
| This is an optional parameter that may be used to  
 +
 
 +
specify how many bytes must be read from the file.
 
|}
 
|}
  
 
Пример вызова:
 
Пример вызова:
  
<pre>'for the binary file demo we need some variables of different types
+
<source lang="vb">'for the binary file demo we need some variables of  
Dim B As Byte , W As Word , L As Long , Sn As Single , Ltemp As Long
+
 
 +
different types
 +
Dim B As Byte , W As Word , L As Long , Sn As Single ,  
 +
 
 +
Ltemp As Long
 
Dim Stxt As String * 10
 
Dim Stxt As String * 10
B = 1 : W = 50000 : L = 12345678 : Sn = 123.45 : Stxt = "test"
+
B = 1 : W = 50000 : L = 12345678 : Sn = 123.45 : Stxt =  
 +
 
 +
"test"
  
 
'open the file in BINARY mode
 
'open the file in BINARY mode
Строка 745: Строка 1113:
 
Put #2 , L ' write a long
 
Put #2 , L ' write a long
 
Ltemp = Loc(#2) + 1 ' get the position of the next byte
 
Ltemp = Loc(#2) + 1 ' get the position of the next byte
Print Ltemp ; " LOC" ' store the location of the file pointer
+
Print Ltemp ; " LOC" ' store the location of the file  
 +
 
 +
pointer
 
Print Seek(#2) ; " = LOC+1"  
 
Print Seek(#2) ; " = LOC+1"  
  
 
Print Lof(#2) ; " length of file"
 
Print Lof(#2) ; " length of file"
Print Fileattr(#2) ; " file mode" ' should be 32 for binary
+
Print Fileattr(#2) ; " file mode" ' should be 32 for  
 +
 
 +
binary
 
Put #2 , Sn ' write a single
 
Put #2 , Sn ' write a single
 
Put #2 , Stxt ' write a string
 
Put #2 , Stxt ' write a string
Строка 766: Строка 1138:
 
Get #2 , Stxt ' get the string
 
Get #2 , Stxt ' get the string
 
Close #2
 
Close #2
</pre>
+
</source>
  
 
=== Put ===
 
=== Put ===
Writes a byte to the hardware or software UART. Writes data to a file opened in BINARY mode.
+
Writes a byte to the hardware or software UART. Writes  
 +
 
 +
data to a file opened in BINARY mode.
 +
 
 +
PUT in combination with the software/hardware UART is
 +
 
 +
provided for compatibility with BASCOM-8051. It writes
 +
 
 +
one byte
 +
PUT in combination with the AVR-DOS filesystem is very
 +
 
 +
flexible and versatile. It works on files opened in
 +
 
 +
BINARY mode and you can write all data types.
 +
By default you only need to provide the variable name.
 +
 
 +
When the variable is a byte, 1 byte wil be written. When
 +
 
 +
the variable is a word or integer, 2 bytes will be
 +
 
 +
written. When the variable is a long or single, 4 bytes
 +
 
 +
will be written. When the variable is a string, the
 +
 
 +
number of bytes that will be written is equal to the
  
PUT in combination with the software/hardware UART is provided for compatibility with BASCOM-8051. It writes one byte
+
dimensioned size of the string. DIM S as string * 10 ,  
PUT in combination with the AVR-DOS filesystem is very flexible and versatile. It works on files opened in BINARY mode and you can write all data types.
+
 
By default you only need to provide the variable name. When the variable is a byte, 1 byte wil be written. When the variable is a word or integer, 2 bytes will be written. When the variable is a long or single, 4 bytes will be written. When the variable is a string, the number of bytes that will be written is equal to the dimensioned size of the string. DIM S as string * 10 , would write 10 bytes.
+
would write 10 bytes.
Note that when you specify the length for a string, the maximum length is 255. The maximum length for a non-string array is 65535.
+
Note that when you specify the length for a string, the  
 +
 
 +
maximum length is 255. The maximum length for a  
 +
 
 +
non-string array is 65535.
 
Example:
 
Example:
<pre>PUT #1, var  
+
<source lang="vb">PUT #1, var  
 
PUT #1, var , , 2 ‘ write 2 bytes at default position
 
PUT #1, var , , 2 ‘ write 2 bytes at default position
PUT #1, var ,PS, 2 ‘ write 2 bytes at location storied in variable PS</pre>
+
PUT #1, var ,PS, 2 ‘ write 2 bytes at location storied  
 +
 
 +
in variable PS</source>
  
  
Строка 788: Строка 1190:
 
{| class="wikitable"
 
{| class="wikitable"
 
| #channel(...)
 
| #channel(...)
| A channel number, which identifies an opened file. This can be a hard coded constant or a variable.
+
| A channel number, which identifies an opened file.  
 +
 
 +
This can be a hard coded constant or a variable.
 
|-
 
|-
 
| Var(...)
 
| Var(...)
| The variable or variable array that will be written to the file
+
| The variable or variable array that will be written to  
 +
 
 +
the file
 
|-
 
|-
 
| Pos(...)
 
| Pos(...)
| This is an optional parameter that may be used to specify the postion where the data must be written to. This must be a long variable.
+
| This is an optional parameter that may be used to  
 +
 
 +
specify the postion where the data must be written to.  
 +
 
 +
This must be a long variable.
 
|-
 
|-
 
| Length(...)
 
| Length(...)
| This is an optional parameter that may be used to specify how many bytes must be written to the file.
+
| This is an optional parameter that may be used to  
 +
 
 +
specify how many bytes must be written to the file.
 
|}
 
|}
  
 
Пример вызова:
 
Пример вызова:
  
<pre>'for the binary file demo we need some variables of different types
+
<source lang="vb">'for the binary file demo we need some variables of  
Dim B As Byte , W As Word , L As Long , Sn As Single , Ltemp As Long
+
 
 +
different types
 +
Dim B As Byte , W As Word , L As Long , Sn As Single ,  
 +
 
 +
Ltemp As Long
 
Dim Stxt As String * 10
 
Dim Stxt As String * 10
B = 1 : W = 50000 : L = 12345678 : Sn = 123.45 : Stxt = "test"
+
B = 1 : W = 50000 : L = 12345678 : Sn = 123.45 : Stxt =  
 +
 
 +
"test"
  
 
'open the file in BINARY mode
 
'open the file in BINARY mode
Строка 813: Строка 1231:
 
Put #2 , L ' write a long
 
Put #2 , L ' write a long
 
Ltemp = Loc(#2) + 1 ' get the position of the next byte
 
Ltemp = Loc(#2) + 1 ' get the position of the next byte
Print Ltemp ; " LOC" ' store the location of the file pointer
+
Print Ltemp ; " LOC" ' store the location of the file  
 +
 
 +
pointer
 
Print Seek(#2) ; " = LOC+1"  
 
Print Seek(#2) ; " = LOC+1"  
  
 
Print Lof(#2) ; " length of file"
 
Print Lof(#2) ; " length of file"
Print Fileattr(#2) ; " file mode" ' should be 32 for binary
+
Print Fileattr(#2) ; " file mode" ' should be 32 for  
 +
 
 +
binary
 
Put #2 , Sn ' write a single
 
Put #2 , Sn ' write a single
 
Put #2 , Stxt ' write a string
 
Put #2 , Stxt ' write a string
Строка 834: Строка 1256:
 
Get #2 , Stxt ' get the string
 
Get #2 , Stxt ' get the string
 
Close #2
 
Close #2
</pre>
+
</source>
  
 
=== Seek ===
 
=== Seek ===
Function: Returns the position of the next Byte to be read or written.
+
Function: Returns the position of the next Byte to be  
Statement: Sets the position of the next Byte to be read or written.
+
 
 +
read or written.
 +
Statement: Sets the position of the next Byte to be read  
  
This function returns the position of the next Byte to be read or written. If an error occures, 0 is returned. Check DOS-Error in variable gbDOSError<ref name="OkrDOS">Подробнее [[Окружение AVR-DOS]]</ref>.
+
or written.
The statetement also returns an error in the gbDOSerror variable in the event that an error occurs.
+
 
You can for example not set the fileposition behinds the filesize.
+
This function returns the position of the next Byte to  
In QB/VB the file is filled with 0 bytes when you set the filepointer behind the size of the file. For embedded systems this does not seem a good idea.
+
 
Seek and Loc seems to do the same function, but take care : the seek function will return the position of the next read/write, while the Loc function returns the position of the last read/write. You may say that Seek = Loc+1.
+
be read or written. If an error occures, 0 is returned.  
 +
 
 +
Check DOS-Error in variable gbDOSError<ref  
 +
 
 +
name="OkrDOS">Подробнее [[Окружение AVR-DOS]]</ref>.
 +
The statetement also returns an error in the gbDOSerror  
 +
 
 +
variable in the event that an error occurs.
 +
You can for example not set the fileposition behinds the  
 +
 
 +
filesize.
 +
In QB/VB the file is filled with 0 bytes when you set  
 +
 
 +
the filepointer behind the size of the file. For  
 +
 
 +
embedded systems this does not seem a good idea.
 +
Seek and Loc seems to do the same function, but take  
 +
 
 +
care : the seek function will return the position of the  
 +
 
 +
next read/write, while the Loc function returns the  
 +
 
 +
position of the last read/write. You may say that Seek =  
 +
 
 +
Loc+1.
 
'''Difference with QB'''
 
'''Difference with QB'''
In QB/VB you can use seek to make the file bigger. When a file is 100 bytes long, setting the filepointer to 200 will increase the file with 0 bytes. By design this is not the case in AVR-DOS.
+
In QB/VB you can use seek to make the file bigger. When  
 +
 
 +
a file is 100 bytes long, setting the filepointer to 200  
 +
 
 +
will increase the file with 0 bytes. By design this is  
 +
 
 +
not the case in AVR-DOS.
  
 
<code>Function: NextReadWrite = Seek (#bFileNumber)
 
<code>Function: NextReadWrite = Seek (#bFileNumber)
Строка 857: Строка 1311:
 
|-
 
|-
 
| NextReadWrite(Long)
 
| NextReadWrite(Long)
| A Long Variable, which is assigned with the Position of the next Byte to be read or written (1-based)
+
| A Long Variable, which is assigned with the Position  
 +
 
 +
of the next Byte to be read or written (1-based)
 
|-
 
|-
 
| NewPos(Long)
 
| NewPos(Long)
| A Long variable that holds the new position the filepointer must be set too.
+
| A Long variable that holds the new position the  
 +
 
 +
filepointer must be set too.
 
|}
 
|}
  
 
Пример вызова:
 
Пример вызова:
  
<pre>Open "test.biN" For Binary As #2
+
<source lang="vb">Open "test.biN" For Binary As #2
 
Put #2 , B ' write a byte
 
Put #2 , B ' write a byte
 
Put #2 , W ' write a word
 
Put #2 , W ' write a word
 
Put #2 , L ' write a long
 
Put #2 , L ' write a long
 
Ltemp = Loc(#2) + 1 ' get the position of the next byte
 
Ltemp = Loc(#2) + 1 ' get the position of the next byte
Print Ltemp ; " LOC" ' store the location of the file pointer
+
Print Ltemp ; " LOC" ' store the location of the file  
 +
 
 +
pointer
 
Print Seek(#2) ; " = LOC+1"  
 
Print Seek(#2) ; " = LOC+1"  
  
Строка 878: Строка 1338:
 
Open "test.bin" For Binary As #2
 
Open "test.bin" For Binary As #2
 
Seek #2 , Ltemp ' set the filepointer
 
Seek #2 , Ltemp ' set the filepointer
Sn = 1.23 ' change the single value so we can check it better
+
Sn = 1.23 ' change the single value so we can check it  
 +
 
 +
better
 
Put #2 , Sn = 1 'specify the file position
 
Put #2 , Sn = 1 'specify the file position
 
Close #2
 
Close #2
</pre>
+
</source>
  
 
== Свойства файла ==
 
== Свойства файла ==
Строка 887: Строка 1349:
 
Returns the End of File Status.
 
Returns the End of File Status.
  
This functions returns information about the End of File Status.
+
This functions returns information about the End of File  
 +
 
 +
Status.
 
{| class="wikitable"
 
{| class="wikitable"
 
! Return value
 
! Return value
Строка 898: Строка 1362:
 
| EOF
 
| EOF
 
|}
 
|}
In case of error (invalid filenumber) 255 (EOF) is returned too.
+
In case of error (invalid filenumber) 255 (EOF) is  
 +
 
 +
returned too.
 
   
 
   
  
Строка 913: Строка 1379:
 
Пример вызова:
 
Пример вызова:
  
<pre>Ff = Freefile() ' get file handle
+
<source lang="vb">Ff = Freefile() ' get file handle
Open "test.txt" For Input As #ff ' we can use a constant for the file too
+
Open "test.txt" For Input As #ff ' we can use a constant  
 +
 
 +
for the file too
 
Print Lof(#ff) ; " length of file"
 
Print Lof(#ff) ; " length of file"
Print Fileattr(#ff) ; " file mode" ' should be 1 for input
+
Print Fileattr(#ff) ; " file mode" ' should be 1 for  
 +
 
 +
input
 
Do
 
Do
 
Line Input #ff , S ' read a line
 
Line Input #ff , S ' read a line
Строка 922: Строка 1392:
 
Print S ' print on terminal emulator
 
Print S ' print on terminal emulator
 
Loop Until Eof(ff) <> 0
 
Loop Until Eof(ff) <> 0
'The EOF() function returns a non-zero number when the end of the file is reached
+
'The EOF() function returns a non-zero number when the  
 +
 
 +
end of the file is reached
 
'This way we know that there is no more data we can read
 
'This way we know that there is no more data we can read
 
Close #ff
 
Close #ff
</pre>
+
</source>
  
 
=== LOC ===
 
=== LOC ===
Returns the position of last read or written Byte of the file.
+
Returns the position of last read or written Byte of the  
 +
 
 +
file.
 +
 
 +
This function returns the position of the last read or
 +
 
 +
written Byte. If an error occurs, 0 is returned. Check
 +
 
 +
DOS-Error in variable gbDOSError<ref
 +
 
 +
name="OkrDOS">Подробнее [[Окружение AVR-DOS]]</ref>. If
 +
 
 +
the file position pointer is changed with the command
 +
 
 +
SEEK, this function can not be used till the next
  
This function returns the position of the last read or written Byte. If an error occurs, 0 is returned. Check DOS-Error in variable gbDOSError<ref name="OkrDOS">Подробнее [[Окружение AVR-DOS]]</ref>. If the file position pointer is changed with the command SEEK, this function can not be used till the next read/write operation.
+
read/write operation.
 
'''Difference with QB'''
 
'''Difference with QB'''
This function differs from QB. In QB the byte position is divided by 128.
+
This function differs from QB. In QB the byte position  
 +
 
 +
is divided by 128.
  
 
<code>lLastReadWritten = Loc (#bFileNumber)</code>
 
<code>lLastReadWritten = Loc (#bFileNumber)</code>
Строка 941: Строка 1429:
 
|-
 
|-
 
| lLastReadWritten(Long)
 
| lLastReadWritten(Long)
| Variable, whichsigned with the Position of last read or written Byte (1-based)
+
| Variable, whichsigned with the Position of last read  
 +
 
 +
or written Byte (1-based)
 
|}
 
|}
  
 
Пример вызова:
 
Пример вызова:
  
<pre>'open the file in BINARY mode
+
<source lang="vb">'open the file in BINARY mode
 
Open "test.biN" For Binary As #2
 
Open "test.biN" For Binary As #2
 
Put #2 , B ' write a byte
 
Put #2 , B ' write a byte
Строка 952: Строка 1442:
 
Put #2 , L ' write a long
 
Put #2 , L ' write a long
 
Ltemp = Loc(#2) + 1 ' get the position of the next byte
 
Ltemp = Loc(#2) + 1 ' get the position of the next byte
Print Ltemp ; " LOC" ' store the location of the file pointer
+
Print Ltemp ; " LOC" ' store the location of the file  
 +
 
 +
pointer
 
Print Lof(#2) ; " length of file"
 
Print Lof(#2) ; " length of file"
Print Fileattr(#2) ; " file mode" ' should be 32 for binary
+
Print Fileattr(#2) ; " file mode" ' should be 32 for  
 +
 
 +
binary
 
Put #2 , Sn ' write a single
 
Put #2 , Sn ' write a single
 
Put #2 , Stxt ' write a string
 
Put #2 , Stxt ' write a string
Строка 960: Строка 1454:
 
Flush #2 ' flush to disk
 
Flush #2 ' flush to disk
 
Close #2
 
Close #2
</pre>
+
</source>
  
 
=== LOF ===
 
=== LOF ===
 
Returns the length of the File in Bytes.
 
Returns the length of the File in Bytes.
  
This function returns the length of an opened file. If an error occures, 0 is returned. Check DOS-Error in variable gbDOSError<ref name="OkrDOS">Подробнее [[Окружение AVR-DOS]]</ref>.
+
This function returns the length of an opened file. If  
 +
 
 +
an error occures, 0 is returned. Check DOS-Error in  
 +
 
 +
variable gbDOSError<ref name="OkrDOS">Подробнее  
 +
 
 +
[[Окружение AVR-DOS]]</ref>.
  
 
<code>lFileLength = LOF (#bFileNumber)</code>
 
<code>lFileLength = LOF (#bFileNumber)</code>
Строка 974: Строка 1474:
 
|-
 
|-
 
| LFileLength(Long)
 
| LFileLength(Long)
| Variable, which issigned with the Length of the file (1-based)
+
| Variable, which issigned with the Length of the file  
 +
 
 +
(1-based)
 
|}
 
|}
  
 
Пример вызова:
 
Пример вызова:
  
<pre>'open the file in BINARY mode
+
<source lang="vb">'open the file in BINARY mode
 
Open "test.biN" For Binary As #2
 
Open "test.biN" For Binary As #2
 
Put #2 , B ' write a byte
 
Put #2 , B ' write a byte
Строка 985: Строка 1487:
 
Put #2 , L ' write a long
 
Put #2 , L ' write a long
 
Ltemp = Loc(#2) + 1 ' get the position of the next byte
 
Ltemp = Loc(#2) + 1 ' get the position of the next byte
Print Ltemp ; " LOC" ' store the location of the file pointer
+
Print Ltemp ; " LOC" ' store the location of the file  
 +
 
 +
pointer
 
Print Lof(#2) ; " length of file"
 
Print Lof(#2) ; " length of file"
Print Fileattr(#2) ; " file mode" ' should be 32 for binary
+
Print Fileattr(#2) ; " file mode" ' should be 32 for  
 +
 
 +
binary
 
Put #2 , Sn ' write a single
 
Put #2 , Sn ' write a single
 
Put #2 , Stxt ' write a string
 
Put #2 , Stxt ' write a string
Строка 993: Строка 1499:
 
Flush #2 ' flush to disk
 
Flush #2 ' flush to disk
 
Close #2
 
Close #2
</pre>
+
</source>
  
 
=== FileAttr ===
 
=== FileAttr ===
 
Returns the file open mode.
 
Returns the file open mode.
  
This functions returns information about the File open mode
+
This functions returns information about the File open  
 +
 
 +
mode
  
 
<code>bFileAttribut = FileAttr (bFileNumber)</code>
 
<code>bFileAttribut = FileAttr (bFileNumber)</code>
Строка 1031: Строка 1539:
 
Пример вызова:
 
Пример вызова:
  
<pre>'open the file in BINARY mode
+
<source lang="vb">'open the file in BINARY mode
 
Open "test.biN" For Binary As #2
 
Open "test.biN" For Binary As #2
Print Fileattr(#2) ; " file mode" ' should be 32 for binary
+
Print Fileattr(#2) ; " file mode" ' should be 32 for  
 +
 
 +
binary
 
Put #2 , Sn ' write a single
 
Put #2 , Sn ' write a single
 
Put #2 , Stxt ' write a string
 
Put #2 , Stxt ' write a string
 
Close #2
 
Close #2
</pre>
+
</source>
  
 
== Другие ==
 
== Другие ==
Строка 1043: Строка 1553:
 
Writes the Content of a File into SRAM.
 
Writes the Content of a File into SRAM.
  
This function writes the content of a file to a desired space in SRAM. A free handle is needed for this function.
+
This function writes the content of a file to a desired  
 +
 
 +
space in SRAM. A free handle is needed for this  
 +
 
 +
function.
  
 
<code>BLoad sFileName, wSRAMPointer</code>
 
<code>BLoad sFileName, wSRAMPointer</code>
Строка 1052: Строка 1566:
 
|-
 
|-
 
| wSRAMPointer(Word)
 
| wSRAMPointer(Word)
| Variable, which holds the SRAM Address to which the content of the file should be written
+
| Variable, which holds the SRAM Address to which the  
 +
 
 +
content of the file should be written
 
|}
 
|}
  
 
Пример вызова:
 
Пример вызова:
  
<pre>'now the good old bsave and bload
+
<source lang="vb">'now the good old bsave and bload
 
Dim Ar(100) As Byte , I As Byte
 
Dim Ar(100) As Byte , I As Byte
 
For I = 1 To 100
 
For I = 1 To 100
Строка 1077: Строка 1593:
 
Next
 
Next
 
Print
 
Print
</pre>
+
</source>
  
 
=== Bsave ===
 
=== Bsave ===
 
Save a range in SRAM to a Fileю
 
Save a range in SRAM to a Fileю
  
This function writes a range from the SRAM to a file. A free file handle is needed for this function.
+
This function writes a range from the SRAM to a file. A  
 +
 
 +
free file handle is needed for this function.
  
 
<code>BSave sFileName, wSRAMPointer, wLength</code>
 
<code>BSave sFileName, wSRAMPointer, wLength</code>
Строка 1091: Строка 1609:
 
|-
 
|-
 
| wSRAMPointer(Word)
 
| wSRAMPointer(Word)
| Variable, which holds the SRAM Address, from where SRAM should be written to a File
+
| Variable, which holds the SRAM Address, from where  
 +
 
 +
SRAM should be written to a File
 
|-
 
|-
 
| wLength(Word)
 
| wLength(Word)
| Count of Bytes from SRAM, which should be written to the file
+
| Count of Bytes from SRAM, which should be written to  
 +
 
 +
the file
 
|}
 
|}
  
 
Пример вызова:
 
Пример вызова:
  
<pre>'now the good old bsave and bload
+
<source lang="vb">'now the good old bsave and bload
 
Dim Ar(100) As Byte , I As Byte
 
Dim Ar(100) As Byte , I As Byte
 
For I = 1 To 100
 
For I = 1 To 100
Строка 1119: Строка 1641:
 
Next
 
Next
 
Print
 
Print
</pre>
+
</source>
  
 
== Сноски ==
 
== Сноски ==

Версия 18:40, 6 января 2009

Список команд AVR-DOS — список функций библиотеки

AVR-DOS.

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

InitFileSystem

Читает Master boot record и partition boot record

(Sector) диска(флэш-карты) и инициализирует файловую

систему.

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

использованием системы!

bErrorCode = InitFileSystem

(bPartitionNumber)

bErrorCode(Byte) Код ошибки, возвращает 0 если система успешно

запущена.

bPartitionNumber(Byte) Partitionnumber on the Flashcard Drive (normally 1,

but use 0 on mediums without Master boot record)

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

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

DiskSize

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

lSize = DiskSize ()

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

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

<source lang="vb">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 </source>

DiskFree

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

lFreeSize = DiskFree ()

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

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

<source lang="vb">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 </source>

Kill

Удаляет файл с диска. Открытый файл не может быть

удален. Специальные символы(WildCards) в имени файла,

применение масок не поддерживаются. Код ошибки хранится

в глобальной переменной gDOSError[1].

Kill sFileName

sFileName(String) Имя файла в текущей директории

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

<source lang="vb">'We can use the KILL statement to delete a file. 'A file mask is not supported Print "Kill (delete) file demo" Kill "test.txt" </source>

Dir

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

Первый вызов функции содержит маску. Все последующие

вызовы совершаются без маски. Фактически, когда вы

хотите получить имя следующего файла в данной

директории, удовлетворяющее маске, вы должны вызывать

вариант функции без параметров после первого вызова.

sFile = Dir(mask)

sFile = Dir()

SFile(String) Имя файла. Строка пуста, если больше нет файлов,

удовлетворяющих маске

Mask(String) Файловая маска, удовлетворяющая требованиям обычного

DOS, напр. *.TXT. Маска *.* удовлетворяет всем файлам

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

<source lang="vb">'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 </source>

FileLen

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

lSize = FileLen ()

lSize = FileLen (file)

lSize(Long) Размер файла в Байтах
File(String) Имя файла в текущей директории. Если не указано,

параметром считается последний файл, выбранный с помощью

DIR()

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

<source lang="vb">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 </source>

FileDate

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

sDate = FileDate ()

sDate = FileDate (file)

sDate(String) Дата создания или изменения(?) файла
File(String) Имя файла в текущей директории. Если не указано,

параметром считается последний файл, выбранный с помощью

DIR()

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

<source lang="vb">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 </source>

FileTime

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

sTime = FileTime ()

sTime = FileTime (file)

sTime(String) Время создания или изменения(?) файла
File(String) Имя файла в текущей директории. Если не указано,

параметром считается последний файл, выбранный с помощью

DIR()

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

<source lang="vb">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 </source>

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.

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

<source lang="vb">' 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 </source>

GetAttr

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

bAttr = FileDate ()

bAttr = FileDate (file)

bAttr(Byte) Атрибуты файла, совместимые с DOS-форматом. Байт

расшифровывается как 00ADVSHR, где биты 5-0: A - Архивный
D - Директория
V - Volume ID(?)
S - Системный
H - Скрытый
R - Только чтение

File(String) Имя файла в текущей директории. Если не указано,

параметром считается последний файл, выбранный с помощью

DIR()

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

<source lang="vb">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 </source>

Name

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

именем не должен существовать в текущей директории,

иначе команда вернет ошибку. Код ошибки можно посмотреть

в глобальной переменной gbDOSError[1].

Name <strOldFilename> As <strNewFileName>

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

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

<source lang="vb">Dim strOldFileName as String * 12 Dim strNewFileName as String * 12

strOldFileName = "Data.txt" strNewFileName = "Data.bak" Name strOldFilename As strNewFileName </source>

ChDir

Изменяет текущую директорию.
Функции Kill, Dir, ChDir, MkDir, RmDir, Name,

FileLen, FileDateTime, FileDate, FileTime, GetAttr,

Open, BLoad и BSave работают только в текущей

директории. Обращаться к файлу с помощью составного пути

запрещается!

ChDIR (strDirectoryName)

strDirectoryName(String) Путь к новой директории, длина не более 8 символов.

Допускаются следующие спецсимволы:
"." - на директорию выше
"\" - в корень диска

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

<source lang="vb">Dim strDirectory as String * 12

ChDir "SubDir" ' or strDirectory = "SubDir" ChDir strDirectory

' Change to next higher directory ChDir "." ' Change to Root Directory strDirectory = "\" ChDir strDirectory </source>

MkDir

Создает каталог в текущей директории.

MkDIR (strDirectoryName)

strDirectoryName(String) Имя новой директории, не более 8 символов

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

<source lang="vb">Dim strDirectory as String * 12 MkDir "NewDir" ' or strDirectory = "NewDir" MkDir strDirectory </source>

RmDir

Удаляет каталог в текущей директории.

RmDIR (strDirectoryName)

strDirectoryName(String) Имя каталога для удаления, не более 8 символов

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

<source lang="vb">Dim strDirectory as String * 12 MkDir "NewDir" ' or strDirectory = "NewDir" MkDir strDirectory </source>

Файлы

FreeFile

Возвращает свободный файловый номер(filenumber). Функция

обеспечивает совместимость с QB.

bFileNumber = FreeFile()

bFileNumber(Byte) Свободный файловый номер, который может использоваться

для открытия новых файлов. В отличие от QB, этот

файловый номер начинается с 128 и заканчивается 255.

Используйте числа 1..127 для пользовательских номеров,

чтобы избежать конфликтов номеров при использованиии

функции.

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

<source lang="vb">Ff = Freefile() ' get file handle Open "test.txt" For Input As #ff ' we can use a constant

for the file too Print Lof(#ff) ; " length of file" Print Fileattr(#ff) ; " file mode" ' should be 1 for

input Do Line Input #ff , S ' read a line ' line input is used to read a line of text from a file Print S ' print on terminal emulator Loop Until Eof(ff) <> 0 'The EOF() function returns a non-zero number when the

end of the file is reached 'This way we know that there is no more data we can read Close #ff </source>

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.

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

<source lang="vb">OPEN "com1:" for binary as #1 Call test End Sub test Print #1, "test" End Sub Close #1 </source>

Close

Освобождает открытое устройство. The statements that support the device are PRINT , INPUT

and INPUTHEX , INKEY, WAITKEY. Every opened device must be closed using the CLOSE

  1. channel statement. Of course, you must use the same

channel number. The best place for the CLOSE statement is at the end of

your program. The INPUT statement in combination with the software

UART, will not echo characters back because there is no

default associated pin for this. For the AVR-DOS filesystem, you may place the CLOSE at

any place in your program. This because the filesystem

supports real file handles.

OPEN "device" for MODE As #channel
...
CLOSE #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

stop bits.

The format for COM1 is : COM1:

Some chips have 2 UARTS. You can use COM2: to open the

second HW UART.

The format for the software UART is:

COMpin:speed,8,N,stop bits[,INVERTED] Where pin is the name of the PORT-pin. Speed must be specified and stop bits can be 1 or 2. 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

MODE You can use BINARY or RANDOM for COM1 and COM2, but for

the software UART pins, you must specify INPUT or OUTPUT

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

constant >0

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

<source lang="vb">$crystal = 10000000 'change to the value of the

XTAL you have installed

Dim B As Byte

'Optional you can fine tune the calculated bit delay 'Why would you want to do that? 'Because chips that have an internal oscillator may not 'run at the speed specified. This depends on the

voltage, temp etc. 'You can either change $CRYSTAL or you can use 'BAUD #1,9610

'In this example file we use the DT006 from

www.simmstick.com 'This allows easy testing with the existing serial port 'The MAX232 is fitted for this example. 'Because we use the hardware UART pins we MAY NOT use

the hardware UART 'The hardware UART is used when you use PRINT, INPUT or

other related statements 'We will use the software UART. Waitms 100

'open channel for output Open "comd.1:19200,8,n,1" For Output As #1 Print #1 , "serial output"


'Now open a pin for input Open "comd.0:19200,8,n,1" For Input As #2 'since there is no relation between the input and output

pin 'there is NO ECHO while keys are typed Print #1 , "Number" 'get a number Input #2 , B 'print the number Print #1 , B

'now loop until ESC is pressed 'With INKEY() we can check if there is data available 'To use it with the software UART you must provide the

channel Do 'store in byte B = Inkey(#2) 'when the value > 0 we got something If B > 0 Then Print #1 , Chr(b) 'print the character End If Loop Until B = 27


Close #2 Close #1


'OPTIONAL you may use the HARDWARE UART 'The software UART will not work on the hardware UART

pins 'so you must choose other pins 'use normal hardware UART for printing 'Print B


'When you dont want to use a level inverter such as the

MAX-232 'You can specify ,INVERTED : 'Open "comd.0:300,8,n,1,inverted" For Input As #2 'Now the logic is inverted and there is no need for a

level converter 'But the distance of the wires must be shorter with this End </source>

Flush

Write current buffer of File to Card and updates

Directory. This function writes all information of an

open file, which is not saved yet to the Disk. Normally

the Card is updated, if a file will be closed or changed

to another sector. When no filenumber is specified, all

open files will be flushed.

Flush #bFileNumber

Flush

BFileNumber(Byte) Filenumber, which identifies an opened file such as #1

or #ff

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

<source lang="vb">$include "startup.inc"

'open the file in BINARY mode Open "test.biN" For Binary As #2 Put #2 , B ' write a byte Put #2 , W ' write a word Put #2 , L ' write a long Ltemp = Loc(#2) + 1 ' get the position of the next byte Print Ltemp ; " LOC" ' store the location of the file

pointer Print Lof(#2) ; " length of file" Print Fileattr(#2) ; " file mode" ' should be 32 for

binary Put #2 , Sn ' write a single Put #2 , Stxt ' write a string

Flush #2 ' flush to disk Close #2 </source>

Print

Send output to the RS-232 port. Writes a string to a

file. You can use a semicolon (;) to print more than one

variable at one line. When you end a line with a semicolon, no linefeed will

be added. The PRINT routine can be used when you have a

RS-232 interface on your uP. The RS-232 interface can be

connected to a serial communication port of your

computer. This way you can use a terminal emulator as an

output device. You can also use the build in terminal

emulator. The AVR-DOS filesystem also supports PRINT.

But in that case, only strings can be written to disk.

PRINT var ; " constant"

Var(...) The variable or constant to print

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

<source lang="vb">Dim A As Byte , B1 As Byte , C As Integer , S As

String * 4 A = 1 Print "print variable a " ; A Print 'new line Print "Text to print." 'constant to print


B1 = 10 Print Hex(b1) 'print in hexa notation C = &HA000 'assign value to c% Print Hex(c) 'print in hex notation Print C 'print in decimal notation

C = -32000 Print C Print Hex(c) Rem Note That Integers Range From -32767 To 32768 End </source>

Write

Writes data to a sequential file. When you write a

variables value, you do not write the binary

representatrion but the ASCII representation. When you

look in a file it contains readable text. When you use

PUT, to write binary info, the files are not readable or

contain unreadable characters. Strings written are

surrounded by string delimeters "". Multiple variables

written are separated by a comma. Look to this example: <source lang="vb">Dim S as String * 10 , W as Word S="hello" : W = 100 OPEN "test.txt" For OUTPUT as #1 WRITE #1, S , W CLOSE #1</source> The file content will look like this : "hello",100. Use

INPUT to read the values from value.

Write #ch , data [,data1]

Ch(...) A channel number, which identifies an opened file.

This can be a hard coded constant or a variable

Data , data1 A variable who’s content are written to the file

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

<source lang="vb">Dim S As string * 10 , W As Word ,L As Long S = "write" Open "write.dmo" For Output As #2 Write #2 , S , W , L ' write is also supported Close #2 Open "write.dmo" For Input As #2 Input #2 , S , W , L ' write is also supported Close #2 Print S ; " " ; W ; " " ; L </source>

Input

Read a Line from an opened File. Only valid for files

opened in mode INPUT. Line INPUT works only with

strings. It is great for working on text files.

LineInput #bFileNumber, sLineText

BfileNumber(Byte) Filenumber, which identifies an opened file
SlineText(String) A string, which is assigned with the next line from

the file

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

<source lang="vb">'Ok we want to check if the file contains the

written lines Ff = Freefile() ' get file handle Open "test.txt" For Input As #ff ' we can use a constant

for the file too Print Lof(#ff) ; " length of file" Print Fileattr(#ff) ; " file mode" ' should be 1 for

input Do Line Input #ff , S ' read a line ' line input is used to read a line of text from a file Print S ' print on terminal emulator Loop Until Eof(ff) <> 0 'The EOF() function returns a non-zero number when the

end of the file is reached 'This way we know that there is no more data we can read Close #ff </source>

Line Input

Read a Line from an opened File. Only valid for files

opened in mode INPUT. Line INPUT works only with

strings. It is great for working on text files.

LineInput #bFileNumber, sLineText

BfileNumber(Byte) Filenumber, which identifies an opened file
SlineText(String) A string, which is assigned with the next line from

the file.

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

<source lang="vb">'Ok we want to check if the file contains the

written lines Ff = Freefile() ' get file handle Open "test.txt" For Input As #ff ' we can use a constant

for the file too Print Lof(#ff) ; " length of file" Print Fileattr(#ff) ; " file mode" ' should be 1 for

input Do Line Input #ff , S ' read a line ' line input is used to read a line of text from a file Print S ' print on terminal emulator Loop Until Eof(ff) <> 0 'The EOF() function returns a non-zero number when the

end of the file is reached 'This way we know that there is no more data we can read Close #ff </source>

Get

Reads a byte from the hardware or software UART. Reads

data from a file opened in BINARY mode.

GET in combination with the software/hardware UART is

provided for compatibility with BASCOM-8051. It reads

one byte. GET in combination with the AVR-DOS filesystem is very

flexible and versatile. It works on files opened in

BINARY mode and you can reads all data types. By default you only need to provide the variable name.

When the variable is a byte, 1 byte wil be read. When

the variable is a word or integer, 2 bytes will be read.

When the variable is a long or single, 4 bytes will be

read. When the variable is a string, the number of bytes

that will be read is equal to the dimensioned size of

the string. DIM S as string * 10 , would read 10 bytes. Note that when you specify the length for a string, the

maximum length is 255. The maximum length for a

non-string array is 65535. <source lang="vb">Example : GET #1 , var ,,2 ‘ read 2 bytes, start at current

position GET #1, var , PS ‘ start at position stored in long PS GET #1, var , PS, 2 ‘ start at position stored in long

PS and read 2 bytes</source>

GET #channel, var

GET #channel, var , [pos] [, length]

#channel(...) A channel number, which identifies an opened file.

This can be a hard coded constant or a variable

Var(...) The variable or variable array that will be assigned

with the data from the file

Pos(...) This is an optional parameter that may be used to

specify the postion where the reading must start from.

This must be a long variable

Length(...) This is an optional parameter that may be used to

specify how many bytes must be read from the file.

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

<source lang="vb">'for the binary file demo we need some variables of

different types Dim B As Byte , W As Word , L As Long , Sn As Single ,

Ltemp As Long Dim Stxt As String * 10 B = 1 : W = 50000 : L = 12345678 : Sn = 123.45 : Stxt =

"test"

'open the file in BINARY mode Open "test.biN" For Binary As #2 Put #2 , B ' write a byte Put #2 , W ' write a word Put #2 , L ' write a long Ltemp = Loc(#2) + 1 ' get the position of the next byte Print Ltemp ; " LOC" ' store the location of the file

pointer Print Seek(#2) ; " = LOC+1"

Print Lof(#2) ; " length of file" Print Fileattr(#2) ; " file mode" ' should be 32 for

binary Put #2 , Sn ' write a single Put #2 , Stxt ' write a string

Flush #2 ' flush to disk Close #2

'now open the file again and write only the single Open "test.bin" For Binary As #2 L = 1 'specify the file position B = Seek(#2 , L) ' reset is the same as using SEEK #2,L Get #2 , B ' get the byte Get #2 , W ' get the word Get #2 , L ' get the long Get #2 , Sn ' get the single Get #2 , Stxt ' get the string Close #2 </source>

Put

Writes a byte to the hardware or software UART. Writes

data to a file opened in BINARY mode.

PUT in combination with the software/hardware UART is

provided for compatibility with BASCOM-8051. It writes

one byte PUT in combination with the AVR-DOS filesystem is very

flexible and versatile. It works on files opened in

BINARY mode and you can write all data types. By default you only need to provide the variable name.

When the variable is a byte, 1 byte wil be written. When

the variable is a word or integer, 2 bytes will be

written. When the variable is a long or single, 4 bytes

will be written. When the variable is a string, the

number of bytes that will be written is equal to the

dimensioned size of the string. DIM S as string * 10 ,

would write 10 bytes. Note that when you specify the length for a string, the

maximum length is 255. The maximum length for a

non-string array is 65535. Example: <source lang="vb">PUT #1, var PUT #1, var , , 2 ‘ write 2 bytes at default position PUT #1, var ,PS, 2 ‘ write 2 bytes at location storied

in variable PS</source>


PUT #channel, var

PUT #channel, var ,[pos] [,length]

#channel(...) A channel number, which identifies an opened file.

This can be a hard coded constant or a variable.

Var(...) The variable or variable array that will be written to

the file

Pos(...) This is an optional parameter that may be used to

specify the postion where the data must be written to.

This must be a long variable.

Length(...) This is an optional parameter that may be used to

specify how many bytes must be written to the file.

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

<source lang="vb">'for the binary file demo we need some variables of

different types Dim B As Byte , W As Word , L As Long , Sn As Single ,

Ltemp As Long Dim Stxt As String * 10 B = 1 : W = 50000 : L = 12345678 : Sn = 123.45 : Stxt =

"test"

'open the file in BINARY mode Open "test.biN" For Binary As #2 Put #2 , B ' write a byte Put #2 , W ' write a word Put #2 , L ' write a long Ltemp = Loc(#2) + 1 ' get the position of the next byte Print Ltemp ; " LOC" ' store the location of the file

pointer Print Seek(#2) ; " = LOC+1"

Print Lof(#2) ; " length of file" Print Fileattr(#2) ; " file mode" ' should be 32 for

binary Put #2 , Sn ' write a single Put #2 , Stxt ' write a string

Flush #2 ' flush to disk Close #2

'now open the file again and write only the single Open "test.bin" For Binary As #2 L = 1 'specify the file position B = Seek(#2 , L) ' reset is the same as using SEEK #2,L Get #2 , B ' get the byte Get #2 , W ' get the word Get #2 , L ' get the long Get #2 , Sn ' get the single Get #2 , Stxt ' get the string Close #2 </source>

Seek

Function: Returns the position of the next Byte to be

read or written. Statement: Sets the position of the next Byte to be read

or written.

This function returns the position of the next Byte to

be read or written. If an error occures, 0 is returned.

Check DOS-Error in variable gbDOSError[1]. The statetement also returns an error in the gbDOSerror

variable in the event that an error occurs. You can for example not set the fileposition behinds the

filesize. In QB/VB the file is filled with 0 bytes when you set

the filepointer behind the size of the file. For

embedded systems this does not seem a good idea. Seek and Loc seems to do the same function, but take

care : the seek function will return the position of the

next read/write, while the Loc function returns the

position of the last read/write. You may say that Seek =

Loc+1. Difference with QB In QB/VB you can use seek to make the file bigger. When

a file is 100 bytes long, setting the filepointer to 200

will increase the file with 0 bytes. By design this is

not the case in AVR-DOS.

Function: NextReadWrite = Seek (#bFileNumber)

Statement: Seek #bFileNumber, NewPos)

bFileNumber(Byte) Filenumber, which identifies an opened file
NextReadWrite(Long) A Long Variable, which is assigned with the Position

of the next Byte to be read or written (1-based)

NewPos(Long) A Long variable that holds the new position the

filepointer must be set too.

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

<source lang="vb">Open "test.biN" For Binary As #2 Put #2 , B ' write a byte Put #2 , W ' write a word Put #2 , L ' write a long Ltemp = Loc(#2) + 1 ' get the position of the next byte Print Ltemp ; " LOC" ' store the location of the file

pointer Print Seek(#2) ; " = LOC+1"

Close #2

'now open the file again and write only the single Open "test.bin" For Binary As #2 Seek #2 , Ltemp ' set the filepointer Sn = 1.23 ' change the single value so we can check it

better Put #2 , Sn = 1 'specify the file position Close #2 </source>

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

EOF

Returns the End of File Status.

This functions returns information about the End of File

Status.

Return value Status
0 NOT EOF
255 EOF

In case of error (invalid filenumber) 255 (EOF) is

returned too.


bFileEOFStatus = EOF(#bFileNumber)

bFileEOFStatus(Byte) A Byte Variable, which issigned with the EOF Status
bFileNumber(Byte) Number of the opened file

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

<source lang="vb">Ff = Freefile() ' get file handle Open "test.txt" For Input As #ff ' we can use a constant

for the file too Print Lof(#ff) ; " length of file" Print Fileattr(#ff) ; " file mode" ' should be 1 for

input Do Line Input #ff , S ' read a line ' line input is used to read a line of text from a file Print S ' print on terminal emulator Loop Until Eof(ff) <> 0 'The EOF() function returns a non-zero number when the

end of the file is reached 'This way we know that there is no more data we can read Close #ff </source>

LOC

Returns the position of last read or written Byte of the

file.

This function returns the position of the last read or

written Byte. If an error occurs, 0 is returned. Check

DOS-Error in variable gbDOSError[1]. If

the file position pointer is changed with the command

SEEK, this function can not be used till the next

read/write operation. Difference with QB This function differs from QB. In QB the byte position

is divided by 128.

lLastReadWritten = Loc (#bFileNumber)

bFileNumber(Byte) Filenumber, which identifies an opened file
lLastReadWritten(Long) Variable, whichsigned with the Position of last read

or written Byte (1-based)

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

<source lang="vb">'open the file in BINARY mode Open "test.biN" For Binary As #2 Put #2 , B ' write a byte Put #2 , W ' write a word Put #2 , L ' write a long Ltemp = Loc(#2) + 1 ' get the position of the next byte Print Ltemp ; " LOC" ' store the location of the file

pointer Print Lof(#2) ; " length of file" Print Fileattr(#2) ; " file mode" ' should be 32 for

binary Put #2 , Sn ' write a single Put #2 , Stxt ' write a string

Flush #2 ' flush to disk Close #2 </source>

LOF

Returns the length of the File in Bytes.

This function returns the length of an opened file. If

an error occures, 0 is returned. Check DOS-Error in

variable gbDOSError[1].

lFileLength = LOF (#bFileNumber)

bFileNumber(Byte) Filenumber, which identifies an opened file
LFileLength(Long) Variable, which issigned with the Length of the file

(1-based)

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

<source lang="vb">'open the file in BINARY mode Open "test.biN" For Binary As #2 Put #2 , B ' write a byte Put #2 , W ' write a word Put #2 , L ' write a long Ltemp = Loc(#2) + 1 ' get the position of the next byte Print Ltemp ; " LOC" ' store the location of the file

pointer Print Lof(#2) ; " length of file" Print Fileattr(#2) ; " file mode" ' should be 32 for

binary Put #2 , Sn ' write a single Put #2 , Stxt ' write a string

Flush #2 ' flush to disk Close #2 </source>

FileAttr

Returns the file open mode.

This functions returns information about the File open

mode

bFileAttribut = FileAttr (bFileNumber)

Return value Open mode
1 INPUT
2 OUTPUT
8 APPEND
32 BINARY
bFileAttribut(Long) File open mode, See table
bFileNumber(Byte) Number of the opened file


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

<source lang="vb">'open the file in BINARY mode Open "test.biN" For Binary As #2 Print Fileattr(#2) ; " file mode" ' should be 32 for

binary Put #2 , Sn ' write a single Put #2 , Stxt ' write a string Close #2 </source>

Другие

Bload

Writes the Content of a File into SRAM.

This function writes the content of a file to a desired

space in SRAM. A free handle is needed for this

function.

BLoad sFileName, wSRAMPointer

sFileName(Long) Name of the File to be read
wSRAMPointer(Word) Variable, which holds the SRAM Address to which the

content of the file should be written

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

<source lang="vb">'now the good old bsave and bload Dim Ar(100) As Byte , I As Byte For I = 1 To 100 Ar(i) = I ' fill the array Next

Wait 2

W = Varptr(ar(1)) Bsave "josef.img" , W , 100 For I = 1 To 100 Ar(i) = 0 ' reset the array Next

Bload "josef.img" , W ' Josef you are amazing !

For I = 1 To 10 Print Ar(i) ; " " ; Next Print </source>

Bsave

Save a range in SRAM to a Fileю

This function writes a range from the SRAM to a file. A

free file handle is needed for this function.

BSave sFileName, wSRAMPointer, wLength

sFileName(Long) Name of the File to be written
wSRAMPointer(Word) Variable, which holds the SRAM Address, from where

SRAM should be written to a File

wLength(Word) Count of Bytes from SRAM, which should be written to

the file

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

<source lang="vb">'now the good old bsave and bload Dim Ar(100) As Byte , I As Byte For I = 1 To 100 Ar(i) = I ' fill the array Next

Wait 2

W = Varptr(ar(1)) Bsave "josef.img" , W , 100 For I = 1 To 100 Ar(i) = 0 ' reset the array Next

Bload "josef.img" , W ' Josef you are amazing !

For I = 1 To 10 Print Ar(i) ; " " ; Next Print </source>

Сноски

  1. 1 2 3 4 5 Подробнее Окружение AVR-DOS Ошибка цитирования Неверный тег <ref>: название «OkrDOS» определено несколько раз для различного содержимого

См. также