Search talk: CAST LREAL INT

 
<< < 1 2 3 4 5 > >> (Page 4 of 5)

Post by talhaali on Alarm status in logic CODESYS Forge talk (Post)
Hi, I am trying to access active alarms in code(As alarm count variable updates only when we go to to alarm table frame in visualization). I wrote following code but it is not working: VAR iCountActiveAlarms : INT; parritfActiveAlarms : POINTER TO ARRAY[0..0] OF IAlarm; itfAlarmManagerClientAll : IAlarmManagerClient; END_VAR AlarmManager.g_AlarmHandler.GetActiveAlarms( itfAlarmManagerClient :=itfAlarmManagerClientAll, iCountActiveAlarms => iCountActiveAlarms, parritfActiveAlarms => parritfActiveAlarms); The Value is always 0. Please help.
Last updated: 2024-06-06

Post by garmusd on Raspberry Pi 5 GPIO not working. CODESYS Forge talk (Post)
Hi, Codesyscontrol 4.13.0.0 Raspberry Pi5 64bit with latest updates. Cant get working GPIO - no output and no input. SPI/I2C not tested. GPIOs B+/Pi2, Input/Output is set in the parameters, assigned variables int the Mapping. Absolutely no reaction. Do I need to configure anything else to make it work? Thanks!
Last updated: 2024-09-26

Post by timvh on Converting each character to a string into ASCII CODESYS Forge talk (Post)
Nice puzzle for a Saturday afternoon :-). Here my suggestion: VAR sInput : STRING := 'R123'; byChar : BYTE; sOutput : STRING; i: INT; END_VAR sOutput := ''; IF LEN(sInput) = 0 THEN RETURN; END_IF FOR i := 0 TO LEN(sInput) - 1 DO byChar := sInput[i]; sOutput := Concat(sOutput, TO_STRING(byChar)); END_FOR
Last updated: 2024-11-09

Post by davidmic on Struct Literal CODESYS Forge talk (Post)
Hi all I want to pass a struct into a function without declaring the struct in a VAR/END_VAR. Is this possible? I think this would be called a struct literal It would look something like this someFB.write(structArgument := MyStruct#(a := 1, b := 1.2), otherArgument := TRUE); With this struct declaration TYPE MyStruct : STRUCT a : INT; b : REAL; END_STRUCT END_TYPE
Last updated: 2025-03-28

Post by benemenn on Type mappings in Datasource CODESYS Forge talk (Post)
Hi! I am trying to achieve the same issue. Has there been a solution? I can create the mapping, and map the local variable, but somehow the object does not update. Furthermore, i have an issue where codesys doesn't let me set ReadWrite accesses to the variables in the "Type Mapping" place. The access will simply not be set. Has anyone ran int that issue?
Last updated: 2025-04-02

Post by timvh on Active alarm access in ST CODESYS Forge talk (Post)
See https://forge.codesys.com/forge/talk/Engineering/thread/280fdf4806/#9fe5 And https://forge.codesys.com/prj/codesys-example/alarm-manager/home/Home/ The application should contain: - an FB which implements AlarmManager.IAlarmFilterCriteria (see example - FB_AlarmFilterCriteria) - an FB which implements AlarmManager.IAlarmManagerClient (see example - FB_AlarmManagerClient) Then register the client and get the information through this client. VAR xInit : BOOL := TRUE; udiResult : UDINT; fbAlarmFilterCriteriaAll : FB_AlarmFilterCriteria; fbAlarmManagerClientAll : FB_AlarmManagerClient; itfAlarmManagerClientAll : IAlarmManagerClient := fbAlarmManagerClientAll; xAlarm1 : BOOL; xAlarm2 : BOOL; xWarning : BOOL; iNrOfAlarmsInAlarmList : INT; iNrOfActiveAlarmsInAlarmList : INT; paitfAlarm: POINTER TO ARRAY [0..0] OF AlarmManager.IAlarm; iAlarmIndex : INT; eAlarmState: AlarmManager.AlarmState; END_VAR IF xInit THEN xInit := FALSE; fbAlarmManagerClientAll.m_itfAlarmFilterCriteria := fbAlarmFilterCriteriaAll; // register alarm client to get updated about alarm status / changes udiResult := AlarmManager.g_AlarmHandler.RegisterClient(itfAlarmManagerClientAll, 0, 0); END_IF // Polling the number of alarms udiResult := AlarmManager.g_AlarmHandler.GetActiveAlarms(itfAlarmManagerClientAll, parritfActiveAlarms => paitfAlarm, iCountActiveAlarms => iNrOfAlarmsInAlarmList); iAlarmIndex := 0; iNrOfActiveAlarmsInAlarmList := 0; WHILE iAlarmIndex < iNrOfAlarmsInAlarmList DO eAlarmState := paitfAlarm^[iAlarmIndex].GetState(); IF eAlarmState = AlarmManager.AlarmState.Active OR eAlarmState = AlarmManager.AlarmState.ActiveAcknowledged THEN iNrOfActiveAlarmsInAlarmList := iNrOfActiveAlarmsInAlarmList + 1; END_IF iAlarmIndex := iAlarmIndex + 1; END_WHILE
Last updated: 2025-04-23

Post by r-niedermayer on C0564 Warning Message CODESYS Forge talk (Post)
Please see or Online Help on how to initialize variable before using them: https://content.helpme-codesys.com/en/CODESYS%20Development%20System/_cds_pragma_attribute_global_init_slot.html Regarding the Attribute global_init_slot: You can use this pragma to influence the order in which signatures are processed during global initialization. It can only be applied to signatures. By default, the initialization sequence for variables from global variable lists is undefined! However, if, for example, variables from one list depend on variables from another list, it is necessary to initialize one before the other. (Aee OLH and Syntax) The placeholder <slot> must be replaced by an integer value that defines the position in the initialization sequence.</slot> The default value is 50000. A lower value causes an earlier initialization! If several signatures have the same value for the 'global_init_slot' attribute, the order of their initialization remains undefined! Cautious application should therefore be considered! Example: The project contains f.e. two global variable lists GVL_1 and GVL_2. The global variable "A" is part of the global variable list GVL_1: {attribute 'global_init_slot' := '300'} VAR_GLOBAL A : INT:=1000; END_VAR The initialization values of the variables "B" and "C" of GVL_2 are dependent on the variable "A". {attribute 'global_init_slot' := '350'} VAR_GLOBAL B : INT:=A+1; C : INT:=A-1; END_VAR So if you set the 'global_init_slot' attribute of the global variable list GVL_1 to 300, i.e. to the lowest initialization value in the example, then it is ensured that the expression "A+1" is well-defined at the time of initialization of "B".
Last updated: 2024-01-30

Post by timo on String nach erlaubten/unerlaubten Zeichen durchsuchen CODESYS Forge talk (Post)
Hallo, Ich bastele gerade an einer möglichst einfachen Möglichkeit mit der ich prüfen kann ob ein String Sonderzeichen enthält. Mein Ansatz ist ein ST FB mit einer Case Schrittkette. Ich vergleiche jedes Zeichen des Strings mit allen Zeichen eines vorher definierten Strings erlaubter Zeichen, der A-Z, a-z und 0-9 enthält und ggf angepasst werden kann, wenn ich weitere Zeichen erlaube. Leider wird meine j Zählervariable nicht richtig ausgeführt. Hat da jemand eine Idee? Oder gibt es eine einfachere Lösung/einen fertigen FB den ich mir anschauen kann? FUNCTION_BLOCK Sonderzeichen_Check VAR_INPUT inputString : STRING; // Zu prüfender String startCheck : BOOL; // Startsignal END_VAR VAR_OUTPUT ok : BOOL; // TRUE, wenn keine ungültigen Zeichen END_VAR VAR i : INT := 1; // Input-String Zähler j : INT := 1; // erlaubte Zeichen Zähler allowedChars: STRING := 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; // Erlaubte Zeichen currentChar : STRING[1]; // Aktuelles Zeichen step : INT := 0; // Schritt END_VAR CASE step OF 0: // Warten auf Start IF startCheck THEN step := 10; END_IF 10: // Initialisierungen i := 1; j := 1; ok := TRUE; // Standard: ok step := 20; 20: // Durchgehen des Eingangs-Strings IF i <= LEN(inputString) THEN currentChar := MID(inputString, i, 1); // Aktuelles Zeichen step := 30; ELSE step := 70; // Alle Zeichen ok END_IF 30: // Durchgehen der erlaubten Zeichen IF j <= LEN(allowedChars) THEN step := 40; // Zu Schritt 40 ELSE step := 60; // Ungültiges Zeichen END_IF 40: // Vergleich IF currentChar = MID(allowedChars, j, 1) THEN i := i + 1; // Nächstes Zeichen im Input step := 20; ELSE j := j + 1; // Nächstes erlaubtes Zeichen step := 30; END_IF 60: // Ungültiges Zeichen ok := FALSE; // Setze auf FALSE step := 0; 70: // Alle Zeichen ok step := 0; END_CASE
Last updated: 2025-01-20

Post by svn123 on In Simulation Mode, logic is not executing CODESYS Forge talk (Post)
Please check the attached snapshot. I am converting an int to real and storing in rVlv01_SV and then scaling the value using LIN_TRAFO. In the bottom Status Bar of Codesys, both RUN and SIMULATION are visible. When I enter value 100 as input to INT_TO_REAL instruction and press Ctrl-F7, the value can be seen at the input but the logic seems not to work. I searched for help but could not find anything relevant. What could be the reason. Codesys ver3.5.11 svn
Last updated: 2023-12-25

Post by wiresplus on Cannot get INT_TO_TIME working CODESYS Forge talk (Post)
Hello, I have a simple TON timer. It is watching prime loss for a pump. The operator can set the delay via the HMI, it is an integer (seconds) As the TON uses milliseconds, we then multiply the entry by 1000 to get seconds. Seems simple, but... VAR PrimeTimer : TON; primetime : INT; END_VAR PrimeTimer(in:=State>0 AND FlowRate<MinimumFlow,pt:=INT_TO_TIME(primetime *1000)); For an entered 15 seconds (VAR primetime:=15;) the timer reads 49d17h2m26s760ms !!!! What am I doing wrong?
Last updated: 2024-01-26

Post by fless on FB having single input but initialized with Array CODESYS Forge talk (Post)
Why will it retain the sum value from the last call? This is how PLC work. Usually variables only get initialized after a download or a reset (i.e. power loss). RETAIN variables are saved in a special kind of RAM and keep their value after a power loss. To initialize variables on every call of your FB use the VAR TEMP block. VAR_TEMP sum : INT; END_VAR
Last updated: 2024-05-07

Post by corriibme on Setting array values with JSON Utilities SL CODESYS Forge talk (Post)
I have been trying to set an array value to a JSON structure of this form: {"key": [1,2,3,4]} While I have been able to create the key and set its value to an empty array, I've not had any luck in putting any value in that array. objindex:= fb_JBuilder.SetKeyWithArray("Key6", diParentIndex := diRootIndex); objindex2:= fb_JBuilder.SetValue(value:= iValue2, diParentIndex:= objindex); iValue2: ARRAY[0..3] OF INT:= [1,2,3,4]; The two lines of code above produce {"key6": []} . The second line essentially has no effect.
Last updated: 2024-05-12

Post by ndzied2 on Rounding error in simple addition CODESYS Forge talk (Post)
This is a consequence of how computers store floating point numbers. 0.1 cannot be exactly represented in a computer. This is not a CoDeSys thing. Here is a link to a converter to show you the exact value that is represented when you use a REAL data type (which is a 32 bit float). https://baseconvert.com/ieee-754-floating-point If you really need to keep track of 0.1 increments. use INT OR DINT and then add 1 each time and assume that there is one decimal place.
Last updated: 2024-05-24

Post by wiresplus on Display minutes as hours & minutes CODESYS Forge talk (Post)
Hello, I have a counter that increments an INT value once per minute I want to display this value in Minutes until 60, then Hours/Minutes thereafter on the HMI Codesys V3.5 SP16 I can divide the minutes by 60 to get hours, but then the minutes is still more than 60. Example: a process has run for 350 Minutes. I need to display "5 Hours 50 Minutes" But if it's only been 45 Minutes, I don't want "0 Hours 45 Minutes" , just "45 Minutes"
Last updated: 2024-05-25

Post by talhaali on Create an alarm list without use of Alarm config CODESYS Forge talk (Post)
Hi, I am trying to access active alarms in code(As alarm count variable updates only when we go to to alarm table frame in visualization). I wrote following code but it is not working: VAR iCountActiveAlarms : INT; parritfActiveAlarms : POINTER TO ARRAY[0..0] OF IAlarm; itfAlarmManagerClientAll : IAlarmManagerClient; END_VAR AlarmManager.g_AlarmHandler.GetActiveAlarms( itfAlarmManagerClient :=itfAlarmManagerClientAll, iCountActiveAlarms => iCountActiveAlarms, parritfActiveAlarms => parritfActiveAlarms); The Value is always 0. Please help.
Last updated: 2024-06-06

Post by talhaali on Create an alarm list without use of Alarm config CODESYS Forge talk (Post)
Hi, I am trying to access active alarms in code(As alarm count variable updates only when we go to to alarm table frame in visualization). I wrote following code but it is not working: VAR iCountActiveAlarms : INT; parritfActiveAlarms : POINTER TO ARRAY[0..0] OF IAlarm; itfAlarmManagerClientAll : IAlarmManagerClient; END_VAR AlarmManager.g_AlarmHandler.GetActiveAlarms( itfAlarmManagerClient :=itfAlarmManagerClientAll, iCountActiveAlarms => iCountActiveAlarms, parritfActiveAlarms => parritfActiveAlarms); The Value is always 0. Please help.
Last updated: 2024-06-06

Post by liamb on Converting CANbus to Decimal from signed 2's complement CODESYS Forge talk (Post)
I need to combine two 8 bit CANbus messages to 16 bits signed int then convert to decimal Decimal from signed 2's complement. I've been using the below code to read for new messages, combine them then assign them to a variable What is the best way to do this for from signed 2's complement? fbRxMessage351(Data := RxMessage351Data); IF fbRxMessage351.NewMessage THEN ChargeVoltage := (WORD_TO_REAL((RxMessage351Data[0]) + ((RxMessage351Data[1]) * 256))) * 0.1; END_IF
Last updated: 2024-08-16

Post by timo on Visualisierung: Tastatur vergrößern? CODESYS Forge talk (Post)
Hallo, Ich nutze den Stil White Style 3.5.16 mit ein paar farblichen Änderungen über den Stileditor. Was ich gerne machen würde, wäre die Tastaturen zu vergrößern, die sich auf dem Touchpanel öffnen wenn ein INT oder STRING eingegeben werden muss. Gibt es dafür "fertige" Variablen im Editor des Stils oder in Codesys selbst, mit dem die Größe hochskaliert werden kann? Oder muss ich jede Taste einzeln anpacken? Danke im Voraus :)
Last updated: 2025-02-21

Post by vipul on Multicast udp CODESYS Forge talk (Post)
Hi, Good afternoon can anybody help me with UDP Multicast code. I am not able to send or recieve data when code is dumped on linux device. Below is my code. Declaration: PROGRAM udp_multicast VAR oneTimeFlag :UINT :=0; state: INT:=0; driver: UDP.UDPDriver; //port : UDP.Port;//moved to GVL src_ipAddr_ud: UDINT; src_ipAddr_st:STRING := '192.168.127.155';//'192.168.1.155';//ipms ip address dst_ipAddr_ud:UDINT; group_ipAddr_st:STRING := '239.1.5.10'; //group_ipAddr_ud:UDINT; result: SysTypes.RTS_IEC_RESULT; //result of recieve function. bind: UDINT; //result of binding. resultCreate:SysTypes.RTS_IEC_RESULT;//result of port creation. timer:BLINK; temFlag :INT:= 0; post:INT :=0; checksumFunc:checksumXor; localStringBuf:STRING[500]; chksum:BYTE; dataBuffer:POINTER TO BYTE; checksumString:ARRAY[0..5] OF BYTE; recvSize:__XINT; errorCode:UDINT; joinGroupErrorCode:UDINT; END_VAR ************8 Implementation: IF oneTimeFlag <> 1 THEN oneTimeFlag:=1; resultCreate := driver.CreatePort(ADR(GVL.port)); src_ipAddr_ud := UDP.IPSTRING_TO_UDINT(sIPAddress:= src_ipAddr_st); GVL.group_ipAddr_ud := UDP.IPSTRING_TO_UDINT(sIpAddress:= group_ipAddr_st); GVL.port.IPAddress := src_ipAddr_ud; GVl.port.ReceivePort:= GVL.src_port;//port on which messages are expected. GVl.port.SendPort := GVL.dest_port; GVl.port.OperatingSystem := 0; //0- any system GVL.port.Socket :=3; //3- socket type is multicast bind := GVL.port.Bind(udiIPAddress:=src_ipAddr_ud,); GVl.port.JoinGroup(udiGroupAddress:= GVL.group_ipAddr_ud,udiInterfaceAddress:= src_ipAddr_ud,eLogCode=>joinGroupErrorCode); END_IF timer(ENABLE:=TRUE,TIMELOW:=T#100MS,TIMEHIGH:=T#100MS); IF timer.OUT = TRUE THEN GVL.port.Send(udiIPTo:=GVL.group_ipAddr_ud,GVL.dest_port,pbyData:=ADR(GVL.writeData),diDataSize:=SIZEOF(GVL.writeData)); ELSE SysMemSet(ADR(GVL.readData[0]),0,SIZEOF(GVL.readData)); result := GVl.port.Receive(ADR(GVL.readData),diDataSize:=SIZEOF(GVL.readData),udiIPFrom=>dst_ipAddr_ud,diRecvSize=>recvSize,eLogCode=>errorCode); SysMemMove(ADR(GVL.readDataBuf[0]),ADR(GVL.readData[0]),SIZEOF(GVL.readData)); END_IF post:=LEN(GVL.readDataBuf);
Last updated: 2024-01-14

Post by ruobian on Analog Input Delay Timer CODESYS Forge talk (Post)
Hello there, I am new here and in programming. I need help with the basics. I am trying to do what I mentioned in the title. I have an analog input. So I have a real or integer data type value. I want to delay it. TON and TOF only work with bool. I think there is a function block that has two inputs, 1 for real or int and 1 for bool. And if bool is true, it will give the output as real or int. I don't know but I need something like this. Actually, it is not exactly like that. In other words, it will not show the real value at the input at the output after a certain period of time. I want it to show the real value from 2 seconds ago continuously. The purpose of doing this is to compare the real value I received with the value from 2 seconds ago and find out whether it went up or down. I am using only FBD. Please help me with this. Thanks in advance.
Last updated: 2024-08-20

Post by ewi04 on Recipe Manager - RecipeManCommands, load & write wrong values, Bug? CODESYS Forge talk (Post)
I'm getting closer to the error. The combination of STRUCT and ARRAY probably causes the strange behavior. As soon as the ARRAY is followed by a variable, the problem arises. Examples: X: ARRAY[1..2] OF INT; // okay Y: ARRAY[1..2] OF STRUCT; // problem Z: STRUCT; Z.ArrayOfInt[1]; // okay Z.ArrayOfStruct[1].Variable // problem // *update - array of array also causes the error A: ARRAY[1..2] OF ARRAY[1..4] OF BOOL; // problem I can't be the only one who has this problem. Or? Maybe there is a solution. Anyone? Or is it a bug after all?
Last updated: 2023-11-17

Post by alexgooi on Modbus writing on value change CODESYS Forge talk (Post)
The way I usally tackle this is by syncing only words (then you are able to use the FB above). If you then want to write a Boolean simply type it like this. Value[1].0 := Bool1; Value[1].1 := Bool2; Value[1].2 := Bool3; Uints have the same number of bits than a INT/WORD so these ones will work as well (they are only represented diffrently). A Real will work but you will loose some infomration in the conversion. If you want to keep the information you can convert 2 words to a float with a function (for example with the IEEE-754 standard) . In this way the syncing to the server is very simple and in the Codesys Program you decide what part of the word you want to use.
Last updated: 2024-04-03

Post by bjarne-pagaard on Codesys v3.5 Sint to byte CODESYS Forge talk (Post)
Hi A SINT is a short (signed) integer. It is already only 1 byte - so you should have no problem casting it to a byte like so: bMyByte := TO_BYTE(sintMyShortInt); If you have a regular INT you want to put in 2 bytes - there are a lot of ways you can do this. A Union is certainly one of them. You could have a union with 2 memebers: An array of 2 bytes as one member, and an integer value as another member. Another way would be to look at MEMCPY to put the value into your CAN-message. .. or create a function to take your input value as input, and giving you 2 individual bytes as output. This could be handy if you need to change the byte-order. Integer data types: https://help.codesys.com/webapp/_cds_datatype_integer;product=codesys;version=3.5.17.0 -Bjarne
Last updated: 2024-04-24

Post by alimans on OPC-UA Server, Symbol Set: Raise an error: Object reference not set to an instance of an object. CODESYS Forge talk (Post)
Hi everyone, I just created a very simple library without any code and, added it to my very simple project. after adding this library, I get an error when I try to open "Symbol Set" in "OPC UA Server" in "Communication Manager". Here is the code of my POU in the library: FUNCTION_BLOCK POU VAR eCommand : (CMD_NONE:=0, CMD_RESET:=-1) INT := CMD_NONE; END_VAR Attached is the error that I get. I also noticed that by removing the enumeration variable above (eCommand), I can open the "Symbol Set" again. Anybody has any idea why this error is raised and how could I use enumeration variables without error in "OPC UA Symbol Set"?
Last updated: 2024-08-08

Post by elsmart on Sequential read and triggering of Modbs RTU channels in application CODESYS Forge talk (Post)
Hello I need some help understanding how to use Modbus RTU (COM port) in Codesys enviroment. I defined a Modbus Server device (slave) in device tree and added some channels to read from (function 3). Also I set trigering mode to Application. I have a POU in which I want to trigger each channel one after the other something like this (C code for better visualisation): for (int i = 0; i < channelsCount; i++) { triggerChannel(channelsArray[i]); // Start transmission while(channel.xBusy); // Wait for transmission to complete } I have found ModbusChannel function block documentation but examples are scarce. I don't understand how rising edge triggering works. What would be the best solution for achieving sequntial channel triggering? What is the common way to read multiple Modbus channels once every time a specified POU is executed?
Last updated: 2025-05-16

<< < 1 2 3 4 5 > >> (Page 4 of 5)

Showing results of 116

Sort by relevance or date