blob: c5e1c2bcb9de17815fd28b87e81dd7cd96572801 [file] [log] [blame]
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18package android.hardware;
19
20import android.app.PendingIntent;
21import android.content.Context;
22import android.os.Bundle;
23import android.os.ParcelFileDescriptor;
24import android.os.RemoteException;
25import android.os.SystemProperties;
26import android.util.Log;
27
28import java.io.IOException;
29import java.util.HashMap;
30
31/**
32 * @hide
33 */
34public class SerialManager {
35 private static final String TAG = "SerialManager";
36
37 private final Context mContext;
38 private final ISerialManager mService;
39
40 /**
41 * {@hide}
42 */
43 public SerialManager(Context context, ISerialManager service) {
44 mContext = context;
45 mService = service;
46 }
47
48 /**
49 * Returns a string array containing the names of available serial ports
50 *
51 * @return names of available serial ports
52 */
53 public String[] getSerialPorts() {
54 try {
55 return mService.getSerialPorts();
56 } catch (RemoteException e) {
57 Log.e(TAG, "RemoteException in getSerialPorts", e);
58 return null;
59 }
60 }
61
62 /**
63 * Opens and returns the {@link android.hardware.SerialPort} with the given name.
64 * The speed of the serial port must be one of:
65 * 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600,
66 * 19200, 38400, 57600, 115200, 230400, 460800, 500000, 576000, 921600, 1000000, 1152000,
67 * 1500000, 2000000, 2500000, 3000000, 3500000 or 4000000
68 *
69 * @param name of the serial port
70 * @param speed at which to open the serial port
71 * @return the serial port
72 */
73 public SerialPort openSerialPort(String name, int speed) throws IOException {
74 try {
75 ParcelFileDescriptor pfd = mService.openSerialPort(name);
76 if (pfd != null) {
77 SerialPort port = new SerialPort(name);
78 port.open(pfd, speed);
79 return port;
80 } else {
81 throw new IOException("Could not open serial port " + name);
82 }
83 } catch (RemoteException e) {
84 Log.e(TAG, "exception in UsbManager.openDevice", e);
85 }
86 return null;
87 }
88}