de:project_s7:dt_to_string

TIA typeconversion: date_and_time to string

english I needed the operation for the SMTP protocol. Emails sent must also include the exact time in string format. The program performs a simple step-by-step conversion. It can be solved more concisely and elegantly, but I have no desire or time to do so. The image below shows the progress of this three-part conversion.

1.) The initial form is the date_and_time variable, where the current time is read with the RD_LOC_T function
2.) With BLKMOV, this is decomposed bytes, as follows:

  • datum[0]: year 1990..2069
  • datum[1]: month 1..12
  • datum[2]: day 1..31
  • datum[3]: hour 0..23
  • datum[4]: minute 0..59
  • datum[5]: second 0..59
  • datum[6]: MSD v. ms 00..99
  • datum[7]: (MSB) LSV: ms 0..9 LSB: Weekday 1..7

3.) Bytes in BCD format will be converted to char array with the byte_to_2_char function
4.) The char array is moved to string [20] with BLKMOV

The byte_to_2_char function converts the two-digit BCD positions (e.g., year, month, day, hour, ..) of the variable byte date_and_time to two char values. These chars can later be converted to string form.

Because of the BLKMOVs, it is important that the smtpMessages DB

  • The DB number (4) must remain or the absolute address of the DB must be corrected in the program
  • variables in DB should remain in place due to direct addressing (absolute addresses cannot change)
  • DB can not be optimized (due to direct addressing)

deutsch Ich brauchte die Operation für das SMTP-Protokoll. Gesendete E-Mails müssen auch die genaue Uhrzeit im Stringformat enthalten. Das Programm führt eine einfache Schritt-für-Schritt-Konvertierung durch. Es lässt sich prägnanter und eleganter lösen, aber dazu habe ich weder Lust und Zeit. Das Bild unten zeigt den Fortschritt dieser dreiteiligen Konvertierung. 1.) Ausgangsform ist die Variable date_and_time, wo die aktuelle Zeit mit der Funktion RD_LOC_T gelesen wird
2.) Mit BLKMOV wird dies wie folgt in Bytes zerlegt:

  • datum[0]: year 1990..2069
  • datum[1]: month 1..12
  • datum[2]: day 1..31
  • datum[3]: hour 0..23
  • datum[4]: minute 0..59
  • datum[5]: second 0..59
  • datum[6]: MSD v. ms 00..99
  • datum[7]: (MSB) LSV: ms 0..9 LSB: Weekday 1..7

3.) Bytes im BCD-Format werden mit der Funktion byte_to_2_char in ein char-Array konvertiert
4.) Das Char-Array wird mit BLKMOV in den String [20] verschoben

Die Funktion byte_to_2_char wandelt die zweistelligen BCD-Positionen (z. B. Jahr, Monat, Tag, Stunde, …) des Variablenbytes date_and_time in zwei Zeichenwerte um. Diese Zeichen können später in Zeichenfolgen umgewandelt werden.

Wegen der BLKMOVs ist es wichtig, dass die „smtpMessages“ DB

  • Die DB-Nummer (4) muss erhalten bleiben oder die absolute Adresse des DB muss im Programm korrigiert werden
  • Variablen im DB sollen wegen direkter Adressierung bestehen bleiben (absolute Adressen können sich nicht ändern)
  • DB darf nicht optimiert werden (wegen direkter Adressierung)

magyar A műveletre nekem az SMTP protokollhoz volt szükségem. Az elküldött email-ekben szerepelnie kell a pontos időnek is, string formában. A program egy egyszerű lépésről-lépésre konverziót végez. Biztos meg lehet ezt oldani tömörebben és elegánsabban is, de erre se kedvem se időm nincs. A lenti képen látható ennek a háromrészes konverziónak a menete.

1.) A kiindulási forma a date_and_time változó, ahová az aktulális idő beolvasásra kerül RD_LOC_T függvénnyel
2.) BLKMOV-val ez kerül bájtos széttagolásra, az alábbiak szerint:

  • datum[0]: year 1990..2069
  • datum[1]: month 1..12
  • datum[2]: day 1..31
  • datum[3]: hour 0..23
  • datum[4]: minute 0..59
  • datum[5]: second 0..59
  • datum[6]: MSD v. ms 00..99
  • datum[7]: (MSB) LSV: ms 0..9 LSB: Weekday 1..7

3.) A byte_to_2_char függvénnyel a BCD formátumú bájtok át lesznek konvertálva char array-be
4.) A char array BLKMOV-val átmozgatásra kerül a string[20]-ba

A byte_to_2_char függvény a date_and_time változó byte kétjegyű BCD pozícióit (pl. év, hó, nap, óra,..) konvertálja két char értékre. Ezek a char-ok később string formába konvertálhatók.

A BLKMOV-ok miatt fontos, hogy a smtpMessages DB

  • A DB számának (4) maradnia kell, vagy a programban a DB abszolut címét korrigálni kell
  • változói a DB-ben a direkt címzés miatt a helyükön maradjanak (az abszolut címei nem változhatnak)
  • A DB-nek nem szabad optimalizáltnak lennie (a direkt címzés miatt)

TIA typeconversion: date_and_time to string

The contents of the following text file date_and_time_to_string_fc_fb.scl:

  • FUNCTION byte_to_2_char
  • DATA_BLOCK smtpMessages
  • FUNCTION_BLOCK generateSMTPMessage

The file must be uploaded to the External source files section of the TIA portal with the Add new external file function, and then the generate block form source operation must be started:

date_and_time_to_string_fc_fb.scl

Donate

If you have any further questions or have any issues that you can't handle, please contact me! » Impressum

~~socialite~~

2022/04/21 15:01

Post views: 587

  • de/project_s7/dt_to_string.txt
  • 2022/04/21 15:01
  • ()