microbit file system with JavaScript - bbc-microbit

I'm trying to write to serial:
input.onButtonPressed(Button.B, function () {
basic.showNumber(1)
serial.redirectToUSB()
serial.writeLine("dit is een test1")
let my_data = "output.txt"
files.appendLine( my_data, "lll,lll,dddl,ll099" )
files.readToSerial(my_data)
})
I followed tutorial on:
https://www.dendrite.me/media/output/mediaid/5a13f86908d73406ab61317c
and when I say:
serial.writeLine("dit is een test1")
It works great and I see it in tera term "dit is een test1"
but when I try to do it like this:
files.readToSerial(my_data)
nothing is showed :(
In the simulator it works, but on Micro:bit it doesn't show up.

The files module is at best a beta edition.
Makecode have advised not to use it, it's unsupported.
Have you tried micropython, it has good support for file system. There is also serial support, but i have little knowledge of it

Related

Can Stata help files be version specific?

Stata's ado packages quite nicely accommodate end users running different versions of Stata. For example:
program define MyGreatProgram
if int(_caller())<8 {
display as res "MyGreatProgram does not support this version of Stata, sorry."
exit
}
else {
if int(_caller())<14 {
MyGreatProgram8 `0'
}
else {
MyGreatProgram14 `0'
}
}
end
Stata's improvements with newer versions have extended to improving the possibilities in help files. For example, in Stata versions 14+, one can incorporate Unicode, and this may be very helpful in documentation (e.g., Greek characters, mathematical operators, etc.). However, in my code above, an end user of MyGreatProgram running Stata version 11, would not find help files with Unicode especially legible, while a user running Stata 15 might think they looked just fine.
Is it possible to have Stata automatically recognize separate help files for different versions of Stata, or to embed version-specific directives into Stata .sthlp files?
The comment by #NickCox suggests the following kinda clunky, but definitely workable non-automated solution:
Write different help files for different versions/version ranges a la MyGreatProgram8.sthlp, MyGreatProgram14.sthlp, etc.
Write a "foyer" help file, MyGreatProgram.sthlp, which serves as a directory to version-specific help files a la:
help MyGreatProgram
-------------------------------------------------------
Title
MyGreatProgram -- Précis of MyGreatProgram
Directory of MyGreatProgram documentation for
[Stata v 8 to Stata v 13 users]
[Stata v 14+ users]
Where [Stata v 8 to Stata v 13 users] links to MyGreatProgram8.sthlp, and [Stata v 14+ users] links to MyGreatProgram14.sthlp.

ZeroBrane : Register APIs on a per file basis

I'm writing a ZeroBrane Studio plugin for our Solarus Game Engine and It works like a charm. Autocompletion included.
I'm wondering now if it's do-able to register lua APIs for one file only.
I need this to offer autocompletion/documentation on global symbols that may vary per-script but are deducible from annex files from the engine.
To summary : Is it possible to register an api for a single file? For example in the onEditorLoad() event.
Thanks.
Greg
EDIT:
I tried the following without sucess:
local function switch_editor(editor)
if current_editor == editor then
ide:Print("same editor")
return
end
current_editor = editor
if not editor then
ide:Print("null ed")
return
end
lua_file_path = ide:GetDocument(editor).filePath
if lua_file_path:match('/data/maps/') then
ide:Print("map file!",type(editor))
local map_api = make_map_api(lua_file_path)
current_api = map_api
ide:AddAPI('lua','solarus_map',map_api)
else
ide:Print('other file')
if current_api then
ide:RemoveAPI('lua','solarus_map')
current_api = nil
end
end
end
api = {"baselib", "solarus", "solarus_map"}, --in interpreter table
... -- in the plugin table :
onEditorFocusSet = function(self,editor)
switch_editor(editor)
end,
Completion with the solarus api works fine but the on-fly registration of the solarus_map api seem not to be taken in account.
EDIT2:
Silly my, I must have done a typo, because after checking and rewriting some things pretty much as in the code pasted above... it works! Awesome!
The only small gotcha is that when switching to a file where I don't want the solarus_map API... ide:RemoveAPI isn't sufficient. Instead I must do ide:AddAPI('lua','solarus_map',{}) to replace the API with an empty one. Which I can live with.
To summary, to achieve a custom api which change from file to file:
Add the api name to the interpreter
In the onEditorFocusSet event, update the API with ide:AddAPI(...), eventually setting it to {} if it needs to be empty/disabled.
Code sample in the editions of my Question.

Psychopy and pylink example

I'm working on integrating an experiment in psychopy with the eyelink eyetracking system. The way to do this seems to be through pylink. Unfortunately I'm really unfamiliar with pylink and I was hoping there was a sample of an experiment that combines the two. I haven't been able to find one. If anyone would be able to share an example or point me towards a more accessible manual than the pylink api that sr-research provides I'd be really grateful.
Thanks!
I am glad you found your solution. I have not used iohub, but we do use psychopy and an eyelink and therefore some of the following code may be of use to others who wish to invoke more direct communication. Note that our computers use Archlinux. If none of the following makes any sense to you, don't worry about it, but maybe it will help others who are stumbling along the same path we are.
Communication between experimental machine and eye tracker machine
First, you have to establish communication with the eyelink. If your experimental machine is turned on and plugged into a live Eyelink computer then on linux you have to first set your ethernet card up, and then set the default address that Eyelink uses (this also works for the Eyelink 1000 - they kept the same address). Note your ethernet will probably have a different name than enp4s0. Try simply with ip link and look for something similar. NB: these commands are being typed into a terminal.
#To set up connection with Eyelink II computer:
#ip link set enp4s0 up
#ip addr add 100.1.1.2/24 dev enp4s0
Eyetracker functions
We have found it convenient to write some functions for talking to the Eyelink computer. For example:
Initialize Eyetracker
sp refers to the tuple of screenx, screeny sizes.
def eyeTrkInit (sp):
el = pl.EyeLink()
el.sendCommand("screen_pixel_coords = 0 0 %d %d" %sp)
el.sendMessage("DISPLAY_COORDS 0 0 %d %d" %sp)
el.sendCommand("select_parser_configuration 0")
el.sendCommand("scene_camera_gazemap = NO")
el.sendCommand("pupil_size_diameter = %s"%("YES"))
return(el)
NB: the pl function comes from import pylink as pl. Also, note that there is another python library called pylink that you can find on line. It is probably not the one you want. Go through the Eyelink forum and get pylink from there. It is old, but it still works.
Calibrate Eyetracker
el is the name of the eyetracker object initialized above. sp screen size, and cd is color depth, e.g. 32.
def eyeTrkCalib (el,sp,cd):
pl.openGraphics(sp,cd)
pl.setCalibrationColors((255,255,255),(0,0,0))
pl.setTargetSize(int(sp[0]/70), int(sp[1]/300))
pl.setCalibrationSounds("","","")
pl.setDriftCorrectSounds("","off","off")
el.doTrackerSetup()
pl.closeGraphics()
#el.setOfflineMode()
Open datafile
You can talk to the eye tracker and do things like opening a file
def eyeTrkOpenEDF (dfn,el):
el.openDataFile(dfn + '.EDF')
Drift correction
Or drift correct
def driftCor(el,sp,cd):
blockLabel=psychopy.visual.TextStim(expWin,text="Press the space bar to begin drift correction",pos=[0,0], color="white", bold=True,alignHoriz="center",height=0.5)
notdone=True
while notdone:
blockLabel.draw()
expWin.flip()
if keyState[key.SPACE] == True:
eyeTrkCalib(el,sp,cd)
expWin.winHandle.activate()
keyState[key.SPACE] = False
notdone=False
Sending and getting messages.
There are a number of built-in variables you can set, or you can add your own. Here is an example of sending a message from your python program to the eyelink
eyelink.sendMessage("TRIALID "+str(trialnum))
eyelink.startRecording(1,1,1,1)
eyelink.sendMessage("FIX1")
tFix1On=expClock.getTime()
Gaze contingent programming
Here is a portion of some code that uses the eyelink's most recent sample in the logic of the experimental program.
while notdone:
if recalib==True:
dict['recalib']=True
eyelink.sendMessage("RECALIB END")
eyelink.startRecording(1,1,1,1)
recalib=False
eventType=eyelink.getNextData()
if eventType==pl.STARTFIX or eventType==pl.FIXUPDATE or eventType==pl.ENDFIX:
sample=eyelink.getNewestSample()
if sample != None:
if sample.isRightSample():
gazePos = sample.getRightEye().getGaze()
if sample.isLeftSample():
gazePos = sample.getLeftEye().getGaze()
gazePosCorFix = [gazePos[0]-scrx/2,-(gazePos[1]-scry/2)]
posPix = posToPix(fixation)
eucDistFix = sqrt((gazePosCorFix[0]-posPix[0])**2+(gazePosCorFix[1]-posPix[1])**2)
if eucDistFix < tolFix:
core.wait(timeFix1)
notdone=False
eyelink.resetData()
break
Happy Hacking.
rather than PyLink, you might want to look into using the ioHub system within PsychoPy. This is a more general-purpose eye tracking system that also allows for saving data in a common format (integrated with PsychoPy events), and provides tools for data analysis and visualisation.
ioHUb is built to be agnostic to the particular eye tracker you are using. You just need to create a configuration file specific to your EyeLink system, and thereafter use the generic functions ioHiv provides for calibration, accessing gaze data in real-time, and so on.
There are some teaching resources accessible here: http://www.psychopy.org/resources/ECEM_Python_materials.zip
For future readers, I wanted to share my library for combining pylink and psychopy. I've recently updated it to work with python 3. It provides simple to use, high level functions.
https://github.com/colinquirk/templateexperiments/tree/master/eyelinker
You could also work at a lower level with the PsychoPyCustomDisplay class (see the pylink docs for more info about EyeLinkCustomDisplay).
For an example of it in use, see:
https://github.com/colinquirk/ChangeDetectionEyeTracking
(At the time of writing, this experiment code is not yet python 3 ready, but it should still be a useful example.)
The repo also includes other modules for creating experiments and recording EEG data, but they are not necessary if you are just interested in the eyelinker code.

ffmpeg code (API)

I started to deal with ffmpeg API ( not the command prompt ) to build a movie editor, and I'm trying to find a good tutorial about how to extract keyframes from video, but I didn't find it.
Someone did it before and can write the code here?
Someone has a good tutorial about ffmpeg API?
Thank you!
In your demuxing loop, check for the AV_PKT_FLAG_KEY flag in AVPacket::flags after calling av_read_frame() with your AVFormatContext and confirming the read packet is from the correct stream of the input. Example:
AVPacket packet;
if (av_read_frame(pFormatCtx, &packet) < 0) {
break;
}
if (videoStream/* e.g. 0 or 1 */ == packet.stream_index) {
if (packet.flags & AV_PKT_FLAG_KEY) { //do something
Note that, in my experience, you sometimes need to decode up to 2 keyframes before the desired frame in order to produce a good picture.
See the doc/examples directory in the ffmpeg distribution for some API usage examples, e.g. demuxing_decoding.c. You can also reference ffmpeg.c (the source of the famous CLI) if you are brave and/or have a good IDE.

How to get started with EPL, Visual Basic, and Zebra Printing?

I can't really find anything on how to print through EPL with Visual Basic. Can anyone help me write some simple text to the printer? I found the Zebra EPL manual so I think I can go from there, I just don't know how to get it started.
The way I do it is using the FSO to do a filecopy from of the label text file to the UNC path of the printer. (i.e. FSO.copyfile filepath, UNCpath).
Create a string with the EPL raw file (text) in it. Save it to a temp file then do the copyfile I mentioned above.
What I have found is that the best way to learn what the EPL is doing is to take an existing string and just play with the settings. Here is a sample FedEx label in EPL for you to start with. Remember - its just text.
(between the 2 'N's)
N
OD10
q812
Q1624,24
D15
ZB
LO0,459,800,4
LO0,713,800,4
LO0,1048,800,4
A35,321,0,2,1,1,N,"From:"
A35,340,0,2,1,1,N,"SHIPPING DEPT"
A35,360,0,2,1,1,N,"Company INC."
A35,380,0,2,1,1,N,"1820 SMARKET BLVD"
A35,401,0,2,1,1,N,""
A35,441,0,2,1,1,N,"(800) 999-9997"
A490,381,0,2,1,1,N,"CAD: 12345/FXRS1060"
A43,500,0,4,1,1,N,"TEST"
A43,535,0,4,1,1,N,"123-45TH"
A43,570,0,4,1,1,N,""
A35,421,0,2,1,1,N,"CHANHASSEN, MN 55317"
A490,340,0,2,1,1,N,"Ship Date: 24NOV10"
A490,360,0,2,1,1,N,"ActWgt: 12.0 LB"
A43,465,0,4,1,1,N,"TEST"
A615,465,0,2,1,1,N,"(320) 555-1212"
A43,608,0,3,1,2,N,"ST CLOUD, MN 56301"
A530,608,0,2,2,2,N,"(US)"
LO670,550,105,10
LO670,560,10,112
LO765,560,10,112
LO670,672,105,10
LO476,315,4,145
A650,485,0,3,2,2,N,"FedEx"
A690,568,0,5,2,2,N,"G"
B80,1083,0,1E,4,2,290,N,"9612304400426670000014"
A135,1397,0,4,1,1,N,"(9612302) 4000266 70000014"
A783,700,3,1,1,1,N,"J10100912242124"
A10,470,0,3,1,1,N,"TO"
A25,1420,0,3,1,1,N,"GND"
A25,1445,0,3,1,1,N,"Prepaid"
A300,1425,0,3,1,1,N,"Hazmat"
A300,1447,0,3,1,1,N,"DIRECT SIGN"
b50,740,P,800,800,s5,f0,x2,y10,r80,o0,l12,"[)>010256301840302400426670000014FDEB40042663281/112.0LBN123-45THST CLOUDMNTEST0610ZGD00411ZTEST12Z320555121223ZN22ZN20Z0.0009KTEST99ZGHAZ028004249300 26Z822a"
A645,1400,0,5,1,1,R,"HAZ"
A580,1457,0,2,1,1,N,"Emergency Contact#"
A580,1477,0,2,1,1,N,"8004249300"
A16,670,0,1,1,1,N,"Ref: TEST"
A16,685,0,1,1,1,N,"INV: "
A16,700,0,1,1,1,N,"PO: TEST"
A406,700,0,1,1,1,N,"Dept: "
P1
N
As you can see the Coordinates are the first 2 sets per line.
A indicates text I believe.
b indicates barcode.
I dont know all the parameters off the top of my head, but you mentioned you had a manual so it should list those details for you.
Hope this helps.
Here's a great blog post by Nicholas Piasecki how to send EPL code to the printer:
Sending Raw EPL2 Directly to a Zebra LP2844 via C#
I was using Zebra printers before (so I already knew EPL), but when I had to print from .NET the first time, I managed to get it to work just with the information from this blog post.
Note that the example code is in C#, but you can translate that to VB.NET.
(the post also mentions an external class named RawPrinterHelper which you can download from Microsoft - if you don't want to translate this to VB, just put it into a separate C# assembly and reference that in your VB project)
If you need to print images too, here's another blog post by the same guy about this:
Using the EPL2 GW command to send an image to a Zebra thermal printer