⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainclass.java

📁 CardBus代码驱动等有用资料
💻 JAVA
字号:
/** * <p>Title: CardBus I/O Sample Application</p> * <p>Description: CardBus I/O Sample Application</p> * <p>Copyright: Copyright (c) 2005</p> * <p>Company: Mobile Satellite Services</p> * @author Poornima Sarvdevabhatla * @version 1.0 */import java.lang.RuntimeException;import cardbus.*;public class MainClass {  public static void main(String[] args) {    CardBus cardbus = new CardBus();    try {      cardbus.connect(0);    } catch (Exception e) {      e.printStackTrace();    }    int status = 0;/*       byte[] valuesToBeWritten2 = new byte[]{//0x32};         (byte) 0x40, //@         (byte) 0x31,//1         (byte) 0x31,//1         (byte) 0x31,//1         (byte) 0x4D,//M         (byte) 0x46,//F         (byte) 0x57,//W         (byte) 0x0D,//CR         (byte) 0x0A};//LF,*/       byte[] valuesToBeWritten = new byte[]{//0x32};         (byte) 0x40, //@         (byte) 0x30,//0         (byte) 0x30,//0         (byte) 0x30,//0x31,//2         (byte) 0x47,//G         (byte) 0x4D,//M         (byte) 0x49,//I         (byte) 0x0D,//CR         (byte) 0x0A};//LF,    int address = 0;    int noOfBytesToWrite = 9;    status = cardbus.writeIoFixAddr8bit(address, noOfBytesToWrite, valuesToBeWritten);    if (status > 0) {      System.out.println("Successfully wrote " + status + " bytes.");      System.out.println("The following values were written:");      for (int i = 0; i < status; i = i + 1) {        System.out.println("Address " + (address) +          ": Value written (dec): " + valuesToBeWritten[i] +            "   (hex): " + zeroPadNumber(Integer.toHexString((int)valuesToBeWritten[i]).toUpperCase(),2));      }    }    // Wait for 10 milli-seconds for the UC to answer    try {      Thread.sleep(1000);    } catch (Exception e) {    }    byte[] readRegisterValue = new byte[100];    status = cardbus.readIoFixAddr8bit(0, 100, readRegisterValue);    System.out.println(status);    if (status > 0) {      for (int i = 0; i < status; i = i + 1) {        System.out.println("Read value #" + (i) +" (dec): " +          ((int )readRegisterValue[i]) + " (hex): " +            (Integer.toHexString((int)readRegisterValue[i])).toUpperCase());      }    }    byte[] valuesToBeWritten1 = new byte[]{//0x32};         (byte) 0x40, //@         (byte) 0x30,//0         (byte) 0x30,//0         (byte) 0x30,//0x31,//2         (byte) 0x47,//G         (byte) 0x53,//S         (byte) 0x4E,//N         (byte) 0x0D,//CR         (byte) 0x0A};//LF,    status = cardbus.writeIoFixAddr8bit(address, noOfBytesToWrite, valuesToBeWritten1);    if (status > 0) {      System.out.println("Successfully wrote " + status + " bytes.");      System.out.println("The following values were written:");      for (int i = 0; i < status; i = i + 1) {        System.out.println("Address " + (address) +          ": Value written (dec): " + valuesToBeWritten1[i] +            "   (hex): " + zeroPadNumber(Integer.toHexString((int)valuesToBeWritten1[i]).toUpperCase(),2));      }    }    // Wait for 10 milli-seconds for the UC to answer    try {      Thread.sleep(1000);    } catch (Exception e) {    }    byte[] readRegisterValue1 = new byte[100];    status = cardbus.readIoFixAddr8bit(0, 100, readRegisterValue1);    System.out.println(status);    if (status > 0) {      for (int i = 0; i < status; i = i + 1) {        System.out.println("Read value #" + (i) +" (dec): " +          ((int )readRegisterValue1[i]) + " (hex): " +            (Integer.toHexString((int)readRegisterValue1[i])).toUpperCase());      }    }    cardbus.closeConnections();    System.out.println("Disposed a handle");  }/**************************************************************************************************************************************************************/  /** Zero-pads a <code>String[]</code>.   *   * @param StringToBePadded  the <code>String[]</code> to be zero-padded   * @param totalNoOfDigits  Total number of characters the return value should   * have. Must be greater or equal to the number of characters in the   * <code>StringToBePadded</code> input parameter.   * @return a zero-padded <code>String[]</code>   */  public static String zeroPadNumber(String StringToBePadded,                                              int totalNoOfDigits){    String returnString = StringToBePadded;    if (StringToBePadded.length() > totalNoOfDigits) {      return StringToBePadded.substring(0,totalNoOfDigits);    }    for (int i = 0; i < totalNoOfDigits-StringToBePadded.length() ; i = i + 1) {      returnString = "0" + returnString;    }    return returnString;  }/**************************************************************************************************************************************************************/}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -