SerialComm

Enterprise Browser 3.5

Overview

The SerialComm API is an extension to facilitate serial communications using Enterprise Browser.

Supported ONLY on devices with an available serial port supported by the device OS.
For a device's API support info, see Release Notes in its device OS "Full Update" section.

Version History

  • Introduced in EB 2.5

Methods

disable()

Disables the serial channel, preventing communication with a remote device.

Parameters

  • callback : CallBackHandler

Callback

Async Callback Returning Parameters: HASH

    • status : STRING

      Connection status will either be success or failure.

    • message : STRING

      Returns the appropriate message.

Returns

Synchronous Return:

  • Void

Platforms

  • Android

Method Access:

  • Instance Method: This method can be accessed via an instance object of this class:
    • myObject.disable()
  • Default Instance: This method can be accessed via the default instance object of this class.
    • EB.SerialComm.disable()

enable()

Enables a serial channel for the application to communicate with a remote device.

Parameters

  • callback : CallBackHandler

Callback

Async Callback Returning Parameters: HASH

    • status : STRING

      Connection status will either be success or failure.

    • message : STRING

      Returns the appropriate message.

Returns

Synchronous Return:

  • Void

Platforms

  • Android

Method Access:

  • Instance Method: This method can be accessed via an instance object of this class:
    • myObject.enable()
  • Default Instance: This method can be accessed via the default instance object of this class.
    • EB.SerialComm.enable()

enumerate()

Gets a list of supported ports on the device.

Parameters

  • callback : CallBackHandler

Callback

Async Callback Returning Parameters: ARRAY

    • Object : SELF_INSTANCE: EB.SerialComm

Returns

Synchronous Return:

  • Void

Platforms

  • Android

Method Access:

  • Class Method: This method can be accessed only using the API class object.
    • EB.SerialComm.enumerate()

getDefault()

Returns an object that represents the default instance of the API class. For example, Camera.getDefault returns a Camera object that represents the default camera.

Parameters

  • callback : CallBackHandler

Callback

Async Callback Returning Parameters: SELF_INSTANCE

    Returns

    Synchronous Return:

    • SELF_INSTANCE : Default object of Module.

    Platforms

    • Android

    Method Access:

    • Class Method: This method can only be accessed via the API class object.
      • EB.SerialComm.getDefault()

    read(STRING readTimeOut)

    Reads the available data and returns it immediately. If no data is available, waits until a timeout occurs. Null is returned if no data is available.

    Parameters

    • readTimeOut : STRING

      Wait for data until timeout. The timeout unit is milli seconds. A timeout of zero means the calling read will wait forever unless interrupted by disable or release.

    • callback : CallBackHandler

    Callback

    Async Callback Returning Parameters: HASH

      • status : STRING

        Read data status will either be success or failure.

      • message : STRING

        Returns the appropriate message.

      • data : STRING

        On Success, it will return the data.

    Returns

    Synchronous Return:

    • Void

    Platforms

    • Android

    Method Access:

    • Instance Method: This method can be accessed via an instance object of this class:
      • myObject.read(STRING readTimeOut)
    • Default Instance: This method can be accessed via the default instance object of this class.
      • EB.SerialComm.read(STRING readTimeOut)

    setDefault(SELF_INSTANCE: EB.SerialComm defaultInstance)

    Allows setting of attributes of the default object instance by passing in an object of the same class.

    Parameters

    • defaultInstance : SELF_INSTANCE: EB.SerialComm

      An instance object that is of the same class.

    • callback : CallBackHandler

    Returns

    Synchronous Return:

    • Void

    Platforms

    • Android

    Method Access:

    • Class Method: This method can be accessed only via the API class object.
      • EB.SerialComm.setDefault(SELF_INSTANCE: EB.SerialComm defaultInstance)

    write(STRING data)

    Writes from buffer to the opened communication channel.

    Parameters

    • data : STRING

      Buffer which contains the data to write.

    • callback : CallBackHandler

    Callback

    Async Callback Returning Parameters: HASH

      • status : STRING

        Write data status will either be success or failure.

      • message : STRING

        Returns the appropriate message.

    Returns

    Synchronous Return:

    • Void

    Platforms

    • Android

    Method Access:

    • Instance Method: This method can be accessed only via an instance object of this class:
      • myObject.write(STRING data)
    • Default Instance: This method can be accessed via the default instance object of this class.
      • EB.SerialComm.write(STRING data)

    Properties

    ParityBit

    Type

    STRING

    Description

    Parity bits are used for detecting error in the transmission.

    Values

    Possible Values (STRING):

    • Constant: EB.SerialComm.EVEN - String: EVEN Sets the parity bit so that the count of bits set is an even number
    • Constant: EB.SerialComm.MARK - String: MARK Leaves the parity bit set to 1.
    • Constant: EB.SerialComm.NONE - String: NONE No parity check occurs.
    • Constant: EB.SerialComm.ODD - String: ODD Sets the parity bit so that the count of bits set is an odd number.
    • Constant: EB.SerialComm.SPACE - String: SPACE Leaves the parity bit set to 0.

    Access

    • Instance: This property can be accessed via an instance object of this class: myObject.ParityBit
    • Default Instance: This property can be accessed via the default instance object of this class.
      • EB.SerialComm.ParityBit

    Platforms

    • Android

    baudRates

    Type

    STRING

    Description

    Specifies the baud at which the communications device operates.

    Values

    Possible Values (STRING):

    • Constant: EB.SerialComm.BR_300 - String: BR_300 Baud rate value is 300
    • Constant: EB.SerialComm.BR_1200 - String: BR_1200 Baud rate value is 1200
    • Constant: EB.SerialComm.BR_2400 - String: BR_2400 Baud rate value is 2400
    • Constant: EB.SerialComm.BR_4800 - String: BR_4800 Baud rate value is 4800
    • Constant: EB.SerialComm.BR_9600 - String: BR_9600 Baud rate value is 9600
    • Constant: EB.SerialComm.BR_14400 - String: BR_14400 Baud rate value is 14400
    • Constant: EB.SerialComm.BR_19200 - String: BR_19200 Baud rate value is 19200
    • Constant: EB.SerialComm.BR_28800 - String: BR_28800 Baud rate value is 28800
    • Constant: EB.SerialComm.BR_38400 - String: BR_38400 Baud rate value is 38400
    • Constant: EB.SerialComm.BR_57600 - String: BR_57600 Baud rate value is 57600
    • Constant: EB.SerialComm.BR_115200 - String: BR_115200 Baud rate value is 115200
    • Constant: EB.SerialComm.BR_230400 - String: BR_230400 Baud rate value is 230400
    • Constant: EB.SerialComm.BR_460800 - String: BR_460800 Baud rate value is 460800
    • Constant: EB.SerialComm.BR_921600 - String: BR_921600 Baud rate value is 921600

    Access

    • Instance: This property can be accessed via an instance object of this class: myObject.baudRates
    • Default Instance: This property can be accessed via the default instance object of this class.
      • EB.SerialComm.baudRates

    Platforms

    • Android

    dataBit

    Type

    STRING

    Description

    Specifies the number of data bits for each character.

    Values

    Possible Values (STRING):

    • Constant: EB.SerialComm.EIGHT - String: EIGHT Data bits per byte is 8
    • Constant: EB.SerialComm.SEVEN - String: SEVEN Data bits per byte is 7.

    Access

    • Instance: This property can be accessed via an instance object of this class: myObject.dataBit
    • Default Instance: This property can be accessed via the default instance object of this class.
      • EB.SerialComm.dataBit

    Platforms

    • Android

    flowControlMode

    Type

    STRING

    Description

    Specifies the flow control to be used.

    Values

    Possible Values (STRING):

    • Constant: EB.SerialComm.DSR_DTR - String: DSR_DTR Hardware flow control DSR/DTR
    • Constant: EB.SerialComm.NONE - String: NONE No flow control
    • Constant: EB.SerialComm.RTS_CTS - String: RTS_CTS Hardware flow control RTS/CTS
    • Constant: EB.SerialComm.XON_XOFF - String: XON_XOFF Software flow control

    Access

    • Instance: This property can be accessed via an instance object of this class: myObject.flowControlMode
    • Default Instance: This property can be accessed via the default instance object of this class.
      • EB.SerialComm.flowControlMode

    Platforms

    • Android

    friendlyName

    Type

    STRING Read Only

    Description

    Returns the friendly name associated with the Serial Port.

    Access

    • Instance: This property can be accessed via an instance object of this class: myObject.friendlyName
    • Default Instance: This property can be accessed via the default instance object of this class.
      • EB.SerialComm.friendlyName

    Platforms

    • Android

    stopBit

    Type

    STRING

    Description

    Specifies the number of stop bits to be used.

    Values

    Possible Values (STRING):

    • Constant: EB.SerialComm.ONE - String: ONE One stop bit is used.
    • Constant: EB.SerialComm.ONE_AND_HALF - String: ONE_AND_HALF 1.5 stop bits are used.
    • Constant: EB.SerialComm.TWO - String: TWO two stop bits are used.

    Access

    • Instance: This property can be accessed via an instance object of this class: myObject.stopBit
    • Default Instance: This property can be accessed via the default instance object of this class.
      • EB.SerialComm.stopBit

    Platforms

    • Android

    Examples

    Enable a Serial Comm port and read/write data

    This example shows how to enable/disable a device and to read and write data. Note that this example assumes that the ebapi-modules.js file is in the same folder as the HTML invoking it.

    
    
                                 <html>
                                  <head>
                                  <script type="text/javascript" src="ebapi-modules.js"></script> 
                                  <script>
                                  var SerialPort;
    
                                    function enumCallBack(params){
                                        alert("enumCallBack");
                                            if(params){     // Most of these methods have callbacks but null 'params' sent.
                                                //alert(params);
                                            }
    
    
                                    }
                                    function Enumerate()
                                    { 
                                    alert("enumerate");
                                      SerialPort = EB.SerialComm.enumerate(enumCallBack); 
                                        alert(SerialPort[0].getId());       
                                    }   
                                    function Enable()
                                    { 
                                        alert("Enable");
    
                                        EB.SerialComm.enable(enableCallback);
    
                                    } 
    
                                    function enableCallback(dat) {
                                    alert("enableCallback");
                                        document.getElementById("myDiv").innerHTML = "Enable:";
                                        document.getElementById("myDiv").innerHTML += "<li>Status:"+dat.status+"<br/><li>message:"+dat.message ;
                                    }
                                    function disableCallback(dat) {
                                        alert("disableCallback");
                                        document.getElementById("myDiv").innerHTML = "Disable:";
                                        document.getElementById("myDiv").innerHTML += "<li>Status:"+dat.status+"<br/><li>message:"+dat.message ;
                                    }   
                                    function Disable()
                                    { 
                                      alert("Disable");
                                      EB.SerialComm.disable(disableCallback);    
                                    }   
                                    function Read()
                                    { 
                                      alert("Read");
                                      EB.SerialComm.read("10000",readCallback);    
                                    } 
                                    function readCallback(dat) {
                                        alert("readCallback");
                                        document.getElementById("myDiv").innerHTML = "Read Data:<br/>";
                                        document.getElementById("myDiv").innerHTML += "<li>Status:"+dat.status+"<br/><li>Data:"+dat.data +"<br/><li>message:"+dat.message ;
                                    }
                                    function Write()
                                    { 
                                      alert("Write");
                                      //SerialPort[0].write("100abcd011");
                                      var writeData= document.getElementById("writeData").value;
                                      EB.SerialComm.write(writeData,writeCallback);    
                                    }
                                        function writeCallback(dat) {
                                        alert("writeCallback");
                                        document.getElementById("myDiv").innerHTML = "Write Data:<br/>";
                                        document.getElementById("myDiv").innerHTML += "<li>Status:"+dat.status+"<br/><li>message:"+dat.message ;
                                    }
                                    function SetConfig()
                                    { 
                                      alert("SetConfig");
                                      alert("Friendly name "+EB.SerialComm.friendlyName);
                                        EB.SerialComm.baudRates= EB.SerialComm.BR_9600;
                                        alert("baudRates "+EB.SerialComm.baudRates);
    
                                        EB.SerialComm.flowControlMode=EB.SerialComm.NONE;
                                        alert("flowControlMode "+EB.SerialComm.flowControlMode);
    
    
                                        EB.SerialComm.ParityBit=EB.SerialComm.NONE;
                                        alert("ParityBit "+EB.SerialComm.ParityBit);    
    
                                        EB.SerialComm.stopBit=EB.SerialComm.ONE;
                                        alert("stopBit "+EB.SerialComm.stopBit);    
    
                                        EB.SerialComm.dataBit=EB.SerialComm.EIGHT;
                                        alert("dataBit "+EB.SerialComm.dataBit);
                                    }
                                  </script>
                                  </head> 
                                  <body>
                                    <br><br> <div id="availableScanners">EnumScanners goes Here</div>
                                    <br><br> <div id=myJsID></div>
                                    <br><br> <div id="msg">Messages Go Here</div>
                                    <br><br> <input type='button' onClick="Enumerate()" value="Enumerate"/>
                                    <br><br> <input type='button' onClick="Enable()" value="Enable"/>
                                    <br><br> <input type="button" onclick="Disable()" value="Disable">
                                    <br><br> <input type="button" onclick="Read()" value="Read" />   
                                    <br><br> <input type="button" onclick="Write()" value="Write" />
                                    <input type="text" id="writeData" value="" />
                                    <br><br> <input type="button" onclick="SetConfig()" value="Set and Get Config" />
                                    <div id="myDiv"></div>
                                  </body>
                                  </html>