Skip to content

Commit

Permalink
v0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
brickpool committed Mar 29, 2018
1 parent acc197e commit fc27c53
Show file tree
Hide file tree
Showing 9 changed files with 685 additions and 349 deletions.
14 changes: 8 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## 0.5.0-beta.3 - 2018-03-08
## [0.5.0] - 2018-03-29
### Added
- CHANGELOG.md added to the project folder
- Library Reference Manual (RefManual.md) added to the project folder
- DTE Interface description (DTE-Interface.md) added to the project folder
- LogoClient::GetPlcDateTime and WritePlcDateTime
- LogoClient::ReadByte, WriteByte and CpuError
- Example ReadClockDemo.ino added to the project folder
- Example WriteClockDemo.ino added to the project folder
- Date/Time functions: LogoClient::GetPlcDateTime and WritePlcDateTime
- System info function: LogoClient::GetOrderCode
- Private functions: LogoClient::GetOrderCode, WriteByte and CpuError
- Security function: LogoClient::GetProtection
- Example ReadClockDemo.ino and WriteClockDemo.ino added to the project folder
- Example PlcInfoDemo.ino added to the project folder

### Changed
- Customization of CPU Exception Codes for LogoClient::CpuError
Expand Down Expand Up @@ -118,7 +120,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- LogoPG.cpp added to the project folder
- keywords.txt added to the project folder

## 0.1.0 - 2018-02-07
## 0.1.0-pre-alpha - 2018-02-07
### Added
- Initial version created
- LICENCE.md added to the project
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Information about the API is described in the document [LOGO! PG Library Referen
All information about the protocol is described in a separate document: [LOGO! PG Protocol Reference Guide](/extras/docs/PG-Protocol.md)

## Releases
The current library version is [0.4.3](https://github.com/brickpool/logo/releases). This version is not the final version, it is a release candidate, with patchlevel 3.
The current library version is [0.5.0](https://github.com/brickpool/logo/releases). This version is not the final version, it is a release candidate, with patchlevel 0.

## Examples
This directory contains the library and some examples that illustrate how the library can be used. The examples were tested with an Arduino UNO. Other hardware has not been tried.
Expand All @@ -18,6 +18,7 @@ This directory contains the library and some examples that illustrate how the li
- [CyclicReading.ino](/examples/CyclicReading/CyclicReading.ino) Cyclic reading of inputs, outputs and flags. The example uses the same function as the LOGO!Soft Routine _Online Test_.
- [ReadClockDemo.ino](/examples/ReadClockDemo/ReadClockDemo.ino) The example reads the date and time from the _LOGO!_ controller.
- [WriteClockDemo.ino](/examples/WriteClockDemo/WriteClockDemo.ino) The example writes a date and time to the _LOGO!_ controller.
- [PlcInfoDemo.ino](/examples/PlcInfoDemo/PlcInfoDemo.ino) The example reads the Ident Number, Firmware version and Protection level from the PLC.

## Dependencies
- _LOGO!_ controller version __0BA4__, __0BA5__ or __0BA6__, e.g. part number `6ED1052-1MD00-0BA6`
Expand Down
123 changes: 123 additions & 0 deletions examples/PlcInfoDemo/PlcInfoDemo.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#include <CustomSoftwareSerial.h>
#include "LogoPG.h"

const byte rxPin = 2;
const byte txPin = 3;

// set up the SoftwareSerial object
CustomSoftwareSerial LogoSerial(rxPin, txPin);
// set up the LogoClient object
LogoClient LOGO(&LogoSerial);

void setup() {
// initialize digital pin LED_BUILTIN as an output and turn the LED off
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);

// Init Monitor interface
Serial.begin(9600);
while (!Serial) ; // Needed for Leonardo only

// Start the SoftwareSerial Library
LogoSerial.begin(9600, CSERIAL_8E1);
// Setup Time, 1s.
delay(1000);
Serial.println("");
Serial.println("Cable connected");
if (LogoSerial.isListening())
Serial.println("Softserial is listening !");
}

void loop()
{
int Result;

// Connection
while (!LOGO.Connected)
{
if (!Connect())
delay(2000);
}

// System info functions
TProtection Info;
Result = LOGO.GetProtection(&Info);
if (Result == 0)
{
if (Info.sch_rel > 0)
{
Serial.print("CPU protection level:");
Serial.print(" sch_schal=");
Serial.print(Info.sch_schal);
Serial.print(", sch_par=");
Serial.print(Info.sch_par);
Serial.print(", sch_rel=");
Serial.print(Info.sch_rel);
Serial.print(", bart_sch=");
Serial.println(Info.sch_rel);
// 'anl_sch' is always 0
}
}
else
CheckError(Result);

// Security functions
TOrderCode OrderCode;
Result = LOGO.GetOrderCode(&OrderCode);
if (Result == 0)
{
Serial.print("Order code: ");
Serial.println(OrderCode.Code);
// print firmware version, if the values are valid
if (OrderCode.V1 > 0 && OrderCode.V2 > 0 && OrderCode.V3 > 0)
{
char Version[] = "V0.00.00";
sprintf(Version, "V%d.%02d.%02d",
OrderCode.V1,
OrderCode.V2,
OrderCode.V3
);
Serial.print("Firmware version: ");
Serial.println(Version);
}
}
else
CheckError(Result);

delay(10000);
}

bool Connect()
{
int Result = LOGO.Connect();
Serial.println("Try to connect with LOGO");
if (Result == 0)
{
// turn the built-in LED on
digitalWrite(LED_BUILTIN, HIGH);
Serial.println("Connected!");
Serial.print("PDU Length = ");
Serial.println(LOGO.GetPDULength());
}
else
{
Serial.println("Connection error!");
}
return Result == 0;
}

void CheckError(int ErrNo)
{
Serial.print("Error No. 0x");
Serial.println(ErrNo, HEX);

// Checks if it's a LOGO Error => we need to disconnect
if (ErrNo & 0x00FF)
{
// turn the built-in LED off
digitalWrite(LED_BUILTIN, LOW);
Serial.println("LOGO ERROR, disconnecting.");
LOGO.Disconnect();
}
}

37 changes: 28 additions & 9 deletions examples/WriteClockDemo/WriteClockDemo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
const byte rxPin = 2;
const byte txPin = 3;

const unsigned long START_TIME = 1357041600; // Jan 1 2013
const unsigned long MY_TIME = 1522238400; // Mar 28 2018

// set up the SoftwareSerial object
CustomSoftwareSerial LogoSerial(rxPin, txPin);
Expand All @@ -29,6 +29,10 @@ void setup() {
Serial.println("Cable connected");
if (LogoSerial.isListening())
Serial.println("Softserial is listening !");

// set the system time to the give time MY_TIME
if (timeStatus() != timeSet)
setTime(MY_TIME);
}

void loop()
Expand All @@ -50,15 +54,14 @@ void loop()
{
Serial.println("STOPPING THE PROG");
LOGO.PlcStop();
Serial.print("DEFAULT: ");
Result = LOGO.SetPlcDateTime(START_TIME);
breakTime(START_TIME, DateTime);
}
else
{
Serial.print("LOGO Clock: ");
Result = LOGO.GetPlcDateTime(&DateTime);
if (LogoClockStatus() != timeSet)
{
Serial.print("Set Time: ");
Result = LOGO.SetPlcDateTime(now());
}
}
Serial.print("LOGO Clock: ");
Result = LOGO.GetPlcDateTime(&DateTime);
if (Result == 0)
{
DisplayClock(DateTime);
Expand Down Expand Up @@ -129,3 +132,19 @@ void CheckError(int ErrNo)
LOGO.Disconnect();
}
}

timeStatus_t LogoClockStatus()
{
// Su 00:00 01-01-2003
const unsigned long START_TIME = 1041379200;
const uint8_t START_WDAY = 1;
const int op_mode;

TimeElements tm;
if (LOGO.GetPlcDateTime(&tm) == 0) {
if (!(makeTime(tm) == START_TIME && tm.Wday == START_WDAY))
return timeSet;
}
return timeNotSet;
}

Loading

0 comments on commit fc27c53

Please sign in to comment.