Tutorial by Examples

% Define serial port with a baud rate of 115200 rate = 115200; if ispc s = serial('COM1', 'BaudRate',rate); elseif ismac % Note that on OSX the serial device is uniquely enumerated. You will % have to look at /dev/tty.* to discover the exact signature of your % serial device ...
Assuming you created the serial port object s as in this example, then % Read one byte data = fread(s, 1); % Read all the bytes, version 1 data = fread(s); % Read all the bytes, version 2 data = fread(s, s.BytesAvailable); % Close the serial port fclose(s);
Assuming you created the serial port object s as in this example, then to close it fclose(s) However, sometimes you can accidentally lose the port (e.g. clear, overwrite, change scope, etc...), and fclose(s) will no longer work. The solution is easy fclose(instrfindall) More info at instrfin...
Assuming you created the serial port object s as in this example, then % Write one byte fwrite(s, 255); % Write one 16-bit signed integer fwrite(s, 32767, 'int16'); % Write an array of unsigned 8-bit integers fwrite(s,[48 49 50],'uchar'); % Close the serial port fclose(s);
It is common for memory performance to compress multiple values into a single primitive value. This may be useful to pass various information into a single variable. For example, one can pack 3 bytes - such as color code in RGB - into an single int. Packing the values // Raw bytes as input byte...
As there is currently no simple way of combining dictionaries in Swift, it can be useful to overload the + and += operators in order to add this functionality using generics. // Combines two dictionaries together. If both dictionaries contain // the same key, the value of the right hand side dicti...
The SQL 2008 standard defines the FETCH FIRST clause to limit the number of records returned. SELECT Id, ProductName, UnitPrice, Package FROM Product ORDER BY UnitPrice DESC FETCH FIRST 10 ROWS ONLY This standard is only supported in recent versions of some RDMSs. Vendor-specific non-stand...
When NSLog is asked to print empty string, it omits the log completely. NSString *name = @""; NSLog(@"%@", name); // Resolves to @"" The above code will print nothing. It is a good practice to prefix logs with labels: NSString *name = @""; NSLog(@&quo...
The for clause of a list comprehension can specify more than one variable: [x + y for x, y in [(1, 2), (3, 4), (5, 6)]] # Out: [3, 7, 11] [x + y for x, y in zip([1, 3, 5], [2, 4, 6])] # Out: [3, 7, 11] This is just like regular for loops: for x, y in [(1,2), (3,4), (5,6)]: print(x+y) ...
Pojo Model public class Model { private String firstName; private String lastName; private int age; /* Getters and setters not shown for brevity */ } Example: String to Object Model outputObject = objectMapper.readValue( "{\"firstName\":\"J...
ProcedureName ProcedureName argument1, argument2 Call a procedure by its name without any parentheses. Edge case The Call keyword is only required in one edge case: Call DoSomething : DoSomethingElse DoSomething and DoSomethingElse are procedures being called. If the Call keyword was rem...
To retrieve the result of a procedure call (e.g. Function or Property Get procedures), put the call on the right-hand side of an assignment: result = ProcedureName result = ProcedureName(argument1, argument2) Parentheses must be present if there are parameters. If the procedure has no parameter...
Parentheses are used to enclose the arguments of function calls. Using them for procedure calls can cause unexpected problems. Because they can introduce bugs, both at run-time by passing a possibly unintended value to the procedure, and at compile-time by simply being invalid syntax. Run-time Re...
Call ProcedureName Call ProcedureName(argument1, argument2) The explicit call syntax requires the Call keyword and parentheses around the argument list; parentheses are redundant if there are no parameters. This syntax was made obsolete when the more modern implicit call syntax was added to VB. ...
Two std::strings can be compared lexicographically using the operators ==, !=, <, <=, >, and >=: std::string str1 = "Foo"; std::string str2 = "Bar"; assert(!(str1 < str2)); assert(str > str2); assert(!(str1 <= str2)); assert(str1 >= str2); assert...
It's possible to attach an object to an existing object as if there was a new property. This is called association and allows one to extend existing objects. It can be used to provide storage when adding a property via a class extension or otherwise add additional information to an existing object. ...
The Objective-C runtime allows you to change the implementation of a method at runtime. This is called method swizzling and is often used to exchange the implementations of two methods. For example, if the methods foo and bar are exchanged, sending the message foo will now execute the implementation...
NSArray *array1 = [NSArray arrayWithObjects:@"one", @"two", @"three", nil]; NSArray *array2 = @[@"one", @"two", @"three"];
HTML5 data-* attributes provide a convenient way to store data in HTML elements. The stored data can be read or modified using JavaScript <div data-submitted="yes" class="user_profile"> … some content … </div> Data attribute structure is data-*, i.e. the n...
You can use the <img> or <object> elements to embed external SVG elements. Setting the height and width is optional but is highly recommended. Using the image element <img src="attention.svg" width="50" height="50"> Using <img> does not allo...

Page 144 of 1336