@@ -398,25 +398,6 @@ public boolean setDTR(boolean enabled) throws SerialPortException {
398398 return serialInterface .setDTR (portHandle , enabled );
399399 }
400400
401- /**
402- * Write byte array to port
403- *
404- * @param buffer <code>byte[]</code> array to write
405- *
406- * @return If the operation is successfully completed, the method returns true, otherwise false
407- *
408- * @throws SerialPortException if exception occurred
409- *
410- * @deprecated use {@link #writeBytes(byte[])}.
411- */
412- @ Deprecated
413- public boolean writeBytes1 (byte [] buffer ) throws SerialPortException {
414- /* Delegate to new method and translate result to what original method
415- * did return. */
416- int numWrittenBytes = writeBytes (buffer );
417- return numWrittenBytes == buffer .length ;
418- }
419-
420401 /**
421402 * Write byte array to port.
422403 *
@@ -440,86 +421,105 @@ public int writeBytes(byte[] buffer) throws SerialPortException {
440421 *
441422 * @param singleByte single <code>byte</code> value to write
442423 *
443- * @return If the operation is successfully completed, the method returns true, otherwise false
424+ * @return Number of bytes written.
444425 *
445426 * @throws SerialPortException if exception occurred
446427 *
447428 * @since 0.8
448429 */
449- public boolean writeByte (byte singleByte ) throws SerialPortException {
430+ public int writeByte (byte singleByte ) throws SerialPortException {
450431 checkPortOpened ("writeByte()" );
451- return writeBytes (new byte []{singleByte }) == 1 ;
432+ return writeBytes (new byte []{singleByte });
452433 }
453434
454435 /**
455436 * Write String to port
456437 *
457438 * @param string <code>String</code> value to write
458439 *
459- * @return If the operation is successfully completed, the method returns true, otherwise false
440+ * @return
441+ * Number of bytes written. WARN: Number of BYTES, NOT number of CHARS!
442+ * This may differ from <code>string.length()</code> if passed in string
443+ * contains chars outside the english alphabeth. If you need reliable
444+ * return lengths, consider calling
445+ * {@link java.lang.String#getBytes(java.nio.charset.Charset)}
446+ * yourself and then passing result to
447+ * {@link #writeBytes(byte[])}
448+ * instead. This gives you the chance to verify the expected return
449+ * value correctly.
460450 *
461451 * @throws SerialPortException if exception occurred
462452 *
463453 * @since 0.8
464454 */
465- public boolean writeString (String string ) throws SerialPortException {
455+ public int writeString (String string ) throws SerialPortException {
466456 checkPortOpened ("writeString()" );
467457 byte [] bytes = string .getBytes ();
468- return writeBytes (bytes ) == bytes . length ;
458+ return writeBytes (bytes );
469459 }
470460
471461 /**
472462 * Write String to port
473463 *
474464 * @param string <code>String</code> value to write
475465 * @param charsetName valid <code>Charset</code> name, e.g. <code>"UTF-8"</code>
476- * @return If the operation is successfully completed, the method returns true, otherwise false
466+ *
467+ * @return
468+ * Number of bytes written. WARN: Number of BYTES, NOT number of CHARS!
469+ * This may differ from <code>string.length()</code> if passed in string
470+ * contains chars outside the english alphabeth. If you need reliable
471+ * return lengths, consider calling
472+ * {@link java.lang.String#getBytes(java.nio.charset.Charset)}
473+ * yourself and then passing result to
474+ * {@link #writeBytes(byte[])}
475+ * instead. This gives you the chance to verify the expected return
476+ * value correctly.
477477 *
478478 * @throws SerialPortException if exception occurred
479479 * @throws UnsupportedEncodingException if encoding exception occurred
480480 *
481481 * @since 2.8.0
482482 */
483- public boolean writeString (String string , String charsetName ) throws SerialPortException , UnsupportedEncodingException {
483+ public int writeString (String string , String charsetName ) throws SerialPortException , UnsupportedEncodingException {
484484 checkPortOpened ("writeString()" );
485485 byte [] bytes = string .getBytes (charsetName );
486- return writeBytes (bytes ) == bytes . length ;
486+ return writeBytes (bytes );
487487 }
488488
489489 /**
490490 * Write int value (in range from 0 to 255 (0x00 - 0xFF)) to port
491491 *
492492 * @param singleInt single <code>int</code> value to write
493493 *
494- * @return If the operation is successfully completed, the method returns true, otherwise false
494+ * @return Number of bytes written.
495495 *
496496 * @throws SerialPortException if exception occurred
497497 *
498498 * @since 0.8
499499 */
500- public boolean writeInt (int singleInt ) throws SerialPortException {
500+ public int writeInt (int singleInt ) throws SerialPortException {
501501 checkPortOpened ("writeInt()" );
502- return writeBytes (new byte []{(byte )singleInt }) == 1 ;
502+ return writeBytes (new byte []{(byte )singleInt });
503503 }
504504
505505 /**
506506 * Write int array (in range from 0 to 255 (0x00 - 0xFF)) to port
507507 *
508508 * @param buffer <code>int[]</code> array to write
509509 *
510- * @return If the operation is successfully completed, the method returns true, otherwise false
510+ * @return Number of bytes written.
511511 *
512512 * @throws SerialPortException if exception occurred
513513 *
514514 * @since 0.8
515515 */
516- public boolean writeIntArray (int [] buffer ) throws SerialPortException {
516+ public int writeIntArray (int [] buffer ) throws SerialPortException {
517517 checkPortOpened ("writeIntArray()" );
518518 byte [] byteArray = new byte [buffer .length ];
519519 for (int i = 0 ; i < buffer .length ; i ++){
520520 byteArray [i ] = (byte )buffer [i ];
521521 }
522- return writeBytes (byteArray ) == byteArray . length ;
522+ return writeBytes (byteArray );
523523 }
524524
525525 /**
0 commit comments