Both sides previous revision
Previous revision
Next revision
|
Previous revision
|
blocks:drivers:example [2019-09-17 16:32] admin Added super call |
blocks:drivers:example [2023-06-12 11:11] admin Clarified connect callback parameters |
- It's available as a [[https://www.dataton.com/downloads/watchout|free download]], so anyone can use it to try out the driver. | - It's available as a [[https://www.dataton.com/downloads/watchout|free download]], so anyone can use it to try out the driver. |
| |
Open the driver using the Atom editor, and follow along in the code as you read this walk-through. | Open the driver using a [[blocks:drivers:tools|code editor]], and follow along in the code as you read this walk-through. |
===== Import Statements ===== | ===== Import Statements ===== |
| |
</code> | </code> |
| |
These other files provide definitions of system functions used to communicate with the device, such as the NetworkTCP interface imported from the "system/Network" file. You can navigate to referenced classes or files by command-clicking (Mac) or control-clicking (Windows) these items in the Atom editor. The referenced files contain the relevant declarations, and often also contain comments that further describe the referenced functions. | These other files provide definitions of system functions used to communicate with the device, such as the NetworkTCP interface imported from the "system/Network" file. You can navigate to referenced classes or files by command-clicking (Mac) or control-clicking (Windows) these items in the editor. The referenced files contain the relevant declarations, and often also contain comments that further describe the referenced functions. |
| |
Not only does this provide relevant documentation. It also provides information for the TypeScript compiler as well as for the [[blocks:drivers:tools|Atom]] editor. The Atom editor uses this information to guide you when writing code, often providing hints as you type, showing available functions, parameters, etc. If you make a mistake, this is often highlighted in red by the Atom editor and/or flagged by the TypeScript compiler. | Not only does this provide relevant documentation. It also provides information for the TypeScript compiler as well as for the [[blocks:drivers:tools|code editor]]. The code editor uses this information to guide you when writing code, often providing hints as you type, showing available functions, parameters, etc. If you make a mistake, this is often highlighted in red by the code editor and/or flagged by the TypeScript compiler. |
| |
===== Driver Class Declaration ===== | ===== Driver Class Declaration ===== |
</code> | </code> |
| |
Event subscriptions are similar to how //addEventListener// is used in web browsers to listen to DOM events. The 'connect' event indicates that the connection status of the socket has changed. All events are described in the Network.ts file. Jump directly to the relevant declaration by command/control-clicking a //subscribe// call. | Event subscriptions are similar to how //addEventListener// is used in web browsers to listen to DOM events. The 'connect' event indicates that the connection status of the socket has changed or failed (as indicated by the type field of the message parameter). All events are described in the Network.ts file, so always look there for full details. Jump directly to the relevant declaration by command/control-clicking a //subscribe// call. |
| |
When the subscribed-to event occurs, the function body following the //[[https://basarat.gitbooks.io/typescript/docs/arrow-functions.html|lambda]]// => operator will be invoked. Either do what needs to be done right here, if its only a line or two, or call a function defined elsewhere in the driver. | When the subscribed-to event occurs, the function body following the //[[https://basarat.gitbooks.io/typescript/docs/arrow-functions.html|lambda]]// => operator will be invoked. Either do what needs to be done right here, if its only a line or two, or call a function defined elsewhere in the driver. |