Search talk: Object reference not set to an instance of an object

 
<< < 1 .. 9 10 11 12 13 .. 286 > >> (Page 11 of 286)

how to ping an IP address CODESYS Forge talk (Thread)
how to ping an IP address
Last updated: 2018-11-26

way to open the libraries from an open project. CODESYS Forge talk (Thread)
way to open the libraries from an open project.
Last updated: 2016-12-01

Connceting an Anybus .Net-to-Ethernet/IP Device CODESYS Forge talk (Thread)
Connceting an Anybus .Net-to-Ethernet/IP Device
Last updated: 2020-03-12

How to Ping an IP address in CoDeSys CODESYS Forge talk (Thread)
How to Ping an IP address in CoDeSys
Last updated: 2018-11-22

Deploy an external library to CODESYS Control RTE v3 CODESYS Forge talk (Thread)
Deploy an external library to CODESYS Control RTE v3
Last updated: 2017-02-16

Providing an own download server to download missing libraries CODESYS Forge talk (Thread)
Providing an own download server to download missing libraries
Last updated: 2018-04-17

How to send an SDO message. CODESYS Forge talk (Thread)
How to send an SDO message.
Last updated: 2012-02-07

how to download an application permanently in turck device CODESYS Forge talk (Thread)
how to download an application permanently in turck device
Last updated: 2015-02-03

How to create an array dynamically CODESYS Forge talk (Thread)
How to create an array dynamically
Last updated: 2009-06-16

How to open an .EXE file window from Codesys CODESYS Forge talk (Thread)
How to open an .EXE file window from Codesys
Last updated: 2024-04-18

Post by struccc on Inheritence of struct, CODESYS Forge talk (Post)
Strangely reminds me to my struggles... Want to do something "Elegant", reusable, universal, practical... In CODESYS??? 🙃 First of all, before you get too deep into this: If you could find a way, to make a "universal" log entry object, containing the variable length data itself, you wouldn't be able to store them in an array, or access them like an array, or pass them by value as a type. (please correct me, if I'm wrong, incorrect, or not precise). Because... Basically you can't declare a type with variable memory footprint. This is a very deeply embedded characteristic of CODESYS, and all IEC 61131-3 systems, and it has many reasons behind. And yes, it is a very common trap / mistake, to forget about. So, with a log entry - I guess - it's pretty much the purpose: store data and metadata together, and then handle it in a uniform way. There are ways to handle this, really depends on what is the purpose. For example: 1. Entries with fixed length (Maybe it is not as evil as it looks for the first time. Depends on the situation, but definitely the fastest and easiest code) You can have your base object, with an internal, fixed length string or byte array variable. I would go with a string, and call it _Data.; And then you can make properties, like As_Bool, As_Int, As_Real... In the 'set' accessors, you can do like: pReal := ADR(_Data); // POINTER TO REAL As_Real := pReal^; In the 'get' accessors, evidently: pReal := ADR(_Data); // POINTER TO REAL pReal^ := AS_Real; Or, can use ANY type, if you are not obsessed with variable / property like access: 2. Fixed length, but nicer First, some disadvantage to any values: - You can only assign values with write access. No literals, constants, etc... - Can only be used as input variable of function or function_block - Therefore, stg you could reach: LogEntry.Initialize (stVariable|rVariable|iVariable|xVariable); Just a quick example (it's funny to play with ANY): Be careful it was not tested. I'm sure can be done better, please feel free to comment FUNCTION_BLOCK FB_LogEntry VAR_INPUT MsgClass : UDINT; // Like DEBUG, WARN, ERR... MsgCode : UDINT; // Like Errors.ERR_FAILED MsgTS : DT; // The timestamp END_VAR VAR _Data : STRING(80); // Our data container... _Descr : __SYSTEM.AnyType; // A standard descriptor for our data, containing TYPE_CLASS, address and size END_VAR METHOD SET_Value : BOOL VAR_INPUT anyValue : ANY; END_VAR VAR I : DINT; diSize : DINT; pStr : POINTER TO STRING; END_VAR // Check what did we receive in anyValue. diSize := anyValue.diSize; // We use constant __SYSTEM.TYPE_CLASS to identify the received data type CASE anyValue.TypeClass OF // Maybe we don't want to store references, pointers... and who knows what else... __SYSTEM.TYPE_CLASS.TYPE_REFERENCE, __SYSTEM.TYPE_CLASS.TYPE_POINTER : SET_Value := FALSE; // For the planned types we will be just fine. TYPE_CLASS.TYPE_BOOL, TYPE_CLASS.TYPE_INT, TYPE_CLASS.TYPE_REAL : SET_Value := TRUE; // Optionally string can be handled separately, maybe we have received STRING(255), but practically it is shorter than 80 bytes... TYPE_CLASS.TYPE_STRING : pStr := anyValue.pValue; diSize := MIN(anyValue.diSize, LEN(pStr^) + 1); // Get the actual size, and rewrite the received structure member diSize := MIN(SIZEOF(_Data), diSize); // Can chop down the received string to our length... SET_Value := TRUE; // Maybe want to play a little bit more here, to narrow down or convert datatypes, etc... // Or just reject any other datatype ELSE SET_Value := FALSE; RETURN; END_CASE // Fail, if the received value is still larger than our container... IF diSize > SIZEOF(_Data) THEN SET_Value := FALSE; END_IF // Here we should be ok, just set up the _DataType structure, and copy store the data IF SET_Value THEN THIS^._Descr.TypeClass := anyValue.TypeClass; // The typeclass is already filtered THIS^._Descr.diSize := diSize; // Set the (adjusted) size THIS^._Descr.pValue := ADR(_Data); // This will not change, just to be sure {IF defined (pou:SysMem.SysMemCpy)} SysMem.SysMemCpy(_DataType.pValue, anyValue.pValue, TO_UDINT(anyValue.diSize)); {ELSE} // An ugly replacement MemCpy FOR I:=0 TO diSize - 1 DO _Descr.pValue[I] := anyValue.pValue[i]; END_FOR {END_IF} // Otherwise, in case of failure maybe better set an empty value (overwrite the former data descriptor) ELSE THIS^._Descr.TypeClass := TYPE_CLASS.TYPE_NONE; THIS^._Descr.pValue := ADR(_Data); THIS^._Descr.diSize := 0; END_IF METHOD GET_Value : BOOL VAR_INPUT anyValue : ANY; END_VAR VAR I : DINT; END_VAR // We just have to serve the data, using the __System.AnyType structure received // Roughly we can say: IF anyValue.TypeClass = _Descr.TypeClass AND anyValue.pValue <> 0 // This should not be possible, already taken care of by Codesys (?) THEN {IF defined (pou:SysMem.SysMemCpy)} SysMem.SysMemCpy(anyValue.pValue, _DataType.pValue, TO_UDINT(MIN(anyValue.diSize, _Descr.diSize))); {ELSE} // An ugly replacement MemCpy FOR I:=0 TO MIN(anyValue.diSize -1, _Descr.diSize - 1) DO anyValue.pValue[I] := _Descr.pValue[I]; END_FOR {END_IF} // Just to make sure, that our string is terminated... IF anyValue.TypeClass = TYPE_CLASS.TYPE_STRING THEN anyValue.pValue[anyValue.diSize -1] := 0; END_IF GET_Value := TRUE; RETURN; END_IF // ... But can play more CASE anyValue.TypeClass OF TYPE_CLASS.TYPE_WSTRING : ; // Could do conversion TYPE_CLASS.TYPE_XSTRING : ; // Wow, I have to figure this out TYPE_CLASS.TYPE_PARAMS : ; // BTW, what is this, how to use? TYPE_CLASS.TYPE_ANYNUM : ; // ... END_CASE Be careful it was not tested. I'm sure can be done better, please feel free to comment 3. If you really want to do entries with variable size In a standard environment, it would be similar to the previous, except you dont have the container variable _Data, just use a pointer, practically _Descr.pValue At Initialize (SET_Value), you have to allocate the memory, would be easy with SysMem.SysMemAlloc - nowadays with SysMem.SysMemAllocData -, and you make sure to release it after use with SysMem.SysMemFreeData... SysMemAlloc was already hidden. The problem with this, that sooner or later your application will totally fragment the dynamic memory, and fail... So should look for some form of dynMaybe MemUtils.MemoryManager (I am not sure what is the status and the future of it). 4. You will end up by a LogEntry Factory ... 5. You could still have a look at this IEC Snippets BTW, Standard Codesys Logger is not a bad choice either. If you are really interested, I share some more code / library.
Last updated: 2025-03-09

addressin an array of byte containing bits of type bool CODESYS Forge talk (Thread)
addressin an array of byte containing bits of type bool
Last updated: 2018-11-14

an element of "Array of BOOL" in SFC Action name CODESYS Forge talk (Thread)
an element of "Array of BOOL" in SFC Action name
Last updated: 2008-05-05

Post by charleskentyfz on (no subject) CODESYS Forge talk (Post)
I have created an EtherCAT slave code and fixed two slaves (IDs written in the 0xF050 object dictionary). The module IDs are 0x1 and 0x101, respectively. It can be scanned normally in TwinCAT, but when scanning in CODESYS, it reports an error. Why is this happening?text in the second pic means 'device cannot be found in repository'
Last updated: 2024-07-07

Post by superjojo2002 on Licensing info not available. CODESYS Forge talk (Post)
I just want to highlight, that we intend to use the codesys runtime on an embedded device that has no possibilites to connect any dongle devices to. It is an edge IO-Link master with an 1.6GHz ARM computer running inside that has an embedded linux running and a Docker container engine: https://www.hilscher.com/de/produkte/edge-gateways-mit-container-management/edge-io-link-master
Last updated: 2024-03-20

Throw an own exception CODESYS Forge talk (Thread)
Throw an own exception
Last updated: 2020-03-13

Zwei MPC3008 an Raspberry CODESYS Forge talk (Thread)
Zwei MPC3008 an Raspberry
Last updated: 2014-08-26

Datenübergabe an Visual Basic CODESYS Forge talk (Thread)
Datenübergabe an Visual Basic
Last updated: 2006-10-18

Licensing an R-PI ? CODESYS Forge talk (Thread)
Licensing an R-PI ?
Last updated: 2023-03-21

Maximale Anzahl an Task CODESYS Forge talk (Thread)
Maximale Anzahl an Task
Last updated: 2006-09-04

Sorting an array CODESYS Forge talk (Thread)
Sorting an array
Last updated: 2021-11-25

Winkelencoder an 750-637 CODESYS Forge talk (Thread)
Winkelencoder an 750-637
Last updated: 2008-12-02

Anschluss an MSSQL CODESYS Forge talk (Thread)
Anschluss an MSSQL
Last updated: 2010-05-11

anschluss an Mysql CODESYS Forge talk (Thread)
anschluss an Mysql
Last updated: 2018-07-24

Operation behind an NAT? CODESYS Forge talk (Thread)
Operation behind an NAT?
Last updated: 2011-01-03

<< < 1 .. 9 10 11 12 13 .. 286 > >> (Page 11 of 286)

Showing results of 7144

Sort by relevance or date