PLCS.net - Interactive Q & A

PLCS.net - Interactive Q & A (http://www.plctalk.net/qanda/index.php)
-   LIVE PLC Questions And Answers (http://www.plctalk.net/qanda/forumdisplay.php?f=2)
-   -   Read excel file in Red Lion (http://www.plctalk.net/qanda/showthread.php?t=122664)

Ce.O November 7th, 2019 12:06 PM

Read excel file in Red Lion
 
Hello
I am working in a project where I have to read data from an excel file. I'm not sure whether this is possible. The screen that I'm using is a Red Lion Cr3000700000420, I'm workig with Crimson 3.1

What I want to do is make a comparison from a text that is enter with a scanner and check whether this data is in the excel file.

Elcan November 7th, 2019 12:52 PM

I never read from an Excel file, but from a text file.
In the Crimson menu, go to Help -> Reference. In the Reference manual, look for the file instructions, like OpenFile, ReaFile, etc.
You need to create a program in the Programs tab.

Ce.O November 7th, 2019 02:40 PM

Like CSV? is it possible to read an specific cell with csv files?
Do you read the files from an USB or sd card?
Thanks for your answer

Elcan November 7th, 2019 03:17 PM

Quote:

Originally Posted by Ce.O (Post 831311)
Like CSV? is it possible to read an specific cell with csv files?
Do you read the files from an USB or sd card?
Thanks for your answer

Yes, it can be cvs. You'll need to convert/export the spreadsheet to csv or txt. Each cell will be separate by commas or some other character that you can select.
In my case, I'm reading from the sd or compactflash card.

Ce.O November 7th, 2019 03:30 PM

Could you give me an example please?
I have never read files in red lion
I did this program and create a tag called dato, and I tried to read the file but it didn't work.
int archivo;
archivo = OpenFile("Volumen.csv",0);
FileSeek(archivo,23);
dato = ReadFileLine(archivo);

Elcan November 8th, 2019 05:24 AM

Quote:

Originally Posted by Ce.O (Post 831319)
Could you give me an example please?

Here you are. I also sent you a private message.

/* This program reads a file where the tag names and its values are stored in */

int tagindex; int Hfile; int count; int space1; int space2; int decimal;
int IntValue; float FloatValue;
cstring line; cstring TagName; cstring TextValue;

//Open file
Hfile := OpenFile("/param/param.txt", 1);
//Read a line from the file
line := ReadFileLine(Hfile);

//While the line read from the files retrieves something, keep reading
while (Len(line)>0)
{
//Read the position of the first and second space occurrence
//Example of line: Polisher_System.Polisher.Vibration 22 mm/s
space1 := Find(line,' ',0);
space2 := Find(line,' ',1);
//The tag name is the section before the first space
TagName := Left(line, space1);
//The tag value is located between the first and the second spaces
TextValue := Mid(line, space1+1, space2-space1);
//Find the tag index
tagindex = FindTagIndex(TagName);

//Find out if the value is decimal (has a ".")
decimal := Find(TextValue,'.',0);

//Write the value to the corresponding tag in Crimson
if (decimal == 0)//If the tag is a integer
{IntValue= TextToInt(TextValue,10);
SetIntTag(tagindex,IntValue);}
else //If the tag is a float
{FloatValue= TextToFloat(TextValue);
SetRealTag(tagindex,FloatValue);}

//Read a new line from the file
line := ReadFileLine(Hfile);
}

//Close the file
CloseFile(Hfile);

Ce.O November 8th, 2019 09:48 AM

Thank you very much


All times are GMT -5. The time now is 12:46 PM.

.