The code for sending and receiving data to an attached Uno R3 board is as follows:
Code:
myDLL = LoadDLL( SYSTEM_PUBLICATION_DIR + "Interaktiv.dll" );
var mySend = "null";
var myReceive = "null";
var myPort ="COM3";
var myData = myDLL.CallFn( "uno_r_three", false, "string","string",mySend,"string",myReceive,"string",myPort);
The first line simply loads the DLL and makes it available to Opus by assigning it to the myDLL variable.
The next three lines are the values SENT to the DLL.
- mySend - this is the data that is passed to the code running on the Uno R3 board. If no data is sent use "null" in inverted commas.
- myReceive - this should be either "null" or "true". This tells the DLL whether it should expect a reply from the Uno R3 board code and to return it to Opus if "true".
- myPort - this is the USB port on which the Uno R3 Board is connected.
The final line is the DLL Call which sends the values above and if myReceive is "true" will store the returned value in the myData variable.
Please note that if you use the DLL to receive data but don't send any back, your program / Opus will probably hang and will need a forced shut-down. I'll look at a solution to this in the future.There are several examples included:
The two LED examples are the simplest and demonstrate how to send information to the Uno R3 code and register a hardware change (IE LED lights or changes colour).
The LM35 example shows how to read information from a component that is constantly providing data. It works by ONLY taking a reading and sending it when the code on the Uno R3 receives a value, via the DLL, from Opus. In this instance, the myReceive variable is set to "true", which causes the DLL to read the information sent by the Uno R3 code and return it back to Opus.
The Push Button example demonstrates how to read information from a component that is in a temporary state. This works by understanding that Uno R3 board is basic a mini computer that is constantly running your code. When the button is pressed (and subsequently released) the code on the Uno R3 registers this and we change the value of a variable (much like we do in Opus) in the board's code.
While the board is running the code, that variable remains set until we tell it to change. This allows us to query the code at any point to check the value of the variable (and in this case reset it). We can query it every second if we need to respond quickly to the button press or we can query it daily.
The DLL and Uno function is provided as is for anybody interested in using Opus with hardware interfacing.
</mack>