本文整理汇总了Java中ioio.lib.api.exception.ConnectionLostException类的典型用法代码示例。如果您正苦于以下问题:Java ConnectionLostException类的具体用法?Java ConnectionLostException怎么用?Java ConnectionLostException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConnectionLostException类属于ioio.lib.api.exception包,在下文中一共展示了ConnectionLostException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createIOIOLooper
import ioio.lib.api.exception.ConnectionLostException; //导入依赖的package包/类
@Override
protected IOIOLooper createIOIOLooper() {
return new BaseIOIOLooper(){
Uart uart;
OutputStream ostream;
@Override
protected void setup() throws ConnectionLostException, InterruptedException {
Thread.sleep(5000);
//led_ = ioio_.openDigitalOutput(0, true);
uart = ioio_.openUart(35,34,57600, Uart.Parity.NONE, Uart.StopBits.ONE);
ostream = uart.getOutputStream();
}
@Override
public void loop() throws ConnectionLostException, InterruptedException {
try {
ostream.write("sending data".getBytes());
Thread.sleep(100);
}
catch (IOException ex) {
//showToast("CommunicationThread: "+ ex.getMessage());
Toast.makeText(getApplicationContext(), ex.getMessage(), Toast.LENGTH_LONG).show();
}
}
};
}
示例2: loop
import ioio.lib.api.exception.ConnectionLostException; //导入依赖的package包/类
@Override
public void loop() throws ConnectionLostException, InterruptedException {
// Do all our writing here based on whether the state changed in the app
// between the last state and the next.
//out.write();
Log.d(TAG, "Inside run loop. Current state: " + Integer.toString(lightEnabled));
if(lightEnabled > -1) {
byte buffer[] = new byte[1];
buffer[0] = (byte) Character.forDigit(lightEnabled, 10);
//Apparently one of the exceptions above extends IOException
try {
Log.d(TAG, "Writing byte to device");
out.write(buffer);
} catch (IOException e) {
Log.e(TAG, "EL Command Lost");
}
led.write(true);
Thread.sleep(1000);
led.write(false);
}
}
示例3: writeReadAsync
import ioio.lib.api.exception.ConnectionLostException; //导入依赖的package包/类
@Override
public Result writeReadAsync(int address, boolean tenBitAddr,
byte[] writeData, int writeSize, byte[] readData, int readSize)
throws ConnectionLostException {
checkState();
TwiResult result = new TwiResult(readData);
OutgoingPacket p = new OutgoingPacket();
p.writeSize_ = writeSize;
p.writeData_ = writeData;
p.tenBitAddr_ = tenBitAddr;
p.readSize_ = readSize;
p.addr_ = address;
synchronized (this) {
pendingRequests_.add(result);
try {
outgoing_.write(p);
} catch (IOException e) {
Log.e("SpiMasterImpl", "Exception caught", e);
}
}
return result;
}
示例4: bufferPull
import ioio.lib.api.exception.ConnectionLostException; //导入依赖的package包/类
private synchronized short bufferPull() throws InterruptedException,
ConnectionLostException {
if (buffer_ == null) {
throw new IllegalStateException(
"Need to call setBuffer() before reading buffered values.");
}
while (bufferSize_ == 0 && state_ == State.OPEN) {
wait();
}
checkState();
short result = buffer_[bufferReadCursor_++];
if (bufferReadCursor_ == bufferCapacity_) {
bufferReadCursor_ = 0;
}
--bufferSize_;
return result;
}
示例5: setPulseWidthInClocks
import ioio.lib.api.exception.ConnectionLostException; //导入依赖的package包/类
synchronized private void setPulseWidthInClocks(float p)
throws ConnectionLostException {
checkState();
if (p > period_) {
p = period_;
}
int pw;
int fraction;
p -= 1; // period parameter is one less than the actual period length
// yes, there is 0 and then 2 (no 1) - this is not a bug, that
// is how the hardware PWM module works.
if (p < 1) {
pw = 0;
fraction = 0;
} else {
pw = (int) p;
fraction = ((int) p * 4) & 0x03;
}
try {
ioio_.protocol_.setPwmDutyCycle(pwmNum_, pw, fraction);
} catch (IOException e) {
throw new ConnectionLostException(e);
}
}
示例6: getImplVersion
import ioio.lib.api.exception.ConnectionLostException; //导入依赖的package包/类
@Override
public String getImplVersion(VersionType v) throws ConnectionLostException {
if (state_ == State.INIT) {
throw new IllegalStateException(
"Connection has not yet been established");
}
switch (v) {
case HARDWARE_VER:
return incomingState_.hardwareId_;
case BOOTLOADER_VER:
return incomingState_.bootloaderId_;
case APP_FIRMWARE_VER:
return incomingState_.firmwareId_;
case IOIOLIB_VER:
return "IOIO0326";
}
return null;
}
示例7: openIcspMaster
import ioio.lib.api.exception.ConnectionLostException; //导入依赖的package包/类
@Override
synchronized public IcspMaster openIcspMaster()
throws ConnectionLostException {
checkState();
checkIcspFree();
final int[] icspPins = hardware_.icspPins();
checkPinFree(icspPins[0]);
checkPinFree(icspPins[1]);
checkPinFree(icspPins[2]);
openPins_[icspPins[0]] = true;
openPins_[icspPins[1]] = true;
openPins_[icspPins[2]] = true;
openIcsp_ = true;
IcspMasterImpl icsp = new IcspMasterImpl(this);
addDisconnectListener(icsp);
incomingState_.addIcspListener(icsp);
try {
protocol_.icspOpen();
} catch (IOException e) {
icsp.close();
throw new ConnectionLostException(e);
}
return icsp;
}
示例8: openDigitalInput
import ioio.lib.api.exception.ConnectionLostException; //导入依赖的package包/类
@Override
synchronized public DigitalInput openDigitalInput(DigitalInput.Spec spec)
throws ConnectionLostException {
checkState();
hardware_.checkValidPin(spec.pin);
checkPinFree(spec.pin);
DigitalInputImpl result = new DigitalInputImpl(this, spec.pin);
addDisconnectListener(result);
openPins_[spec.pin] = true;
incomingState_.addInputPinListener(spec.pin, result);
try {
protocol_.setPinDigitalIn(spec.pin, spec.mode);
protocol_.setChangeNotify(spec.pin, true);
} catch (IOException e) {
result.close();
throw new ConnectionLostException(e);
}
return result;
}
示例9: openDigitalOutput
import ioio.lib.api.exception.ConnectionLostException; //导入依赖的package包/类
@Override
synchronized public DigitalOutput openDigitalOutput(
DigitalOutput.Spec spec, boolean startValue)
throws ConnectionLostException {
checkState();
hardware_.checkValidPin(spec.pin);
checkPinFree(spec.pin);
DigitalOutputImpl result = new DigitalOutputImpl(this, spec.pin, startValue);
addDisconnectListener(result);
openPins_[spec.pin] = true;
try {
protocol_.setPinDigitalOut(spec.pin, startValue, spec.mode);
} catch (IOException e) {
result.close();
throw new ConnectionLostException(e);
}
return result;
}
示例10: openAnalogInput
import ioio.lib.api.exception.ConnectionLostException; //导入依赖的package包/类
@Override
synchronized public AnalogInput openAnalogInput(int pin)
throws ConnectionLostException {
checkState();
hardware_.checkSupportsAnalogInput(pin);
checkPinFree(pin);
AnalogInputImpl result = new AnalogInputImpl(this, pin);
addDisconnectListener(result);
openPins_[pin] = true;
incomingState_.addInputPinListener(pin, result);
try {
protocol_.setPinAnalogIn(pin);
protocol_.setAnalogInSampling(pin, true);
} catch (IOException e) {
result.close();
throw new ConnectionLostException(e);
}
return result;
}
示例11: openTwiMaster
import ioio.lib.api.exception.ConnectionLostException; //导入依赖的package包/类
@Override
synchronized public TwiMaster openTwiMaster(int twiNum, Rate rate,
boolean smbus) throws ConnectionLostException {
checkState();
checkTwiFree(twiNum);
final int[][] twiPins = hardware_.twiPins();
checkPinFree(twiPins[twiNum][0]);
checkPinFree(twiPins[twiNum][1]);
openPins_[twiPins[twiNum][0]] = true;
openPins_[twiPins[twiNum][1]] = true;
openTwi_[twiNum] = true;
TwiMasterImpl twi = new TwiMasterImpl(this, twiNum);
addDisconnectListener(twi);
incomingState_.addTwiListener(twiNum, twi);
try {
protocol_.i2cConfigureMaster(twiNum, rate, smbus);
} catch (IOException e) {
twi.close();
throw new ConnectionLostException(e);
}
return twi;
}
示例12: loop
import ioio.lib.api.exception.ConnectionLostException; //导入依赖的package包/类
@Override
public void loop() throws ConnectionLostException
{
JSONObject jsonObject = new JSONObject();
try {
// ask rover for sensor and other data values
JSONObject commandJson = new JSONObject();
commandJson.put("cmd", ROVER_COMM_DA);
ostream.write((commandJson.toString() + "\n").getBytes());
// wait a few seconds before reading response.
Thread.sleep(2000);
// read the data sent
byte[] roverData = new byte[1024];
istream.read(roverData);
String dataStr = new String(roverData);
Log.d("Data from rover", dataStr);
// sleep again
Thread.sleep(500);
}
catch(Exception ex){
Log.e("ERROR CONTROL APP", ex.getMessage(), ex);
}
}
示例13: createIOIOLooper
import ioio.lib.api.exception.ConnectionLostException; //导入依赖的package包/类
@Override
protected IOIOLooper createIOIOLooper() {
MLog.d(TAG, "createIOIOLooper");
return new BaseIOIOLooper() {
@Override
protected void setup() throws ConnectionLostException, InterruptedException {
MLog.d(TAG, "Setup in IOIOLooper");
callback_.onConnect(ioio_);
callback_.setup();
// abort_ = (resp != null && resp != true);
}
@Override
public void loop() throws ConnectionLostException, InterruptedException {
if (abort_) {
this.disconnected();
} else {
callback_.loop();
// abort_ = (resp != null && resp != true);
Thread.sleep(100);
}
}
@Override
public void disconnected() {
super.disconnected();
MLog.d("IOIOBoardService", "-----> Disconnecting <-----");
ioio_.disconnect();
}
};
}
示例14: setup
import ioio.lib.api.exception.ConnectionLostException; //导入依赖的package包/类
@Override
public void setup() throws ConnectionLostException {
uart = ioio_.openUart(RX_PIN, TX_PIN, 9600, Uart.Parity.NONE, Uart.StopBits.ONE);
out = uart.getOutputStream();
in = uart.getInputStream();
led = ioio_.openDigitalOutput(0, true);
toggleUi(true);
toast("IOIO Connected");
}
示例15: write
import ioio.lib.api.exception.ConnectionLostException; //导入依赖的package包/类
@Override
synchronized public void write(boolean val) throws ConnectionLostException {
checkState();
if (val != value_) {
try {
ioio_.protocol_.setDigitalOutLevel(pinNum_, val);
value_ = val;
} catch (IOException e) {
throw new ConnectionLostException(e);
}
}
}