Ogni dispositivo slave 1-Wire è caratterizzato da un identificatore univoco a 64 bit (8 bytes) utilizzato come indirizzo. L’identificatore è diviso in 3 sezioni. 1o byte (LSB) contiene il codice della famiglia che identifica il tipo di dispositivo; i successivi 6 bytes rappresentano l’indirizzo individuale; l’ultimo byte (MSB) contiene il CRC (Cyclic Redundancy Checksum).
+--------+--------+--------+--------+--------+--------+--------+--------+ | CRC | ID Code (6 Bytes) | Family | +--------+--------+--------+--------+--------+--------+--------+--------+
Questo blocco funzione da eseguire in task Back utilizzabile con modello a cascata, esegue la lettura del codice di identificazione di un dispositivo One-Wire, occorre fornire in OWCore l’indirizzo di allocazione del FB OWireCore di gestione convertitore one-wire. Attivando Enable, viene eseguita la lettura del codice di identificazione del dispositivo connesso al bus. Attenzione! Bisogna avere un solo dispositivo connesso al bus.
Al termine della lettura del codice si attiva l’uscita Done. Se la lettura ha esito positivo si attiva per un loop di programma l’uscita Ok e gli 8 bytes del codice sono trasferiti in IDCode. Disattivando Enable si azzera Done e l’eventuale Fault, per eseguire nuovamente il comando occorre riabilitare l’ingresso Enable.
Approfondimenti
- In questo articolo informazioni sul bus 1-Wire.
- In questo topic sono riportate informazioni sul bus 1-Wire.
Famiglia dispositivi
Come visto l’ultimo byte del codice ritornato indica la famiglia del dispositivo, di seguito un elenco.
Family | Device | Description |
---|---|---|
05 | DS2405 | Addressable Switch |
10 | DS18S20 | High-Precision 1-Wire Digital Thermometer |
12 | DS2406 | Dual Addressable Switch Plus 1Kb Memory |
1D | DS2423 | 4kbit 1-Wire RAM with Counter |
1F | DS2409 | MicroLAN Coupler |
22 | DS1822 | Econo 1-Wire Digital Thermometer |
26 | DS2438 | Smart Battery Monitor |
28 | DS18B20 | Programmable Resolution 1-Wire Digital Thermometer |
29 | DS2408 | 1-Wire 8-Channel Addressable Switch |
30 | DS2760 | High-Precision Li+ Battery Monitor |
3A | DS2413 | 1-Wire Dual-Channel Addressable Switch |
3B | DS1825 | Programmable Resolution 1-Wire Digital Thermometer With 4-Bit ID |
42 | DS28EA00 | 1-Wire Digital Thermometer with Sequence Detect and PIO |
7E | EDS00xx | 1-Wire Environmental Sensors |
Descrizione
Enable (BOOL) Comando abilitazione.
SpyOn (BOOL) Se attivo permette di spiare il funzionamento della FB (Vedi articolo).
OWCore (@OWireCore_v2) Indirizzo allocazione FB di gestione core one-wire.
Done (BOOL) Si attiva al termine della esecuzione comando.
Fault (BOOL) Attivo se errore esecuzione.
Ok (BOOL) Attivo per un loop se lettura codice eseguita correttamente.
IDCode (LWORD) Codice a 64 bits acquisito dal dispositivo.
OkCount (UDINT) Contatore acquisizioni correttamente eseguite.
Errors (UDINT) Contatore errori di esecuzione si incrementa ad ogni errore.

Spionaggio funzionamento
Se SpyOn attivo è possibile utilizzare la console di spionaggio per verificare il funzionamento della FB. Sono previsti vari livelli di triggers.
Trigger di spionaggio
16#10000000 | Lg: Messaggi di log funzionamento. |
16#40000000 | Er: Errori di esecuzione. |
Esempi
Come utilizzare gli esempi.
FBD_OWRdIdentifier, ST_OWRdIdentifier: Viene eseguita la lettura dell’identificativo di un dispositivo connesso al bus one-wire. Selezionare la porta COM alla quale è connesso il bus. E’ possibile acquisire sia un TAG a contatto che il lettore RFID 1-Wire.
ST_TAGReaderMultiplexer: Nella lettura dei TAGs sia a contatto che RFID non è possibile come nei normali dispositivi One-Wire avere più dispositivi connessi in parallelo allo stesso bus. Per poter acquisire più lettori con una unica interfaccia possiamo sfruttare le uscite statiche dei nostri moduli CPU (MPS054 e MPS056) che essendo di tipo MOS possono essere utilizzate per multiplexare il segnale One-Wire. Questo programma gestisce il multiplexing di due lettori TAG utilizzando le uscite 0 e 1 di un modulo CPU
LogicLab (Ptp120, ST_OWRdIdentifier)
PROGRAM ST_OWRdIdentifier
VAR
TAGPresent : BOOL; (* Identifier TAG on the reader *)
Sp : SysSerialPort; (* Serial port management *)
OWCore : OWireCore_v2; (* FB One-Wire core *)
OWIdf : OWRdIdentifier_v1; (* FB read identifier *)
END_VAR
// *****************************************************************************
// PROGRAM "ST_OWRdIdentifier"
// *****************************************************************************
// If a TAG is connected to the reader its code is read.
// -----------------------------------------------------------------------------
// -------------------------------------------------------------------------
// INITIALIZATION
// -------------------------------------------------------------------------
IF (SysFirstLoop) THEN
// Set serial port parameters.
Sp.COM:=ADR('PCOM255.0'); //COM port definition
// Sp.COM:=ADR('COM0'); //COM port definition
Sp.Baudrate:=9600; //Baudrate
Sp.Parity:='N'; //Parity
Sp.DataBits:=8; //Data bits
Sp.StopBits:=1; //Stop bits
Sp.DTRManagement:=DTR_OFF; //DTR management
Sp.DTRComplement:=FALSE; //DTR complement
Sp.EchoFlush:=FALSE; //Received echo flush
Sp.DTROnTime:=0; //DTR On time delay (mS)
Sp.DTROffTime:=0; //DTR Off time delay (mS)
Sp.FlushTm:=0; //Flush time (mS)
Sp.RxSize:=0; //Rx buffer size
Sp.TxSize:=0; //Tx buffer size
// Set One-Wire core parameters.
OWCore.SpyOn:=TRUE; //Spy active
// OWCore.IType:=OW_ITYPE#OW_ITDS2480B; //Interface type
OWCore.IType:=OW_ITYPE#OW_ITDS2484; //Interface type
// Set One-Wire read identifier parameters.
OWIdf.SpyOn:=TRUE; //Spy active
OWIdf.OWCore:=ADR(OWCore); //One-Wire core management
END_IF;
// -------------------------------------------------------------------------
// READ IDENTIFIER CODE
// -------------------------------------------------------------------------
// One-Wire core management
Sp(Open:=TRUE); //Serial port management
eTO_JUNK(SysSetSerialDTR(OWCore.CPower, Sp.File)); //Manage DTR signal
OWCore.Enable:=NOT(OWIdf.Done); //Enable
OWCore.Power:=Sp.Opened; //Converter power
OWCore(File:=Sp.File); //FB One-Wire core
// Acquire the identifier code.
OWIdf.Enable:=OWCore.Done; //Enable
OWIdf(); //Read identifier
// If code has been read a identifier TAG is on the reader.
IF (OWIdf.Ok) THEN TAGPresent:=TRUE; END_IF;
IF (OWCore.OWBSts <> OW_BSTATUS#OW_BOK) THEN TAGPresent:=FALSE; END_IF;
// [End of file]
LogicLab (Ptp120, ST_TAGReaderMultiplexer
)
PROGRAM ST_TAGReaderMultiplexer
VAR
TAGIDx : USINT; (* TAG IDx *)
CaseNr : USINT; (* Program case *)
TimeBf : UDINT; (* Time buffer (mS) *)
TAGPresent : ARRAY[0..1] OF BOOL; (* TAG on the reader *)
Sp : SysSerialPort; (* Serial port management *)
OWCore : OWireCore_v2; (* FB One-Wire core *)
OWIdf : OWRdIdentifier_v1; (* FB read identifier *)
DOut : SysSetPhrDO; (* Digital output management *)
TAGCode : ARRAY[0..1] OF LWORD; (* TAG code *)
END_VAR
// *****************************************************************************
// PROGRAM "ST_TAGReaderMultiplexer"
// *****************************************************************************
// Multiplex two RFID TAG readers connected to the One-Wire bus. You can choose
// the converter to use.
//
// Sp.COM:=ADR('COM0') and OWCore.IType:=OW_ITYPE#OW_ITDS2480B
// To use the DS2480B One-Wire adapter connected to serial COM0.
//
// Sp.COM:=ADR('PCOM255.0') and OWCore.IType:=OW_ITYPE#OW_ITDS2484
// To use the DS2484 One-Wire interface built in on the CPU module.
// -----------------------------------------------------------------------------
// -------------------------------------------------------------------------
// INITIALIZATION
// -------------------------------------------------------------------------
IF (SysFirstLoop) THEN
// Set serial port parameters.
// Sp.COM:=ADR('PCOM255.0'); //COM port definition
Sp.COM:=ADR('COM0'); //COM port definition
Sp.Baudrate:=9600; //Baudrate
Sp.Parity:='N'; //Parity
Sp.DataBits:=8; //Data bits
Sp.StopBits:=1; //Stop bits
Sp.DTRManagement:=DTR_OFF; //DTR management
Sp.DTRComplement:=FALSE; //DTR complement
Sp.EchoFlush:=FALSE; //Received echo flush
Sp.DTROnTime:=0; //DTR On time delay (mS)
Sp.DTROffTime:=0; //DTR Off time delay (mS)
Sp.FlushTm:=0; //Flush time (mS)
Sp.RxSize:=0; //Rx buffer size
Sp.TxSize:=0; //Tx buffer size
// Set One-Wire core parameters.
OWCore.SpyOn:=TRUE; //Spy active
OWCore.IType:=OW_ITYPE#OW_ITDS2480B; //Interface type
// OWCore.IType:=OW_ITYPE#OW_ITDS2484; //Interface type
// Set One-Wire read identifier parameters.
OWIdf.SpyOn:=TRUE; //Spy active
OWIdf.OWCore:=ADR(OWCore); //One-Wire core management
END_IF;
// -------------------------------------------------------------------------
// READ IDENTIFIER CODE
// -------------------------------------------------------------------------
// Serial port management.
Sp(Open:=TRUE); //Serial port management
eTO_JUNK(SysSetSerialDTR(OWCore.CPower, Sp.File)); //Manage DTR signal
// One-Wire core management, if One-Wire interface is not set enable the
// core. The "OWISet" signal become false only on an error.
OWCore.Power:=Sp.Opened; //Converter power
OWCore(File:=Sp.File); //FB One-Wire core
IF NOT(OWCore.OWISet) THEN OWCore.Enable:=TRUE; CaseNr:=0; RETURN; END_IF;
// One-Wire read identifier management.
OWIdf(); //Read identifier
// -------------------------------------------------------------------------
// DIGITAL OUTPUT MANAGEMENT
// -------------------------------------------------------------------------
// Manage digital outputs on CPU module to multiplex the One-Wire bus.
DOut.Address:=255; //Module address
DOut.Mode:=DO_MODE#DO_8_LL; //Management mode
DOut.Mask:=16#00000003; //Output mask (Mask Output 0 and 1)
DOut(); //Digital output management
// -------------------------------------------------------------------------
// READ IDENTIFIER CODES
// -------------------------------------------------------------------------
// Program cases.
CASE (CaseNr) OF
// ---------------------------------------------------------------------
// Change the TAG ID selector and manage output 0 and 1 to multiplex the
// One-Wire bus.
0:
TAGIDx:=TAGIDx+1; //TAG IDx
IF (TAGIDx > 1) THEN TAGIDx:=0; END_IF;
IF (TAGIDx = 0) THEN DOut.Value:=16#00000001; END_IF;
IF (TAGIDx = 1) THEN DOut.Value:=16#00000002; END_IF;
// Disable the One-Wire management.
OWCore.Enable:=FALSE; //Enable
OWIdf.Enable:=FALSE; //Enable
TimeBf:=SysTimeGetMs(); //Time buffer (mS)
CaseNr:=CaseNr+1; //Program case
// ---------------------------------------------------------------------
// After a digital output settling time enable the core.
1:
IF ((SysTimeGetMs()-TimeBf) < TO_UDINT(T#20ms)) THEN RETURN; END_IF;
OWCore.Enable:=TRUE; //Enable
TimeBf:=SysTimeGetMs(); //Time buffer (mS)
CaseNr:=CaseNr+1; //Program case
// ---------------------------------------------------------------------
// Wait the core "Done" output and enable the read identifier..
2:
IF NOT(OWCore.Done) THEN RETURN; END_IF;
OWIdf.Enable:=TRUE; //Enable
// Waits the "Done". If it isn't "Ok" the TAG isn't present.
IF NOT(OWIdf.Done) THEN RETURN; END_IF;
IF NOT(OWIdf.Ok) THEN TAGPresent[TAGIDx]:=FALSE; TAGCode[TAGIDx]:=0; CaseNr:=0; RETURN; END_IF;
// TAG present and readed.
TAGPresent[TAGIDx]:=TRUE; //TAG on the reader
TAGCode[TAGIDx]:=OWIdf.IDCode; //TAG code
CaseNr:=0; //Program case
END_CASE;
// [End of file]