User Tools

Site Tools


built_in:usbserial

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
built_in:usbserial [2014/12/18 21:48]
bcarroll created
built_in:usbserial [2016/01/14 00:41] (current)
Line 2: Line 2:
  
 ===== Methods ===== ===== Methods =====
-^Method ^Description ^ +^ Method                              ^ Description                                    
-|USBSerial.Start() | | +| USBSerial.SetOnReceivecallback                                                 
-|USBSerial.Stop() | | +| USBSerial.Start()                                                                  
-|USBSerial.Writep1 ) | | +| USBSerial.Stop()                                                                   
-|USBSerial.SetOnReceive( p1 ) | |+| USBSerial.Write( p1, mode         mode is optional, can be "US-ASCII" (vs UTF8)  | 
 + 
 +=====Example===== 
 +//(Example taken from the DroidScript sample section)// 
 +<code javascript> 
 +// Simple serial transmit example.  
 +//  
 +// Note: this application only works on devices that support   
 +// OTG and allow access to external serial devices.  
 +//  
 +// Known to work: Nexus7, GalaxyS3/S4, ExperiaZUltra, TescoHudl      
 +// Don't work: Nexus4, GalaxyS1, AsusMemo  
 + 
 +//Called when application is started.  
 +function OnStart()  
 +{  
 + //Create a layout with objects vertically centered.  
 + lay = app.CreateLayout( "linear", "VCenter,FillXY" );  
 + 
 + //Create a button 1/3 of screen width and 1/4 screen height.  
 + btn = app.CreateButton( "Press Me", 0.3, 0.25 );  
 + lay.AddChild( btn );  
 +  
 + //Set function to call when button pressed.  
 + btn.SetOnTouch( btn_OnTouch );  
 +  
 + //Add layout to app.  
 + app.AddLayout( lay );  
 +  
 + //Create USB serial object.  
 + usb = app.CreateUSBSerial();  
 +}  
 + 
 +//Called when user touches our button.  
 +function btn_OnTouch()  
 +{  
 + //Send serial text to device.  
 + usb.Write( "Hello serial device!" );  
 +} </code>
built_in/usbserial.1418939301.txt.gz · Last modified: 2014/12/19 05:48 (external edit)