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