You are on page 1of 9

Open WinlogLite Project manager Lite and create new project.

-Select Configuration folder from your project tree and open Channels view.

-Create channel number 1 and select configuration ModBus RTU.

After this Options window opens. Change your ModBus parameters there.

When parameters are set, channel configuration is done.

- Next open Devices view. Add new device eg. Arduino UNO. Set channel to number 1 and device to
number 1. Device number must be same what you have Slave ID. in your Arduino sketch!

Click OK and device configuration is done.


- Next open Gates folder from project tree. Now, because Arduino sketch supports ModBus
functions 3, 6 and 10 and Winlog supports only function 3 of those, you must use numeric gate for
all data.
- Open Numeric gates view and add new gate:

Give Gate ID eg. Temp_Sensor_1 and so on, N ID eg. 1 (You can use any number as long as it is
individual in each gate), Description eg. Temperature Sensor 1. This is done, choose sampling tab.

In this tab you select what channel do you use and what device do you use. In first step you
choosed the channel number, in this case channel number 1. So when you put number 1 to channel
field it should regonize that it uses ModBus RTU protocol and this text appears after channel.
Fill address field. Addressing goes like this:
When you open Arduino ModBus sketch you can find these lines there:
/* slave registers */
enum {
MB_TE0101, /* analogIn 1 */
MB_TE0102, /* analogIn 2 */
MB_XE0111, /* analogIn 3 */
MB_A4, /* analogIn 4 */
MB_TE0103, /* analogIn 5 */
MB_TS010,
MB_SP010,
MB_TI010,
MB_STR,
MB_REGS=100 /* dummy register. using 0 offset to keep size of array */
};
So when you want to read Arduinos analog input (A1) from WinLog you use address 3:0, if you
want to read Arduinos analog input (A2) from WinLog you use address 3:1 and so on.
In sample field choose always if you want to read values from sensor in certain frequency. Sample
freq. indicates hof often you want to read that sensor value.

Next choose value tab.

Here you can set limits to your measurement. If min. value and Max. value are set to zero, no limits
in measurement are used. Start value means if you want to set some initializing value at startup.
In measure field you can set units to your measurements eg. C.
Variable type depends what kind of values you are reading. If you read analog values without
scaling those in Arduino sketch you can use U_WORD at any time. It can read values from 0 to
65535 so Arduinos 0-1023 suits fine for that.

To decimal digits field you can put the number of decimals that have to be rounded while
converting from the measured value into the engineering value.

This is done, choose Conversion tab.


Here you can use conversion (scaling) to your measurement. Measured vals. are readings what
Arduino sends to Winlog. In this case I use LM35Z temperature sensors and those have linear
voltage output from zero to 1 VDC which equals temperature from zero to 100 C.
So when measured value is zero, of course I want that temperature in Winlog is also zero. But when
temperature is 100 C it equals Arduino analog read values with these sensors (1023*1,0VDC) / 5 =
204,6. So I put Measured val. 2 to 200 (204.6) and engineering val. 2 to 100 and now I have scaled
this measurement.

Now you have done your first numeric gate. This is just the basic configuration for reading analog
values from Arduino. So you can tune these settings as you like but here is shown how basics for
the addressing, scaling and sampling!

Now heres instructions how to make Numeric Gate which writes value to Arduino.
Insert new Numeric Gate. Fill Gate ID. and N ID. fields same way as in first Numeric Gate
configuration. Remember to use individual N ID eg. 6. Now when you wanto to write values to
Arduino, only change to previous procedure is to put a check tap to Enable writing to device box

Simple and easy isnt it? That is all changes you have to make compared to read only numeric
gate. Addressing of this kind of gate goes exactly the same way as read only gate. In my case this
Temperature Setpoint is 7:th in Arduino sketch modbus register list, so address for this is 3:6!

Reading digital inputs states with numeric gate.

Lets begin with a short math lesson. Maybe easiest way to read bit states eg. digital inputs with
winlog with only one Numeric gate is to use Bitwise operation.
Lets say that we want to read Arduino digital inputs 2, 3, 4 and 5. Take four values 1, 2, 4 and 8.
All inputs low states represents value 0 and DI2 high value is 1, DI3 high value is 2, DI4 high value is
4 and DI 5 high value is 8.
In Arduino sketch we use this line to write input states to Winlog:
regs[MB_STR] = (DigIn1 + DigIn2 + DigIn3 + DigIn4);
If DI2 state is high and other states are zero sum of that expression is 1+0+0+0=1.
If DI2 and DI3 states are high and other states are zero sum of that expression is 1+2+0+0=3
If DI2 and DI3 and DI4 states are high and DI5 state is low sum is 1+2+4+0=7
If all DIs states are high sum is 1+2+4+8= 15. Ok, nice values but what these values have to do with
single bits?!

Now lets convert these integers to 4 digit binary values


1 = 0001, 2 = 0010, 4 = 0100 and 8 = 1000 and tadah Now you have individual bits!
So all you have to do is set those values to DigInX variables when certain digital input state is high.
Eg. in Arduino sketch DigIn1 is state of Digital input pin 2. When input pins state goes high, variable
DigIn1 gets value 1.
if (buttonState == HIGH){
DigIn1 = 1;}
Now lets make Numeric Gate for bit state readings.
Everything goes with the same way as two previous Gate configurations. In value tab set decimal
digits to 0 and in variable type you can use BCD or U_WORD or FLOAT, that depends how many bit
states you want to read. In this example we have only four bit states and sum of those values is 15
so we can use BCD or U_WORD, its your choice. I used BCD. Address in this case is 3:8.

Now when you have done all numeric gates what you need in your project its time to move on and
make a template to visualize measurement values.

Open template folder from project tree and make new file and rename it to Main.
Open that file. At first we have to add all gates we want to use in this template. Left side of the
window there is a Property editor . Locate field named Gates and click on that field. Field turns to
white and riht side to that field comes button with three dots. Click that button and Template
Gates window opens.

Click Add gate button and from type drop down list select Numeric. Now you can see all your
numeric gates. Add all gates what you want to use and finally clik OK to exit. Now we have added
gates to this template.
Next is to add labels, leds and thermometer to our measurements.
From toolbar click Frame, go to empty template and click to place the frame to its place. Resize
frame if needed.

Now click A button in toolbar. This is Label and it is used to show your own text or measurement
values in your template. Place label to your framed template and make as many copies of that what
you have values to read.

Note that all of those texts are also labels.

Now its time to add gates to labels.


Select label where you want to add a gate. From property editor click Gate field and press appeared
box with three dots. Select a gate window opens and select gate you want to use from drop down
list. Then hit ok. After that under Gate field in Property editor is Label field. To here you can write
your own text eg. Temperature 1 or you can point a format how value is shown in label frame. Now
we use Decimal value with 1 decimal digit and unit is C, so place this text to Label field: %5.1lf C.
Do this same operation to all label frames .

Now lets put some leds to indicate digital input bit states. Click led symbol in toolbar and place it to
template. Add as many leds as you have bits to read. Now we have four bits what we want to read,
so add four leds.
Adding gate is quite similar as it was with Labels, now you just have to locate Led ON conditions
field from property editor.

Click Add in Conditions window and State condition window opens. Now select gate where you configured
Bit states. And from Condition drop down list select =(Bitwise). Now you should see same view as picture
shows. Value (Bitmask) frame is used to mask or read active/inactive bit states. So heres possible to read
32 bits and now we are using just four. Refer to that little math lesson Now because this led is condition
for digital input 1 and value for that variable is 1 we only need to change 0 bit from X to 1. 2nd. Led
condition you change 1 bit from X to 1 (all other bits are set to X) and so on.

Finally heres how to make numeric field where you can send values to Arduino.
Click Edit symbol from toolbar and place it to template.
Again locate Gate field from Property editor list. Box with three dots appears to right side. Click and add
gate what is used to Write values to arduino.
When this is done basically you are ready now. Ive added some extra too and those goes same way as
weve done so far. Just locate the Gate field from property editor list and add right gate and it is done. It is
very simple.

Save your template and open Code folder from project tree. The code we make is used just to open our
main template when project is executed, thats all. Make new file to Code folder and rename it to Main.
Place this code there:

// Function called at Winlog startup


Function void Main()
#Startup

//***************************************
// Open default page
//***************************************
TPageOpen("Main");
end

Press save button and our code is ready. Now its good time to load our sketch to Arduino. After this is
done you can execute your Winlog project. Main template opens and it is very likely that there is some
communication errors at startup. So from toolbar select Supervision -> Status -> Devices. A new window
opens where you can see your device (Arduino UNO). Now what you do is double click that row to disable
device scanning. After that press Reset COM errors- button. Wait about 10 seconds and enable scanning by
double clicking device row. Status should become OK instead of KO and text turns to blue. Now
communicating is ok and values should be visible at your template. If not, do this same again. If still not ok,
check your configurations etc. I made this project along writing these instructions, so believe me it is
working. :D
Hopefully these instructions are useful and give some tips or basic knowledge how to communicate with
Winlog and Arduino.

You might also like