Can anyone help me to write a Karel Programm? I want to write Robot registers to MC Card.
Need one example programm. I get to many errors whilie building...
Can anyone help me to write a Karel Programm? I want to write Robot registers to MC Card.
Need one example programm. I get to many errors whilie building...
PROGRAM WriteRegistersToMC
%NOLOCKGROUP
%COMMENT = 'Schreibt Registerwerte auf Memory Card'
VAR
reg_value : REAL
reg_number : INTEGER
file_id : INTEGER
file_name : STRING[30]
BEGIN
-- Dateiname definieren
file_name = 'mc:register.txt'
-- Datei öffnen
OPEN FILE file_id (file_name, WRITE)
IF file_id < 0 THEN
WRITE('Datei konnte nicht geöffnet werden', CR)
ABORT
ENDIF
-- Registerwerte auslesen und in die Datei schreiben
FOR reg_number = 1 TO 10 DO
-- Wert des Registers auslesen
GET_REG(reg_number, reg_value)
-- Wert in die Datei schreiben
WRITE file_id ('Register ', reg_number, ': ', reg_value, CR)
ENDFOR
-- Datei schließen
CLOSE FILE file_id
-- Bestätigungsmeldung ausgeben
WRITE('Registerwerte erfolgreich auf Memory Card geschrieben', CR)
END WriteRegistersToMC
---->>> ERROR
----------------------------------------------------------------------
Translating C:\Users\t.virnich\Desktop\write_registers.kl
KTRANS Version V9.30 (Build 25 9/14/2023)
Copyright (C) FANUC America Corporation, 1985 through 2019.
All Rights Reserved.
C:\Users\t.virnich\Desktop\write_registers.kl(16)
16 OPEN FILE file_id (file_name, WRITE)
^ ERROR
Id or quoted string expected.
C:\Users\t.virnich\Desktop\write_registers.kl(16)
16 OPEN FILE file_id (file_name, WRITE)
^ ERROR
")" expected.
C:\Users\t.virnich\Desktop\write_registers.kl(16)
16 OPEN FILE file_id (file_name, WRITE)
^ ERROR
Invalid statement. ";" or new line expected.
===============Translation not successful===============
Build Failed: Error translating program: Code: 0xFFFFFFFF:
----------------------------------------------------------------------
Can anyone Help?
Hi Tomeeek,
I will sum up some of your problems.
Please read your error output carefully and go step by step through your erros.
The translator/compiler will show and help you!
file_id : FILE --// var type file !!
OPEN FILE file_id ('RW',file_name) --//order and types...
GET_REG(reg_number, reg_value) --// please check your arguments!!!
best
file_name = 'MC:\register.txt'
dont forget "\"
when u use GET_REG,dont forget the int value~!
code tested in RG 9.4
------------------------------------------------------------------------------------------------------------------
PROGRAM WriteRegMC
%NOLOCKGROUP
%COMMENT = 'Schreibt Registerwerte auf Memory Card'
VAR
reg_value : REAL
int_value : INTEGER
real_flag : BOOLEAN
reg_number : INTEGER
file_name : STRING[30]
OutStr : STRING[30]
RegFile : FILE
SAT : INTEGER
BEGIN
-- Dateiname definieren
file_name = 'MC:\register.txt'
-- Datei 枚ffnen
OPEN FILE RegFile ('RW', file_name)
IF (IO_STATUS(RegFile) <> 0 ) THEN
CLR_IO_STAT(RegFile)
WRITE('Datei konnte nicht ge枚ffnet werden', CR)
ABORT
ENDIF
-- Registerwerte auslesen und in die Datei schreiben
FOR reg_number = 1 TO 10 DO
-- Wert des Registers auslesen
GET_REG(reg_number,real_flag,int_value,reg_value,SAT)
CNV_INT_STR(int_value,16,10,OutStr)
IF (real_flag=TRUE) THEN
CNV_REAL_STR(reg_value,16,6,OutStr)
ENDIF
-- Wert in die Datei schreiben
--WRITE RegFile ('Register ', reg_number, ': ', reg_value, CR)
WRITE RegFile ('Register ', reg_number, ': ', OutStr, CR)
ENDFOR
-- Datei schlie脽en
CLOSE FILE RegFile
-- Best盲tigungsmeldung ausgeben
WRITE('Registerwerte erfolgreich auf Memory Card geschrieben', CR)
END WriteRegMC
i convert "scientific notation" to string used "CNV_" , in the txt file,i do not like scientific notation...
Thank U very much! I will test.
Br. Tomasz
Do You have some sampe KAREL Programms for me? Just to get a better undeerstanding of the Karel stuff.
Thank U
Do You have some sampe KAREL Programms for me? Just to get a better undeerstanding of the Karel stuff.
Thank U
Hi,
below it's a example of CSV file :
PROGRAM CVS_Write
%COMMENT='CVS_Write'
%NOLOCKGROUP
%NOPAUSE= ERROR+COMMAND+TPENABLE
%INCLUDE KLEVCCDF
VAR
CVS_File:FILE
Status: INTEGER
ROUTINE Clr_Scr
BEGIN
WRITE TPDISPLAY(CHR(cc_clear_win),CHR(cc_home))
WRITE TPERROR (CHR(cc_clear_win))
WRITE TPSTATUS(CHR(cc_clear_win))
WRITE TPPROMPT(CHR(cc_clear_win))
WRITE TPFUNC(CHR(cc_clear_win))
FORCE_SPMENU(TP_PANEL,SPI_TPUSER,1)
END Clr_Scr
BEGIN
Clr_Scr
OPEN FILE CVS_File('AP','test_out.csv')
Status =IO_STATUS(CVS_File)
IF Status <>0 THEN
WRITE TPDISPLAY('Open File failed',Status,CR)
ENDIF
WRITE CVS_File('test1;test2;test3',CR)
Status =IO_STATUS(CVS_File)
IF Status <>0 THEN
WRITE TPDISPLAY('Open File failed',Status,CR)
ENDIF
WRITE TPDISPLAY('Done',CR)
CLOSE FILE CVS_File
END CVS_Write
Display More
for learn i know the Youtube channel of Eduardo Suarez. These video explain step by step the programing in Karel. And are very good quality.
Hallo Yakaw,
I modified the programm. Now is working like i wanted. Thanks a lot!
Below new Code:
PROGRAM CVS_Write_V5
%COMMENT='CVS_Write'
%NOLOCKGROUP
%NOPAUSE= ERROR+COMMAND+TPENABLE
%INCLUDE KLEVCCDF
VAR
CVS_File: FILE
Status: INTEGER
reg_value1: REAL
reg_value2: REAL
reg_value3: REAL
reg_string1: STRING[10]
reg_string2: STRING[10]
reg_string3: STRING[10]
reg_value : REAL
int_value : INTEGER
real_flag : BOOLEAN
reg_number : INTEGER
file_name : STRING[30]
OutStr : STRING[30]
RegFile : FILE
SAT : INTEGER
ROUTINE Clr_Scr
BEGIN
WRITE TPDISPLAY(CHR(cc_clear_win), CHR(cc_home))
WRITE TPERROR(CHR(cc_clear_win))
WRITE TPSTATUS(CHR(cc_clear_win))
WRITE TPPROMPT(CHR(cc_clear_win))
WRITE TPFUNC(CHR(cc_clear_win))
FORCE_SPMENU(TP_PANEL, SPI_TPUSER, 1)
END Clr_Scr
BEGIN
Clr_Scr
OPEN FILE CVS_File('AP', 'test_out.csv')
Status = IO_STATUS(CVS_File)
IF Status <> 0 THEN
WRITE TPDISPLAY('Open File failed', Status, CR)
ELSE
-- Registerwerte auslesen und in die Datei schreiben
FOR reg_number = 1 TO 10 DO
-- Wert des Registers auslesen
GET_REG(reg_number, real_flag, int_value, reg_value, SAT)
-- Wert in String umwandeln
IF (real_flag=TRUE) THEN
CNV_REAL_STR(reg_value,16,6,OutStr)
ELSE
CNV_INT_STR(int_value,16,10,OutStr)
ENDIF
-- Schreibregisterwerte in die CSV-Datei
WRITE CVS_File('Register ', reg_number, ': ', OutStr, CR)
Status = IO_STATUS(CVS_File)
IF Status <> 0 THEN
WRITE TPDISPLAY('Write File failed', Status, CR)
ENDIF
ENDFOR
CLOSE FILE CVS_File
WRITE TPDISPLAY('Done', CR)
ENDIF
END CVS_Write_V5