Skip to content

Commit

Permalink
add examples of IO reading and writing
Browse files Browse the repository at this point in the history
  • Loading branch information
vnadot committed Mar 6, 2019
1 parent 294a4c4 commit 25e1fea
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions snippets/c.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,46 @@

"aSub Record C subroutine": {
"prefix": "asub_code",
"body": [ "static long ${1:my_asub_routine}(aSubRecord *precord){",
" ${2:// insert code here}",
"body": [ "// most of these examples are coming from Yves Lussignol (https://drf-gitlab.cea.fr/, signalProcessingApp module)",
"// the goal is to provide examples of reading and writing in different variable types",
"static long ${1:my_asub_routine}(aSubRecord *precord){",
" // inputs:",
" // - a: short",
" // - b: float[]",
" // - c: int",
" // outputs:",
" // - vala: float",
" // - valb: float[]",
" ",
" // inputs",
" short inputA = *(short *)precord->a; // input scalar",
" epicsFloat32 *inputB_array = (epicsFloat32 *)precord->b; // input array",
" int nob = precord->nob // nb of element in array (input b)",
" int inputC = *(epicsUInt32 *)precord->c;",
" ",
" // read the whole input array (input b)",
" float val;",
" for (int i=0; i<nbOfElement; i++) {",
" val = *inputB_array++;",
" // read cell 3 of input array (input b)",
" val = inputB_array[2]; // <=> val = ((epicsFloat32 *)precord->b)[2];",
" ",
" // write the whole output array (output b)",
" epicsFloat32 *outputB_array = (epicsFloat32 *)precord->valb;",
" for(int i=0; i < nbOfElement; i++){",
" *outputB_array++ = i;",
" }",
" // write cell 3 of output array (ouput b)",
" outputB_array[2] = 3.14; // <=> ((epicsFloat32 *)precord->valb)[2] = 3.10;",
" ",
" ${2:// insert your code here}",
" ",
" // outputs",
" *(float *)precord->vala = 94.77;",
" precord->nevb = outsize; // number of output array elements",
" ",
" return 0;",
"}",
"epicsRegisterFunction(${1:my_asub_routine});"]
}
}
}

0 comments on commit 25e1fea

Please sign in to comment.