Gurux.Serial.Android

Gurux serial port component for Android.

License

License

GroupId

GroupId

org.gurux
ArtifactId

ArtifactId

gurux.serial.android
Last Version

Last Version

1.0.8
Release Date

Release Date

Type

Type

aar
Description

Description

Gurux.Serial.Android
Gurux serial port component for Android.
Project URL

Project URL

https://github.com/gurux/Gurux.Serial.Android.git
Source Code Management

Source Code Management

https://github.com/gurux/Gurux.Serial.Android.git

Download gurux.serial.android

How to add to project

<!-- https://jarcasting.com/artifacts/org.gurux/gurux.serial.android/ -->
<dependency>
    <groupId>org.gurux</groupId>
    <artifactId>gurux.serial.android</artifactId>
    <version>1.0.8</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/org.gurux/gurux.serial.android/
implementation 'org.gurux:gurux.serial.android:1.0.8'
// https://jarcasting.com/artifacts/org.gurux/gurux.serial.android/
implementation ("org.gurux:gurux.serial.android:1.0.8")
'org.gurux:gurux.serial.android:aar:1.0.8'
<dependency org="org.gurux" name="gurux.serial.android" rev="1.0.8">
  <artifact name="gurux.serial.android" type="aar" />
</dependency>
@Grapes(
@Grab(group='org.gurux', module='gurux.serial.android', version='1.0.8')
)
libraryDependencies += "org.gurux" % "gurux.serial.android" % "1.0.8"
[org.gurux/gurux.serial.android "1.0.8"]

Dependencies

compile (2)

Group / Artifact Type Version
com.android.support » appcompat-v7 jar 25.0.1
org.gurux : Gurux.Common.Android jar 1.0.4

Project Modules

There are no modules declared in this project.

See An Gurux for an overview.

With gurux.serial.android component you can send data easily syncronously or asyncronously using serial port connection in Android devices.

Join the Gurux Community or follow @Gurux for project updates.

Open Source GXSerial media component, made by Gurux Ltd, is a part of GXMedias set of media components, which programming interfaces help you implement communication by chosen connection type. Our media components also support the following connection types: network.

For more info check out Gurux.

With gurux.serial component you can send data easily syncronously or asyncronously.

We are updating documentation on Gurux web page.

If you have problems you can ask your questions in Gurux Forum.

You can get source codes from http://www.github.com/gurux or if you use gradle add this to your build.gradle-file:

compile 'org.gurux:gurux.serial.android:1.0.1'

Simple example

Before use you must set following settings:

  • PortName
  • BaudRate
  • DataBits
  • Parity
  • StopBits

It is also good to add listener and start to listen following events.

  • onError
  • onReceived
  • onMediaStateChange
  • onTrace
  • onPropertyChanged
GXSerial cl = new GXSerial(this);
cl.setPortName(gurux.serial.GXSerial.getPortNames(this)[0]);
cl.setBaudRate(9600);
cl.setDataBits(8);
cl.setParity(Parity.ODD);
cl.setStopBits(StopBits.ONE);
cl.open();

Data is send with send command:

cl.Send("Hello World!");

In default mode received data is coming as asynchronously from OnReceived event.

Event listener is adding class that you want to use to listen media events and derive class from IGXMediaListener.

*/
 Media listener.
*/
public class MainActivity extends AppCompatActivity implements IGXMediaListener {
{
	/** 
    Represents the method that will handle the error event of a Gurux component.

    @param sender The source of the event.
    @param ex An Exception object that contains the event data.
    */
    @Override
    void onError(Object sender, RuntimeException ex)
    {
	//Show occured error.
    }

    /** 
    Media component sends received data through this method.

    @param sender The source of the event.
    @param e Event arguments.
    */
    @Override
    void onReceived(Object sender, ReceiveEventArgs e)
    {
	//Handle received asyncronous data here.
    }

    /** 
    Media component sends notification, when its state changes.

    @param sender The source of the event.    
    @param e Event arguments.
    */
    @Override
    void onMediaStateChange(Object sender, MediaStateEventArgs e)
    {
	//Media is open or closed.
    }

    /** 
    Called when the Media is sending or receiving data.

    @param sender
    @param e
    @see IGXMedia.Trace Traceseealso>
    */
    @Override
    void onTrace(Object sender, TraceEventArgs e)
    {
	//Send and received data is shown here.
    }
    
    /** 
    Represents the method that will handle the System.ComponentModel.INotifyPropertyChanged.PropertyChanged
    event raised when a property is changed on a component.
    
    @param sender The source of the event.
    @param sender e A System.ComponentModel.PropertyChangedEventArgs that contains the event data.
    */
    @Override
    void onPropertyChanged(Object sender, PropertyChangedEventArgs e)
    {
	//Example port name is change.
    }      
}

Listener is registered calling addListener method.

cl.addListener(this);

Data can be also send as syncronous if needed.

synchronized (cl.getSynchronous())
{
    String reply = "";    
    ReceiveParameters<byte[]> p = new ReceiveParameters<byte[]>(byte[].class);    
    //End of Packet.
    p.setEop('\n'); 
    //How long reply is waited.   
    p.setWaitTime(1000);          
    cl.send("Hello World!", null);
    if (!cl.receive(p))
    {
        throw new RuntimeException("Failed to receive response..");
    }
}
org.gurux

Gurux Ltd

Versions

Version
1.0.8
1.0.7
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1