All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.serialpundit.serial.vendor.SerialComSLabsCP210xRuntime Maven / Gradle / Ivy

The newest version!
/*
 * This file is part of SerialPundit.
 * 
 * Copyright (C) 2014-2016, Rishi Gupta. All rights reserved.
 *
 * The SerialPundit is DUAL LICENSED. It is made available under the terms of the GNU Affero 
 * General Public License (AGPL) v3.0 for non-commercial use and under the terms of a commercial 
 * license for commercial use of this software. 
 * 
 * The SerialPundit is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */

package com.serialpundit.serial.vendor;

import java.io.File;
import java.io.FileNotFoundException;

import com.serialpundit.core.SerialComSystemProperty;
import com.serialpundit.core.SerialComException;
import com.serialpundit.serial.internal.SerialComCP210xRuntimeJNIBridge;

/**
 * 

Silicon labs provides libraries to communicate with their USB-UART devices. More information can * be found here : https://www.silabs.com/products/mcu/Pages/USBtoUARTBridgeVCPDrivers.aspx

* *
    *
  • The data types used in java layer may be bigger in size than the native layer. For example; if native * function returns 16 bit signed integer, than java method will return 32 bit integer. This is done to make * sure that no data loss occur. This library take care of sign and their applicability internally.
  • * *
  • Developers are requested to check with vendor library documentation if a particular function is supported * for desired platform or not and also how does a particular API will behave. Also consider paying attention to * valid values and range when passing arguments to a method.

  • * *
  • The application note for CP210XRuntime library is here : * https://www.silabs.com/Support%20Documents/TechnicalDocs/an223.pdf
  • * *
  • SerialPundit version 1.0.4 is linked to v3.4.0.0 version of CP210xRuntime library (CP210xRuntime.dll).

  • *
* * @author Rishi Gupta */ public final class SerialComSLabsCP210xRuntime extends SerialComVendorLib { /**

Bit mask to represent mask and latch definition for GPIO0 in CP210X terminology.

*/ public static final int CP210x_GPIO_0 = 0x0001; /**

Bit mask to represent mask and latch definition for GPIO1 in CP210X terminology.

*/ public static final int CP210x_GPIO_1 = 0x0002; /**

Bit mask to represent mask and latch definition for GPIO2 in CP210X terminology.

*/ public static final int CP210x_GPIO_2 = 0x0004; /**

Bit mask to represent mask and latch definition for GPIO3 in CP210X terminology.

*/ public static final int CP210x_GPIO_3 = 0x0008; /**

Bit mask to represent mask and latch definition for GPIO4 in CP210X terminology.

*/ public static final int CP210x_GPIO_4 = 0x0010; /**

Bit mask to represent mask and latch definition for GPIO5 in CP210X terminology.

*/ public static final int CP210x_GPIO_5 = 0x0020; /**

Bit mask to represent mask and latch definition for GPIO6 in CP210X terminology.

*/ public static final int CP210x_GPIO_6 = 0x0040; /**

Bit mask to represent mask and latch definition for GPIO7 in CP210X terminology.

*/ public static final int CP210x_GPIO_7 = 0x0080; /**

Bit mask to represent mask and latch definition for GPIO8 in CP210X terminology.

*/ public static final int CP210x_GPIO_8 = 0x0100; /**

Bit mask to represent mask and latch definition for GPIO9 in CP210X terminology.

*/ public static final int CP210x_GPIO_9 = 0x0200; /**

Bit mask to represent mask and latch definition for GPIO10 in CP210X terminology.

*/ public static final int CP210x_GPIO_10 = 0x0400; /**

Bit mask to represent mask and latch definition for GPIO11 in CP210X terminology.

*/ public static final int CP210x_GPIO_11 = 0x0800; /**

Bit mask to represent mask and latch definition for GPIO12 in CP210X terminology.

*/ public static final int CP210x_GPIO_12 = 0x1000; /**

Bit mask to represent mask and latch definition for GPIO13 in CP210X terminology.

*/ public static final int CP210x_GPIO_13 = 0x2000; /**

Bit mask to represent mask and latch definition for GPIO14 in CP210X terminology.

*/ public static final int CP210x_GPIO_14 = 0x4000; /**

Bit mask to represent mask and latch definition for GPIO15 in CP210X terminology.

*/ public static final int CP210x_GPIO_15 = 0x8000; private final SerialComCP210xRuntimeJNIBridge mSerialComCP210xRuntimeJNIBridge; /** *

Allocates a new SerialComSLabsCP210xRuntime object and extract and load shared libraries as * required.

* * @param libDirectory directory in which native library will be extracted and vendor library will * be found. * @param vlibName name of vendor library to load and link. * @param cpuArch architecture of CPU this library is running on. * @param osType operating system this library is running on. * @param serialComSystemProperty instance of SerialComSystemProperty to get required java properties. * @throws SerialComException if java system properties can not be is null, if any file system related issue occurs. * @throws SecurityException if java system properties can not be accessed or required files can not be accessed. * @throws UnsatisfiedLinkError if loading/linking shared library fails. * @throws FileNotFoundException if the vendor library file is not found. */ public SerialComSLabsCP210xRuntime(File libDirectory, String vlibName, int cpuArch, int osType, SerialComSystemProperty serialComSystemProperty) throws SerialComException { mSerialComCP210xRuntimeJNIBridge = new SerialComCP210xRuntimeJNIBridge(); SerialComCP210xRuntimeJNIBridge.loadNativeLibrary(libDirectory, vlibName, cpuArch, osType, serialComSystemProperty); } /** *

Executes CP210xRT_ReadLatch function of CP210XRuntime library.

* *

Gets the current port latch value from the device.

* * @param handle handle of the opened COM port. * @return bit mask of constant(s) CP210x_GPIO_XX. * @throws SerialComException if an I/O error occurs. */ public long readLatch(final long handle) throws SerialComException { long ret = mSerialComCP210xRuntimeJNIBridge.readLatch(handle); if(ret < 0) { throw new SerialComException("Could not read the port latch value for given device. Please retry !"); } return ret; } /** *

Executes CP210xRT_WriteLatch function of CP210XRuntime library.

* *

Sets the current port latch value for the device.

* * @param handle handle of the opened COM port. * @param mask determines which pins to change [Change = 1, Leave = 0]. * @param latchValue bit mask value to write to GPIO latch [Logic High = 1, Logic Low = 0]. * @return true if value gets set successfully. * @throws SerialComException if an I/O error occurs. */ public boolean writeLatch(final long handle, long mask, long latchValue) throws SerialComException { int ret = mSerialComCP210xRuntimeJNIBridge.writeLatch(handle, mask, latchValue); if(ret < 0) { throw new SerialComException("Could not write the given latch value on the given device. Please retry !"); } return true; } /** *

Executes CP210xRT_GetPartNumber function of CP210XRuntime library.

* *

Gets the part number of the current device.

* * @param handle handle of the opened COM port. * @return part number string of the current device. * @throws SerialComException if an I/O error occurs. */ public String getPartNumber(final long handle) throws SerialComException { String ret = mSerialComCP210xRuntimeJNIBridge.getPartNumber(handle); if(ret == null) { throw new SerialComException("Could not get the part number of the current device. Please retry !"); } return ret; } /** *

Executes CP210xRT_GetDeviceProductString function of CP210XRuntime library.

* *

Gets the product string in the current device.

* * @param handle handle of the opened COM port. * @return product string. * @throws SerialComException if an I/O error occurs. */ public String getDeviceProductString(final long handle) throws SerialComException { String ret = mSerialComCP210xRuntimeJNIBridge.getDeviceProductString(handle); if(ret == null) { throw new SerialComException("Could not get the product string of the current device. Please retry !"); } return ret; } /** *

Executes CP210xRT_GetDeviceSerialNumber function of CP210XRuntime library.

* *

Gets the serial number in the current device.

* * @param handle handle of the opened COM port. * @return serial number string. * @throws SerialComException if an I/O error occurs. */ public String getDeviceSerialNumber(final long handle) throws SerialComException { String ret = mSerialComCP210xRuntimeJNIBridge.getDeviceSerialNumber(handle); if(ret == null) { throw new SerialComException("Could not get the serial number of the current device. Please retry !"); } return ret; } /** *

Executes CP210xRT_GetDeviceInterfaceString function of CP210XRuntime library.

* *

Gets the interface string of the current device.

* * @param handle handle of the opened COM port. * @return interface string. * @throws SerialComException if an I/O error occurs. */ public String getDeviceInterfaceString(final long handle) throws SerialComException { String ret = mSerialComCP210xRuntimeJNIBridge.getDeviceInterfaceString(handle); if(ret == null) { throw new SerialComException("Could not get the interface string of the current device. Please retry !"); } return ret; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy