Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Conversion Functions
Conversion_Functions.project
Example Guide
04/2012
Basic
Intermediate
EIO0000000900.01
Expert
www.schneider-electric.com
EIO0000000900.01 04/2012
Table of Contents
SAFETY INFORMATION 5
ABOUT THE BOOK 7
1. DESCRIPTION13
1.1.
Presentation 13
1.2.
1.3.
Hardware Installation 16
CFC Program 23
5.2.
LD Program 26
5.3.
ST Program 35
6.2.
6.3.
EIO0000000900.01 04/2012
EIO0000000900.01 04/2012
Safety Information
Safety Information
Important Information
NOTICE
Read these instructions carefully, and look at the equipment to become familiar with the
device before trying to install, operate, or maintain it. The following special messages
may appear throughout this documentation or on the equipment to warn of potential
hazards or to call attention to information that clarifies or simplifies a procedure.
The addition of this symbol to a Danger or Warning safety label
indicates that an electrical hazard exists, which will result in personal
injury if the instructions are not followed.
This is the safety alert symbol. It is used to alert you to potential
personal injury hazards. Obey all safety messages that follow this
symbol to avoid possible injury or death.
DANGER
DANGER indicates an imminently hazardous situation which, if not avoided,
will result in death or serious injury.
WARNING
WARNING indicates a potentially hazardous situation which, if not avoided, can
result in death or serious injury.
CAUTION
CAUTION indicates a potentially hazardous situation which, if not avoided, can
result in minor or moderate injury.
NOTICE
NOTICE is used to address practices not related to physical injury.
PLEASE NOTE
Electrical equipment should be installed, operated, serviced, and maintained only by
qualified personnel. No responsibility is assumed by Schneider Electric for any
consequences arising out of the use of this material.
A qualified person is one who has skills and knowledge related to the construction
and operation of electrical equipment and the installation, and has received safety
training to recognize and avoid the hazards involved.
EIO0000000900.01 04/2012
EIO0000000900.01 04/2012
At a Glance
Document Scope
This document describes one of the SoMachine examples.
Since the example described in this document is intended for learning purposes
only, it must not be run, nor tested, on products that are part of a machine or
process.
Validity Note
This document has been updated with the release of SoMachine V3.1.
The technical characteristics of the device(s) described in this manual also appear
online. To access this information online:
Step
Action
Go to www.schneider-electric.com
In the Search box on the home page, type a model number. Do not type any blank
spaces in the model number. To get information on a grouping of similar modules, you
can use the characters **; do not use dots or xx's.
Under All, click Products Product Datasheets and select the model number that
interests you.
Related Documents
Title of Documentation
Reference Number
EIO0000000016 (ENG);
EIO0000000017 (FRE);
EIO0000000018 (GER);
EIO0000000019 (SPA);
EIO0000000020 (ITA);
EIO0000000021 (CHS)
EIO0000000096 (ENG)
EIO0000000900.01 04/2012
Reference Number
EIO0000000374 (ENG);
EIO0000000737 (FRE);
EIO0000000738 (GER);
EIO0000000739 (SPA);
EIO0000000740 (ITA);
EIO0000000741 (CHS)
EIO0000000384 (ENG);
EIO0000000385 (FRE);
EIO0000000386 (GER);
EIO0000000387 (ITA);
EIO0000000388 (SPA);
EIO0000000389 (CHS)
EIO0000000364 (ENG);
EIO0000000757 (FRE);
EIO0000000758 (GER);
EIO0000000759 (SPA);
EIO0000000760 (ITA);
EIO0000000761 (CHS)
EIO0000000898 (ENG)
EIO0000000903 (ENG)
EIO0000000911 (ENG)
WARNING
UNINTENDED EQUIPMENT OPERATION
Only use software approved by Schneider Electric for use with this equipment.
Update your application program every time you change the physical hardware
configuration.
EIO0000000900.01 04/2012
WARNING
LOSS OF CONTROL
The designer of any control scheme must consider the potential failure modes
of control paths and, for certain critical control functions, provide a means to
achieve a safe state during and after a path failure. Examples of critical control
functions are emergency stop and overtravel stop, power outage and restart.
Separate or redundant control paths must be provided for critical control
functions.
System control paths may include communication links. Consideration must be
given to the implications of unanticipated transmission delays or failures of the
link.
Observe all accident prevention regulations and local safety guidelines.1
Each implementation of this equipment must be individually and thoroughly
tested for proper operation before being placed into service.
For additional information, refer to NEMA ICS 1.1 (latest edition), "Safety
Guidelines for the Application, Installation, and Maintenance of Solid State Control"
and to NEMA ICS 7.1 (latest edition), "Safety Standards for Construction and Guide
for Selection, Installation and Operation of Adjustable-Speed Drive Systems" or
their equivalent governing your particular location.
WARNING
REGULATORY INCOMPATIBILITY
Be sure that all equipment applied and systems designed comply with all
applicable local, regional and national regulations and standards.
Failure to follow these instructions can result in death, serious injury, or
equipment damage.
The use and application of the information contained herein require expertise in the
design and programming of automated control systems. Only the user or integrator
can be aware of all the conditions and factors present during installation and setup,
operation, and maintenance of the machine or process, and can therefore
determine the automation and associated equipment and the related safeties and
EIO0000000900.01 04/2012
you do not follow the required standards applicable to the operation of the
machine, or if the adjustments to and the maintenance of the machine are
not properly made (it is essential to strictly follow the prescribed machine
maintenance schedule).
CAUTION
EQUIPMENT INCOMPATIBILITY
Read and thoroughly understand all device and software documentation before
attempting any component substitutions or other changes related to the
application examples provided in this document.
Failure to follow these instructions can result in injury or equipment
damage.
10
EIO0000000900.01 04/2012
CAUTION
EQUIPMENT OPERATION HAZARD
Verify that all installation and set up procedures have been completed.
Before operational tests are performed, remove all blocks or other temporary
holding means used for shipment from all component devices.
Verify that the completed system, including the functional safety system, is free from
all short-circuits and grounds, except those grounds installed according to local
regulations. If high-potential voltage testing is necessary, follow the
recommendations in equipment documentation to help prevent injury or equipment
damage.
WARNING
UNGUARDED MACHINERY CAN CAUSE SERIOUS INJURY
EIO0000000900.01 04/2012
11
User Comments
We welcome your comments about this document. You can reach us by e-mail at
techcomm@schneider-electric.com.
12
EIO0000000900.01 04/2012
1. Description
1.
Description
1.1. Presentation
This example presents the Conversion Functions of the Toolbox library. In this
example, these functions are used on a M238 logic controller.
The controllers program is created using SoMachine software.
Related SoMachine project: Conversion_Functions.project
CFC
ST
LD
IL
FBD
SFC
Download
& Monitoring
PC with SoMachine
EIO0000000900.00 04/2012
13
1. Description
Function
Description
DWORD_AS_WORD
WORD_AS_DWORD
Celsius_TO_Kelvin
Kelvin_TO_Celsius
ArrayOfByte_TO_String
String_TO_ArrayOfByte
Celsius_TO_Fahrenheit
Fahrenheit_TO_Celsius
Frequency_TO_Period
Period_TO_Frequency
NOTE: The other functions of the Toolbox library are used in the examples
described in the SoMachine Boolean Functions Example Guide and in the
SoMachine Analog Signal Functions Example Guide.
14
EIO0000000900.01 04/2012
1. Description
Please refer to the SoMachine online help.
NOTE: In the remaining sections of this document, the former sentence instructs
you to refer to the online help of SoMachine which is accessible through the upperhelp button.
right
Please refer to the SoMachine online help for detailed information on these
Functions and Function Blocks: Function description, Graphical representation, I/O
Variables description, and more.
To install these libraries in your own project, please refer to Library Manager (see
page 20).
EIO0000000900.00 04/2012
15
1. Description
1
3
USB
Controller
2a
or
2b
Prg.
Port
Designation
Reference
Use or Description
SoMachine Software
MSD CHNLMUA
2a
Terminal port/USB
port cordset
From the mini B USB port on the Modicon M238 base to the
type A USB port on the PC terminal for programming and
updating firmware; length: 3 m (10 ft)
2b
Programming cable
M238 controller
TM238
Please refer to the Modicon M238 Logic Controller Hardware Guide for the
hardware setup of this device.
16
EIO0000000900.01 04/2012
2.
EIO0000000900.00 04/2012
17
3.
Step
1
Action
In the Create new machine part of the Home tab, select Start with empty project to
create a new SoMachine project.
Give this new project the following name: Conversion_Functions.
NOTE: Details on the selected controller are displayed in the Information section of
SoMachine.
SoMachine controller version: Defines the version of the selected controller; it is
displayed in the Information section of SoMachine.
Target controller firmware version: Defines the firmware version of your controller. This
version is shown when you select your controllers node, as shown in Downloading the
Example to the Controller (see page 40).
For compatibility purposes between a SoMachine controller version and a target
controller firmware version, only the first three numbers of a version must be identical. In
the preceding dialog display, the 2.0.30.13 SoMachine controller version is compatible
with any 2.0.30. target controller firmware version.
For each controller model, SoMachine only presents the latest available version. If you
check the Display all versions (for expert only) option, SoMachine will list the
supported controller firmware versions. However, a good practice consists in using the
latest available version and updating the firmware of your controller, if required. Please
refer to the M238 ExecLoader User Guide.
18
EIO0000000900.01 04/2012
Action
EIO0000000900.00 04/2012
19
4. Library Manager
4.
Library Manager
The steps listed in the following table describe how to add and/or check the list of
the libraries linked to this example.
Step
1
Action
Select the Program tab.
In the Devices tree view, double-click on the Library Manager to open the list of the
libraries linked to the Application software of this example.
20
EIO0000000900.01 04/2012
4. Library Manager
Step
Action
This adds the Toolbox library to the list of libraries linked to the project.
NOTE: In the Library Manager, this library is represented in black to inform that it has
been manually linked to the program and that it can be removed.
EIO0000000900.00 04/2012
21
5.
22
EIO0000000900.01 04/2012
Action
Creation of the POU: Create a new POU in CFC language, called
Conversion_Functions_CFC.
CFC variables: In the upper part of the CFC editor, declare the following variables:
PROGRAM Conversion_Functions_CFC
VAR
(* Temperature Conversions *)
(* Celsius to Fahrenheit Conversion *)
i_rCelsiusValue
: REAL
q_rFahrenheitValue
: REAL;
(* Celsius to Kelvin Conversion
q_rKelvinValue
q_xErrorConvCelsiusToKelvin
CelsiusToKelvinConversion
*)
: REAL;
: BOOL;
: Celsius_TO_Kelvin;
*)
: REAL
: REAL;
: BOOL;
: Kelvin_TO_Celsius;
:= 25.0;
:= 298.15;
:= 77.0;
:= T#20MS;
:= 50.0;
EIO0000000900.00 04/2012
23
Action
i_sString
i_xInStringOrder
q_ArrayOfByte
(* Array of Byte to String *)
i_ArrayOfByte
[72,101,108,108,111];
i_xInArrayOfByteOrder
i_xInsertSpace
q_sString
: STRING (255)
:= 'Hello';
: BOOL
:= TRUE;
: ARRAY [1..255] OF BYTE;
:= TRUE;
:= TRUE;
:
:
:
:
DWORD
WORD;
WORD;
DWORD_AS_WORD;
:= 1310865;
(* Word as Dword *)
i_wLowWord
i_wHighWord
q_dwDword
Shifting_Words
:
:
:
:
WORD
WORD
DWORD;
WORD_AS_DWORD;
:= 145;
:= 20;
END_VAR
24
CFC program: In the lower part of the CFC editor, implement the following program:
EIO0000000900.01 04/2012
Action
EIO0000000900.00 04/2012
25
5.2. LD Program
The following table presents optional steps that give you information on how to
program in LD language.
Step
1
Action
Optional step
How to display titles and comments in LD language
Select the Options command of the Tools menu.
Select, in the Options window, the FBD, LD and IL editor section.
If you wish to add a title and/or a comment for each LD network, check the
Show network title and/or the Show network comment options, as shown
below:
26
EIO0000000900.01 04/2012
Action
Optional step
How to add the EN/ENO pins on a Function Block
You must perform this step if you wish to append the additional Boolean enable input EN
and Boolean output ENO (Enable Out) to the function blocks of your own programs.
Please refer to the SoMachine online help: search for additional Boolean ENO.
NOTE: The EN/ENO pins are not used in this example.
In the View part of the FBD/LD/IL menu, select the View as function block
diagram mode.
EIO0000000900.00 04/2012
27
Action
Select, in your LD program, the LD network where you want to add a Function
Block (or a Function).
In the FBD/LD/IL menu, execute the Insert Box with EN/ENO command.
28
EIO0000000900.01 04/2012
Action
In the Input Assistant window that is displayed, select the Function blocks
category, if you wish to add a Function Block, or the Module Calls category, if
you wish to add a Function.
Select the Function Block (or the Function) you wish to add in your program.
In the following dialog, the Celsius_TO_Kelvin Function Block of the Toolbox
library is selected. The location of this Function Block is given in Functions Used
in this Example (see page 14):
Click OK.
This adds the selected Function Block (or Function) to your program, with the two
EN and ENO pins.
In the View part of the FBD/LD/IL menu, you can now select the View as ladder
logic mode to return to the default view mode.
EIO0000000900.00 04/2012
29
Action
Optional step
How to use the Insert Empty Box Command
Sometimes, the Empty Box created by the Insert Empty Box command does not work
with a Function or Function Block.
This is the case with this example: The Empty Box is not compatible with the Toolbox
librarys Conversion Functions.
Therefore, you must use the Insert Box command instead of the Insert Empty Box
command for any of the Conversion Functions of the Toolbox library.
If, in your own programs, the Empty Box is incompatible with a Function or Function
Block instance, then you must also use the Insert Box command instead of the Insert
Empty Box command.
Example: In the following image, the Celsius_TO_Kelvin Function Block is rejected by
an Empty Box; in this case, the Insert Box command must be used:
Select in your LD program the LD network where you want to add a Function
Block (or a Function).
In the FBD/LD/IL menu, execute the Insert Box command.
30
EIO0000000900.01 04/2012
Action
In the Input Assistant window that is displayed, select the Function blocks
category if you wish to add a Function Block or the Module Calls category if you
wish to add a Function.
Select the Function Block (or the Function) you wish to add in your program.
In the following dialog the Celsius_TO_Kelvin Function Block of the Toolbox
library is selected:
NOTE: The location of the Conversion Functions of the Toolbox library are given
in Functions Used in this Example (see page 14).
Click OK.
This adds the selected Function Block (or Function) to your program.
EIO0000000900.00 04/2012
31
Action
Creation of the POU: Create a new POU in LD language, called
Conversion_Functions_LD.
LD variables: In the upper part of the LD editor, declare the following variables:
PROGRAM Conversion_Functions_LD
VAR
(* Temperature Conversions *)
(* Celsius to Fahrenheit Conversion *)
i_rCelsiusValue
: REAL
q_rFahrenheitValue
: REAL;
(* Celsius to Kelvin Conversion
q_rKelvinValue
q_xErrorConvCelsiusToKelvin
CelsiusToKelvinConversion
*)
: REAL;
: BOOL;
: Celsius_TO_Kelvin;
*)
: REAL
: REAL;
: BOOL;
: Kelvin_TO_Celsius;
:= 25.0;
:= 298.15;
:= 77.0;
:= T#20MS;
:= 50.0;
32
EIO0000000900.01 04/2012
Action
i_ArrayOfByte
[72,101,108,108,111];
i_xInArrayOfByteOrder
i_xInsertSpace
q_sString
:= TRUE;
:= TRUE;
:
:
:
:
DWORD
WORD;
WORD;
DWORD_AS_WORD;
:= 1310865;
(* Word as Dword *)
i_wLowWord
i_wHighWord
q_dwDword
Shifting_Words
:
:
:
:
WORD
WORD
DWORD;
WORD_AS_DWORD;
:= 145;
:= 20;
END_VAR
EIO0000000900.00 04/2012
33
34
Action
LD program: In the lower part of the LD editor, implement the following program:
EIO0000000900.01 04/2012
5.3. ST Program
Step
1
Action
Creation of the POU: Create a new POU in ST language, called
Conversion_Functions_ST.
ST variables: In the upper part of the ST editor, declare the following variables:
PROGRAM Conversion_Functions_ST
VAR
(* Temperature Conversions *)
(* Celsius to Fahrenheit Conversion *)
i_rCelsiusValue
: REAL
q_rFahrenheitValue
: REAL;
(* Celsius to Kelvin Conversion
q_rKelvinValue
q_xErrorConvCelsiusToKelvin
CelsiusToKelvinConversion
*)
: REAL;
: BOOL;
: Celsius_TO_Kelvin;
*)
: REAL
: REAL;
: BOOL;
: Kelvin_TO_Celsius;
:= 25.0;
:= 298.15;
:= 77.0;
:= T#20MS;
:= 50.0;
EIO0000000900.00 04/2012
35
Action
i_sString
i_xInStringOrder
q_ArrayOfByte
: STRING (255)
:= 'Hello';
: BOOL
:= TRUE;
: ARRAY [1..255] OF BYTE;
:= TRUE;
:= TRUE;
:
:
:
:
DWORD
WORD;
WORD;
DWORD_AS_WORD;
:= 1310865;
(* Word as Dword *)
i_wLowWord
i_wHighWord
q_dwDword
Shifting_Words
:
:
:
:
WORD
WORD
DWORD;
WORD_AS_DWORD;
:= 145;
:= 20;
END_VAR
ST program: In the lower part of the ST editor, implement the following program:
(* Temperature Conversions *)
(* Celsius to Fahrenheit Conversion *)
q_rFahrenheitValue := Celsius_TO_Fahrenheit(i_rIput := i_rCelsiusValue);
(* Celsius to Kelvin Conversion *)
CelsiusToKelvinConversion.i_rIput
CelsiusToKelvinConversion();
q_rKelvinValue
q_xErrorConvCelsiusToKelvin
(* Kelvin to Celsius Conversion *)
KelvinToCelsiusConversion.i_rIput
KelvinToCelsiusConversion();
q_rKelvinToCelsiusValue
q_xErrorConvKelvinToCelsius
:= i_rCelsiusValue;
:= CelsiusToKelvinConversion.q_rOput;
:= CelsiusToKelvinConversion.q_xErr;
:= i_rKelvinValue;
:= KelvinToCelsiusConversion.q_rOput;
:= KelvinToCelsiusConversion.q_xErr;
(* Fahrenheit to Celsius *)
q_rFahrenheitToCelsiusValue := Fahrenheit_TO_Celsius(i_rIput :=
i_rFahrenheitValue);
(* Period & Frequency Conversions *)
(* Period to Frequency Conversion *)
q_rFrequencyHz := Period_TO_Frequency(i_tIput := i_tPeriodMs);
(* Frequency to Period Conversion *)
q_tPeriodMs := Frequency_TO_Period(i_rIput := i_rFrequencyHz);
(* String & Array of byte Conversions *)
(* String to Array of Byte Conversion *)
q_ArrayOfByte := String_TO_ArrayOfByte(i_sIput := i_sString,
i_xOrdr := i_xInStringOrder);
(* Array of Byte to String conversion *)
q_sString := ArrayOfByte_TO_String(i_abyIput := i_ArrayOfByte,
i_xOrdr
:= i_xInArrayOfByteOrder,
i_xSpce
:= i_xInsertSpace);
(* Dword & Word *)
(* Dword as Word *)
Splitting_Dword.i_dwIput := i_dwDword;
Splitting_Dword();
q_wLowWord
:= Splitting_Dword.q_wLow;
q_wHighWord
:= Splitting_Dword.q_wHigh;
(* Word as Dword *)
Shifting_Words.i_wLow
Shifting_Words.i_wHigh
Shifting_Words();
q_dwDword
36
:= i_wLowWord;
:= i_wHighWord;
:= Shifting_Words.q_dwOput;
EIO0000000900.01 04/2012
6.
Action
In the Devices tree view:
Expand the contents of the M238_Controller (TM238LFDC24DT) item.
Double-click on the MAST task of the Task Configuration item:
Click on the Add POU command.
EIO0000000900.00 04/2012
37
Action
In the Input Assistant window that is displayed:
Select your program.
In the following dialog, the CFC program described in CFC Program (see page 23),
Conversion_Functions_CFC, is selected:
Click OK.
This adds the selected POU to the list of programs run by the MAST task of the
controller.
38
EIO0000000900.01 04/2012
Action
Connect the USB programming cable between your PC and the M238 controller.
Please refer to Hardware Installation (see page 16), for the reference and usage of this
cable.
EIO0000000900.00 04/2012
39
Action
Select this controllers node and click on the Set active path button.
The following window will display and prompts you to confirm your choice:
Read the hazard message;
Simultaneously press the <Alt> and <F> keys to validate your choice and close
this window;
Or, click on the Cancel button if you can not comply with the statements in the
hazard message.
40
EIO0000000900.01 04/2012
Action
Login button of the toolbar to establish a connection from SoMachine to
Click on the
the controller.
7a
If you download the current project to the controller for the first time and if there is no
project on the controller, the following window is displayed:
If you download the current project to the controller for the first time and if there is
another project on the controller, the following window is displayed:
If you already have downloaded the current project to the controller, the following window
displays if new modifications were made to this project:
If you already have downloaded the current project to the controller, the connection is
immediate if no modifications were made to this project.
Click on the
controller.
EIO0000000900.00 04/2012
STOP
to
RUN
41
Action
In the Devices panel, double-click on your Conversion_Functions program to open it
(e.g. Conversion_Functions_CFC if you previously selected this program as the
program run by the MAST task of your controller).
This command opens the program in the central panel of SoMachine; the online values of
the variables used by this program are also displayed, as shown below:
Temperature conversions:
Celsius to Fahrenheit conversion using the Celsius_TO_Fahrenheit Function:
To test this conversion Function, proceed as follows:
Change the value of the i_rCelsiusValue variable (expressed in Celsius
degrees); the corresponding Fahrenheit temperature is stored in
q_rFahrenheitValue (expressed in Fahrenheit degrees).
Celsius to Kelvin conversion using the Celsius_TO_Kelvin Function Block:
Name of the Celsius_TO_Kelvin function block instance:
CelsiusToKelvinConversion
To test the CelsiusToKelvinConversion instance, proceed as follows:
Change the value of the i_rCelsiusValue variable (expressed in Celsius
degrees); the corresponding Kelvin temperature is stored in q_rKelvinValue
(expressed in Kelvin degrees).
Please note that an error is generated by this instance if the
i_rCelsiusValue variables value goes beyond the absolute zero
Temperature (273.15C). In this case, the q_xErrorConvCelsiusToKelvin
variable is set to TRUE and the q_rKelvinValue variable is reset to 0.
42
EIO0000000900.01 04/2012
Action
Kelvin to Celsius conversion using the Kelvin_TO_Celsius Function Block:
Name of the Kelvin_TO_Celsius function block instance:
KelvinToCelsiusConversion
To test the KelvinToCelsiusConversion instance, proceed as follows:
Change the value of the i_rKelvinValue variable (expressed in Kelvin
degrees); the corresponding Celsius temperature is stored in
q_rKelvinToCelsiusValue (expressed in Celsius degrees).
Please note that an error is raised by this instance if the i_rKelvinValue
variables value goes beyond the absolute zero Temperature (0K). In this case,
the q_xErrorConvKelvinToCelsius variable is set to TRUE and the
q_rKelvinToCelsiusValue variable is set to the absolute zero Temperature
(0K).
Fahrenheit to Celsius conversion using the Fahrenheit_TO_Celsius Function:
To test this conversion Function, proceed as follows:
Change the value of the i_rFahrenheitValue variable (expressed in
Fahrenheit degrees); the corresponding Celsius temperature is stored in
q_rFahrenheitToCelsiusValue (expressed in Celsius degrees).
Period/frequency conversions:
Period to frequency conversion using the Period_TO_Frequency Function:
To test this conversion Function, proceed as follows:
Change the value of the i_tPeriodMs variable (in TIME format); the
corresponding frequency is stored in q_rFrequencyHz (expressed in Hertz).
Please note that the minimum period is 1 ms (T#1ms in TIME format), for a
maximum frequency of 1,000 Hz.
Frequency to period conversion using the Frequency_TO_Period Function:
To test this conversion Function, proceed as follows:
Change the value of the i_rFrequencyHz variable (in Hertz); the
corresponding period is stored in q_tPeriodMs (in TIME format).
Please note that the maximum frequency is 1,000 Hz, for a minimum period of
1 ms (T#1ms in TIME format).
EIO0000000900.00 04/2012
43
Action
1) The following example converts the 'ABCDEFG' string into a non-swapped
array of bytes (i_xInStringOrder = TRUE):
i_sString
ASCII codes
q_ArrayOfByte
' A B C D E F G'
65 66 67 68 69 70 71 0
1 2 3 4 5 6 7 8
0
9
2) The following example converts the 'ABCDEFG' string into a swapped array
of bytes (i_xInStringOrder = FALSE):
i_sString
'A
G'
ASCII codes
q_ArrayOfByte
66 65 68 67 70 69 00 71
1 2 3 4 5 6 7 8
0
9
1 2 3 4 5 6
72 101 108 108 111 0
'H e
l
l
o'
44
EIO0000000900.01 04/2012
Action
2) The following example converts a swapped array of bytes
(i_xInArrayOfByteOrder = FALSE) into the corresponding 'Hello'
string (even number of bytes):
i_ArrayOfByte
ASCII codes
1 2 3 4 5 6
101 72 108 108 0 111
q_sString
'H
o'
1 2 3 4 5 6
101 72 108 108 111 0
q_sString
'H
o'
1 2 3 4 5 6
101 72 108 108 111 0
q_sString
'H
o'
NOTE: These conversion functions can be useful for ASCII communications. An example
is given in the SoMachine ASCII Communications - Send/Receive Text Example Guide:
The example described in this guide uses the String_TO_ArrayOfByte function to
convert a text into an array of bytes; then, this array of bytes is sent on the controllers
serial line using the SEND_RECV_MSG Function Block of the PLCCommunication library.
EIO0000000900.00 04/2012
45
Action
Dword/Word conversions:
NOTE: To correctly test these conversions, you must set the Display Mode of
SoMachine from Decimal to Hexadecimal, as shown below:
In the Display Mode part of the Debug/Watch menu, select the Hexadecimal
mode.
46
EIO0000000900.01 04/2012