If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2017-02-13
Originally created by: Viacheslav Mezentsev
Up.
The same question. Is there a complete example of using asynchronous (non blocking) read? I need to read input event ('/dev/input/event1').
CoDeSys 3.5.10.x.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2017-03-15
Originally created by: Viacheslav Mezentsev
Worked example.
PROGRAMPLC_PRGvarconstant
  STATE_IDLE:   byte :=0;
  STATE_CONFIG:   byte :=1;
  STATE_OPEN:   byte :=2;
  STATE_FLUSH:   byte :=3;
  STATE_READ:   byte :=4;
  STATE_READWAIT: byte :=5;
  STATE_CATCHEVENT: byte :=6;
  STATE_CLOSE:   byte :=7;
  STATE_CLOSEWAIT: byte :=8;  end_varvar Â
  ready: bool; Â
  step: byte :=1; Â
  state: udint;
  result: RTS_IEC_RESULT;
  file : SysFileAsync.SysFileAsyncFB;
  jobparams : SysFileAsync.AsyncJob_Param;
  taskName : string :='EventTask';
 Â
  open : SysFileAsync.tSysFileOpen;
  write: SysFileAsync.tSysFileWrite;
  read: SysFileAsync.tSysFileRead;
  close : SysFileAsync.tSysFileClose;
  ulOut : SysFileAsync.RTS_IEC_RESULT;
   Â
  fileName: string :='/dev/input/event1';
  event: array [0 .. 15 ] ofbyte;  end_varcasestepof
 Â
  STATE_CONFIG:
 Â
    jobparams.TaskParam.pszTaskname   :=adr(taskName);
    jobparams.TaskParam.ulTaskPriority   :=SysFileAsync.TASK_PRIORITIES.TASKPRIO_IDLE;
    jobparams.TaskParam.ulTaskSleepTime :=10;
    jobparams.TaskParam.phTaskHandle   :=SysFileAsync.RTS_INVALID_HANDLE;
    jobparams.TaskParam.ulEndTaskAfterJob :=0;
   Â
    file.AsyncSetJobParams(SysFileAsync.ASYNCJOB_TASK, 1000000, adr(jobparams));
   Â
    step :=STATE_OPEN;
   Â
  STATE_OPEN:
 Â
    open.szFile :=fileName;
    open.am :=SysFileAsync.ACCESS_MODE.AM_READ;
    open.pulOut :=adr(ulOut);
   Â
    file.SysFileOpenAsync(adr(open), adr(state), adr(result));
    step :=STATE_READ;
   Â
  STATE_READ:
 Â
    ifstate=SysFileAsync.ASYNCSTATE_READYorstate=SysFileAsync.ASYNCSTATE_ERRORorstate=SysFileAsync.ASYNCSTATE_TIMEOUTthen
     Â
      (*Thefileiscorrectlyopened*)
      read.pbyBuffer :=adr(event);
      read.ulSize  :=sizeof(event);
      read.pResult  :=adr(result);
      read.pulOut   :=adr(ulOut);
      State :=0;
     Â
      file.SysFileReadAsync(adr(read), adr(state), adr(result));
     Â
      step :=STATE_READWAIT;
    end_if
   Â
  STATE_READWAIT:
   Â
    ready :=state=SysFileAsync.ASYNCSTATE_READYorstate=SysFileAsync.ASYNCSTATE_ERRORorState=SysFileAsync.ASYNCSTATE_TIMEOUT;
    step :=  sel(ready, STATE_READWAIT, STATE_CATCHEVENT);
 Â
  STATE_CATCHEVENT:
 Â
    step :=STATE_READ;
   Â
  STATE_CLOSE:
 Â
    close.pulOut :=adr(ulOut);
    file.SysFileCloseAsync(adr(close), adr(state), adr(result));   Â
    step :=STATE_CLOSEWAIT;
   Â
  STATE_CLOSEWAIT:
 Â
    ready :=state=SysFileAsync.ASYNCSTATE_READYorstate=SysFileAsync.ASYNCSTATE_ERRORorState=SysFileAsync.ASYNCSTATE_TIMEOUT;
   Â
    (*Thefileiscorrectlyclosed*)
    step :=  sel(ready, STATE_CLOSEWAIT, STATE_IDLE);   Â
   Â
  STATE_IDLE:  ;
 Â
end_case
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
should work, but meanwhile due security reason only readings allowed in /var/opt/codesys/PlcLogic directory
/dev/input/event1 need then to be added in config file
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
[CmpLog]
Logger.0.Name=/tmp/codesyscontrol.log
Logger.0.Filter=0x0000000F
Logger.0.Enable=1
Logger.0.MaxEntries=1000
Logger.0.MaxFileSize=1000000
Logger.0.MaxFiles=1
Logger.0.Backend.0.ClassId=0x00000104 ;writes logger messages in a file
Logger.0.Type=0x314 ;Set the timestamp to RTC
When I run the following program, I get in ResultAsync the error 2.
That means invalid parameter for this operation.
What can be the cause of this ?
// DECLARATION:
PROGRAM Test
VAR
udStateOpen: UDINT := 16#FFFFFFFF;
TestFB : SysFileAsyncFB;
SFO : tSysFileOpen;
TestString: STRING;
TestAccessMode: UDINT;
Result, ResultAsync, OUT, hJob: UDINT;
END_VAR
// IMPLEMENTATION:
SFO.szFile := TestString;
SFO.am := TestAccessMode;
SFO.pResult := ADR(Result);
SFO.pulOut := ADR(OUT);
hJob := TestFB.SysFileOpenAsync(ADR(SFO), ADR(udStateOpen), ADR(ResultAsync));
Originally created by: Viacheslav Mezentsev
Up.
The same question. Is there a complete example of using asynchronous (non blocking) read? I need to read input event ('/dev/input/event1').
CoDeSys 3.5.10.x.
Originally created by: Viacheslav Mezentsev
Worked example.
@Edwin Schwellinger: Would this work with a raspberry pi also?
should work, but meanwhile due security reason only readings allowed in /var/opt/codesys/PlcLogic directory
/dev/input/event1 need then to be added in config file
Just realized that it is the /dev/input/js0 file.
Don't think this is a prob either.
Found the ConfigFile.
Where and how to add /dev/input/js0?
raspberry
[SysFile]
FilePath.1=/etc/, 3S.dat
PlcLogicPrefix=1
[SysTarget]
TargetVersionMask=0
TargetVersionCompatibilityMask=0xFFFF0000
[CmpLog]
Logger.0.Name=/tmp/codesyscontrol.log
Logger.0.Filter=0x0000000F
Logger.0.Enable=1
Logger.0.MaxEntries=1000
Logger.0.MaxFileSize=1000000
Logger.0.MaxFiles=1
Logger.0.Backend.0.ClassId=0x00000104 ;writes logger messages in a file
Logger.0.Type=0x314 ;Set the timestamp to RTC
[CmpSettings]
FileReference.0=SysFileMap.cfg, SysFileMap
FileReference.1=/etc/CODESYSControl_User.cfg
[SysExcept]
Linux.DisableFpuOverflowException=1
Linux.DisableFpuUnderflowException=1
Linux.DisableFpuInvalidOperationException=1
[CmpWebServer]
ConnectionType=0
[CmpOpenSSL]
WebServer.Cert=server.cer
WebServer.PrivateKey=server.key
WebServer.CipherList=HIGH
[SysMem]
Linux.Memlock=0
[CmpCodeMeter]
InitLicenseFile.0=3SLicense.wbb
[SysEthernet]
Linux.ProtocolFilter=3
[CmpSchedule]
ProcessorLoad.Enable=1
ProcessorLoad.Maximum=95
ProcessorLoad.Interval=5000
DisableOmittedCycleWatchdog=1
[CmpUserMgr]
AsymmetricAuthKey=6873d655ac1f166f3743feea42d2f3dd1b39ae40
[CmpSecureChannel]
CertificateHash=09fd8d52be4ddd45a709bc9c95e2aa093b3f5695
[SysSocket]
Adapter.0.Name="eth0"
Adapter.0.EnableSetIpMask=1
;raspberry
[ComponentManager]
;Component.1=CmpGateway
;Component.2=CmpGwCommDrvTcp
;Component.3=CmpGwCommDrvShm
[SysCom]
;Linux.Devicefile=/dev/ttyS
[CmpBlkDrvCom]
;Com.0.Name=MyCom
;Com.0.Baudrate=115200
;Com.0.Port=3
;Com.0.EnableAutoAddressing=1
[SysProcess]
Command.0=shutdown
[CmpApp]
Bootproject.RetainMismatch.Init=1
;Application.1=Application
;Application.1=Application
;Application.1=Application
Application.1=Application
[CmpRasPi]
Architecture=armv6l
[CmpRedundancyConnectionIP]
[CmpRedundancy]
[CmpSrv]
[IoDrvEtherCAT]
Last edit: solve-it 2024-07-16
It works without adding "/dev/input/js0" in config file.
Great!
Last edit: solve-it 2024-07-17