Package ptolemy.data

Examples of ptolemy.data.UnsignedByteToken


                    port.send(0, new DoubleToken(((Double) ret).doubleValue()));
                } else if (typ.equals("int")) {
                    port.send(0, new IntToken(((Integer) ret).intValue()));
                } else if (typ.equals("char")) {
                    port.send(0,
                            new UnsignedByteToken(((Byte) ret).byteValue()));
                } else {
                    System.out.println("The return type is not convertible "
                            + "with Ptolemy II types.");
                }
            }
            //if the argument is output
            else if ((port != null)
                    && port.isOutput()
                    && (port.getName() != null)
                    && (getArgumentReturn() != null)
                    && !(port.getName().equals(this.getArgumentReturn()
                            .getName()))) {
                String typ = "";
                Field field = null;

                try {
                    field = _class.getDeclaredField("_" + port.getName());
                    typ = field.getType().toString();
                } catch (NoSuchFieldException ex) {
                    try {
                        field = _class.getDeclaredField("_"
                                + port.getName().substring(0,
                                        port.getName().length() - 3));
                        typ = field.getType().toString();
                    } catch (Throwable throwable) {
                        try {
                            throw new IllegalActionException(this, throwable,
                                    "No '+" + port.getName() + "' field !");
                        } catch (Throwable throwable2) {
                            getDirector().stop();
                        }
                    }
                }

                if (field == null) {
                    throw new InternalErrorException("Field '" + port.getName()
                            + "' in '" + _class + "' is null?");
                } else {
                    if (typ.equals("boolean")) {
                        try {
                            port.send(0,
                                    new BooleanToken(field.getBoolean(obj)));
                        } catch (IllegalAccessException ex) {
                            throw new IllegalActionException(this, ex, "Type '"
                                    + typ + "' is not castable");
                        }
                    } else if (typ.equals("double")) {
                        try {
                            port.send(0, new DoubleToken(field.getDouble(obj)));
                        } catch (IllegalAccessException ex) {
                            throw new IllegalActionException(this, ex, "Type '"
                                    + typ + "' is not castable");
                        }
                    } else if (typ.equals("int")) {
                        try {
                            port.send(0, new IntToken(field.getInt(obj)));
                        } catch (IllegalAccessException ex) {
                            throw new IllegalActionException(this, ex, "Type '"
                                    + typ + "' is not castable");
                        }
                    } else if (typ.equals("char")) {
                        try {
                            port.send(0, new UnsignedByteToken(field
                                    .getChar(obj)));
                        } catch (IllegalAccessException ex) {
                            throw new IllegalActionException(this, ex, "Type '"
                                    + typ + "' is not castable");
                        }
View Full Code Here


            if (!useDefaultOutput) {
                Token[] dataTokens = new Token[bytesAvailable];

                for (int j = 0; j < bytesAvailable; j++) {
                    dataTokens[j] = new UnsignedByteToken(dataBytes[j]);
                }

                _outputToken = new ArrayToken(BaseType.UNSIGNED_BYTE,
                        dataTokens);
            }
View Full Code Here

            ArrayToken dataArrayToken = (ArrayToken) data.get(0);

            byte[] dataBytes = new byte[dataArrayToken.length()];

            for (int j = 0; j < dataArrayToken.length(); j++) {
                UnsignedByteToken token = (UnsignedByteToken) dataArrayToken
                        .getElement(j);
                dataBytes[j] = token.byteValue();
            }

            DatagramPacket packet = new DatagramPacket(dataBytes,
                    dataBytes.length, _address, _remoteSocketNumber);
View Full Code Here

                        jjtn003._ptToken = new ShortToken(Integer.parseInt(x,
                                radix));
                    } else if (mustBeUnsignedByte) {
                        // If the size was specified as unsignedbyte,
                        // then create an unsigned byte, truncating if necessary.
                        jjtn003._ptToken = new UnsignedByteToken(Integer
                                .parseInt(x, radix));
                    } else {
                        // Try to infer the size.  Inferred sizes are at least
                        // integer.
                        try {
View Full Code Here

                        _debug("Writing bytes from the input port to the serial port: "
                                + inputLength);
                    }

                    for (int j = 0; j < inputLength; j++) {
                        UnsignedByteToken dataToken = (UnsignedByteToken) dataArrayToken
                                .getElement(j);
                        out.write(dataToken.byteValue());
                    }

                    out.flush();
                }

                InputStream in = _serialPort.getInputStream();
                int bytesAvailable = in.available();

                if (_debugging) {
                    _debug("Number of input bytes available on the serial port: "
                            + bytesAvailable);
                }

                // NOTE: This needs _minimumOutputSize to be at least 1.
                // FIXME: stopFire() is called if the serial port receives
                // a byte while we are in the wait() (by the serialEvent()
                // method, through fireAtCurrentTime(), I think). But we
                // don't want to exit the loop if stopFire() is called for
                // this reason.  We want to continue waiting until there
                // is enough input data.  But this means that if stopFire()
                // is called for some other reason, then this actor will
                // ignore the call.  This is not quite right, and could
                // make the actor fail in domains where stopFire() is essential
                // (are there any?).
                while ((bytesAvailable < _minimumOutputSize) && _blocking
                        && !_stopRequested /* && !_stopFireRequested */) {
                    try {
                        if (_debugging) {
                            _debug("Blocking waiting for minimum number of bytes: "
                                    + _minimumOutputSize);
                        }

                        PortListener.class.wait();
                        bytesAvailable = in.available();

                        if (_debugging) {
                            _debug("Number of input bytes available on the serial port: "
                                    + bytesAvailable);
                        }
                    } catch (InterruptedException ex) {
                        throw new IllegalActionException(this,
                                "Thread interrupted waiting for serial port data.");
                    }
                }
                if (_debugging) {
                    _debug("Number of input bytes available on the serial port: "
                            + bytesAvailable);
                }
                if (bytesAvailable >= _minimumOutputSize) {
                    // Read only if at least desired amount of data is present.
                    if (_discardOldData
                            && (bytesAvailable > _maximumOutputSize)) {
                        // Skip excess bytes.
                        int excess = bytesAvailable - _maximumOutputSize;

                        if (_debugging) {
                            _debug("Discarding input bytes: " + excess);
                        }

                        bytesAvailable -= (int) in.skip(excess);
                    }

                    int outputSize = bytesAvailable;

                    if (outputSize > _maximumOutputSize) {
                        outputSize = _maximumOutputSize;
                    }

                    byte[] dataBytes = new byte[outputSize];

                    if (_debugging) {
                        _debug("Reading bytes from the serial port: "
                                + outputSize);
                    }

                    int bytesRead = in.read(dataBytes, 0, outputSize);
                    // FindBugs asks us to check the return value of in.read().
                    if (bytesRead != outputSize) {
                        throw new IllegalActionException(this, "Read only "
                                + bytesRead + " bytes, expecting" + outputSize
                                + " bytes.");
                    }

                    Token[] dataTokens = new Token[outputSize];

                    for (int j = 0; j < outputSize; j++) {
                        dataTokens[j] = new UnsignedByteToken(dataBytes[j]);
                    }

                    if (_debugging) {
                        _debug("Producing byte array on the output port.");
                    }
View Full Code Here

        } else if (object instanceof Byte) {
            // Note: This is technically not quite right, because of
            // the sign involved...  In lieu of a signed byte token,
            // we assume that methods that return byte should be
            // interpreted unsigned.
            returnValue = new UnsignedByteToken(((Byte) object).byteValue());
        } else if (object instanceof Short) {
            returnValue = new ShortToken(((Short) object).shortValue());
        } else if (object instanceof Integer) {
            returnValue = new IntToken(((Integer) object).intValue());
        } else if (object instanceof Long) {
View Full Code Here

        int bytesAvailable = dataBytes.length;
        Token[] dataTokens = new Token[bytesAvailable];

        for (int j = 0; j < bytesAvailable; j++) {
            dataTokens[j] = new UnsignedByteToken(dataBytes[j]);
        }

        output.send(0, new ArrayToken(BaseType.UNSIGNED_BYTE, dataTokens));
    }
View Full Code Here

        super.fire();
        ArrayToken dataArrayToken = (ArrayToken) input.get(0);
        byte[] dataBytes = new byte[dataArrayToken.length()];

        for (int j = 0; j < dataArrayToken.length(); j++) {
            UnsignedByteToken dataToken = (UnsignedByteToken) dataArrayToken
                    .getElement(j);
            dataBytes[j] = dataToken.byteValue();
        }

        // Convert using the default character encoding.
        String outputString = new String(dataBytes);
        output.send(0, new StringToken(outputString));
View Full Code Here

TOP

Related Classes of ptolemy.data.UnsignedByteToken

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.