Lua custom file name - lua

In my company i've a QR reader made by Keyence with which we read codes in our production line.
The images acquired by the sensor are saved on an FTP server, and for business needs, the name of the images must be in the format: yyyymmdd_qrcodecontent.jpg.
On the sensor we already have a script in .lua that saves the images with the naming qrcodecontent.jpg.
I don't know the lua language, and from the documentation I could not find info on how to add date information
Do you have any suggestions or advice?
fmset.lua
function nameformatEvent()
local read_data
read_data = readResult():readData()
return(read_data)
end

Lua provides date and time through its os library.
https://www.lua.org/manual/5.4/manual.html#pdf-os
You can get a formatted date string through os.date.
Search the Keyence scripting manual for date and time. Run a script with print(os). If it prints nil that library is not available. At least it is not listed in the manual while some other standard libraries are.
If Keyence's scripting API does not provide the os library and no other means to get the current date and time you cannot access that information.
I'm not aware that the Keyence readers have a realtime clock on-board, so that information is probably not available on the sensor.
Get in touch with the Keyence support. That's what they're getting payed for.

You can probably use some os functions.
For the date formatting on the filename, you could write a quick function like this:
function GenerateFilename()
return os.date("%d%m%y") .. "_qrcodecontent"
end
You can probably configure a filename somewhere. I don't know what the code for readResult and :readData is, but check the content of those functions.
Just add .jpg/.jpeg to the end if it doesn't generate the file extension (change _qrcodecontent to _qrcodecontent.jpg).

Related

How can I check if my react-intl messages are consistent with my en-US locale?

I want to have some type of script that will check if all the formattedMessage I have in my React components are consistent with the data I have in my en-US.json locale.
I'm using react-intl, and in my React components I use both the FormattedMessage component, as well as the formatMessage function. The FormattedMessage component is imported from react-intl, and the formatMessage function is a function from the useIntl object, which is imported from react-intl.
What is a good way to proceed with this analysis and comparison? I want to ensure that all the keys and values that exist in these FormattedMessages, match the keys and values in my en-US.json locale. This script will be run as part of my Github Workflow.
I don't know how to get started on this.

What is the recommended way to make & load a library?

I want to make a small "library" to be used by my future maxima scripts, but I am not quite sure on how to proceed (I use wxMaxima). Maxima's documentation covers the save(), load() and loadFile() functions, yet does not provide examples. Therefore, I am not sure whether I am using the proper/best way or not. My current solution, which is based on this post, stores my library in the *.lisp format.
As a simple example, let's say that my library defines the cosSin(x) function. I open a new session and define this function as
(%i0) cosSin(x) := cos(x) * sin(x);
I then save it to a lisp file located in the /tmp/ directory.
(%i1) save("/tmp/lib.lisp");
I then open a new instance of maxima and load the library
(%i0) loadfile("/tmp/lib.lisp");
The cosSin(x) is now defined and can be called
(%i1) cosSin(%pi/4)
(%o1) 1/2
However, I noticed that a substantial number of the libraries shipped with maxima are of *.mac format: the /usr/share/maxima/5.37.2/share/ directory contains 428 *.mac files and 516 *.lisp files. Is it a better format? How would I generate such files?
More generally, what are the different ways a library can be saved and loaded? What is the recommended approach?
Usually people put the functions they need in a file name something.mac and then load("something.mac"); loads the functions into Maxima.
A file can contain any number of functions. A file can load other files, so if you have somethingA.mac and somethingB.mac, then you can have another file that just says load("somethingA.mac"); load("somethingB.mac");.
One can also create Lisp files and load them too, but it is not required to write functions in Lisp.
Unless you are specifically interested in writing Lisp functions, my advice is to write your functions in the Maxima language and put them in a file, using an ordinary text editor. Also, I recommend that you don't use save to save the functions to a file as Lisp code; just type the functions into a file, as Maxima code, with a plain text editor.
Take a look at the files in share to get a feeling for how other people have gone about it. I am looking right now at share/contrib/ggf.mac and I see it has a lengthy comment header describing its purpose -- such comments are always a good idea.
For principiants, like me,
Menu Edit:configure:Startup commands
Copy all the functions you have verified in the first box (this will write your wxmaxima-init.mac in the location indicated below)
Restart Wxmaxima.
Now you can access the functions whitout any load() command

Get localized name other channel

I get the version number of the firefox from the applications.ini.
Then I hardcoded that between date #### and #### v35 is release. So now based on this and the current date and version from applications.ini I figure out the channel of other builds.
But now I want to get the localized name of the channel.
So for example I'm using beta channel and from this build I want to get the localized name of "Nightly" in chineese, so it has the chineese characters, and word for nightly in chineese. Can this also be obtained from the applications.ini? Is [App] -> Name localized in applications.ini?
This is the applications.ini method: https://ask.mozilla.org/question/705/detect-if-auroranightlybetanormal-and-get-paths/ (credits to #paa)
EDIT
i discovered this file: OS.Path.join(Services.dirsvc.get('XREExeF', Ci.nsIFile).parent.path, 'defaults', 'pref', 'channel-prefs.js')
its contents is the following:
//#line 2 "c:\builds\moz2_slave\rel-m-beta-w32_bld-00000000000\build\browser\app\profile\channel-prefs.js"
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
pref("app.update.channel", "beta");
Is this a reliable check? Does this channel-prefs.js file exist for all builds as soon as they are installed?
Is this a reliable check?
Not really. There used to be channel switcher add-ons, and in theory the user can change this pref (although at the moment this is not sufficient to really switch the channel I think).
Does this channel-prefs.js file exist for all builds as soon as they are installed?
Yes, for now. But this is an implementation detail. There is no guarantee that the file won't be moved or renamed later, or merged with another file.
Can this also be obtained from the applications.ini?
The localized name? I didn't even know there was one... I thought it was called e.g. "Nightly" in all locales like it was a (product) name. But yeah, it is theoretically possible to localize that string. It is not available from the ini file, though.
I wouldn't poke in application.ini anyway, and instead just use Services.appinfo.defaultUpdateChannel
But now I want to get the localized name of the channel.
Since you're in a running Firefox instance already (judging from your OS.File code), you should use the string bundle service to load chrome://branding/locale/brand.properties and get the brandShortName or brandFullName string from there.

Lua - My documents path and file creation date

I'm planning to do a program with Lua that will first of all read specific files
and get information from those files. So my first question is whats the "my documents" path name? I have searched a lot of places, but I'm unable to find anything. My second question is how can I use the first four letters of a file name to see which one is the newest made?
Finding the files in "my documents" then find the newest created file and read it.
The reading part shouldn't be a problem, but navigating to "my documents" and finding the newest created file in a folder.
For your first question, depends how robust you want your script to be. You could use Lua's builtin os.getenv() to get a variety of environment vars related to user, such as USERNAME, USERPROFILE, HOMEDRIVE, HOMEPATH. Example:
username = os.getenv('USERNAME')
dir = 'C:\\users\\' .. username .. '\\Documents'
For the second question, there is no builtin mechanism in Windows to have the file creation or modification timestamp as part of the filename. You could read the creation or modification timestamp, via a C extension you create or using an existing Lua library like lfs. Or you could read the contents of a folder and parse the filenames if they were named according to the pattern you mention. Again there is nothing built into Lua to do this, you would either use os.execute() or lfs or, again, your own C extension module, or combinations of these.

How to get Date and Time the picture was taken at?

I am writing a program in Delphi which should get the date and time of the picture which was taken with photo cam and then it would rename the file to include the date+time it found.
So far i have achieved that by opening file as binary and searching for a special order of bytes. These bytes were then followed by the date and then time. So i've come to a problem. Actually few problems.
Because it reads the file 1 byte after another, reading a file is a slow process. If the date was found, it is usually at the start of file, it doesn't take long, however if 'special byte order' was not found, it will read the whole file. So my method is way too slow.
The special byte order may change in some pictures (i have no idea why) even if it was taken with the same camera. So my program sometimes fails to find the date in the file even though it is there.
Windows explorer has no problems finding date in all of the pictures, so i was thinking maybe there are some kind of special functions which could get me what i need?
How do i get the information i need from the picture so it works with all the formats?
Thanks
I think you only need to look at the EXIF information. http://en.wikipedia.org/wiki/Exif
There are some open source tools which accomplish that, but I don't know of anything Delphi specific. If you're not scared of Java, you can have a look at the source code of this open source project: http://sourceforge.net/projects/jexifviewer/ to see how they evaluate the date field.
You can then optimise your reader, to only look at the relevant area. You might want to keep in mind that the Endianness in Java is different to Delphi.
Jules is right about Exif data; you might want to try this Delphi library:
http://delphihaven.wordpress.com/ccr-exif/
This is an amazing site to view Exif data.
http://regex.info/exif.cgi
If it is a graphic file (as in your case), to open it with a dialog box, place a TOpenPictureDialog component on the form.
Also place the component TLabel, for displaying the date of creation of the file.
In the button's place the following code:
if OpenPictureDialog1.Execute then Label1.Caption := DateTimeToStr(FileDateToDateTime(FileAge(OpenPictureDialog1.FileName));
In order to open jpeg and png files in the code, in the line uses you need to add the name of the two libraries, JPEG, PNGImage.
If you have the full address of your file, you can write the code above instead of the code above:
Label1.Caption := DateTimeToStr(FileDateToDateTime(FileAge('full address to file')));
If you only need the date, without the file creation time, then instead of the DateTimeToStr command, use the DateToStr command.

Resources