Tolong pilih kategori sesuai, jenis posting (diskusi atau bukan) dan sertakan tag/topik yang sesuai seperti komputer, java, php, mysql, dll. Promosi atau posting tidak pada tempatnya akan kami hapus!
- Bagi Anda yang ingin mendaftar, baca link berikut:
http://diskusiweb.com/discussion/50491/how-to-registrasi-diskusiweb-com-baca-ini-terlebih-dahulu
- Cara menyisipkan kode program supaya tampil rapi dan terformat dengan baik di diskusiweb.com: http://www.diskusiweb.com/discussion/50415/cara-menyisipkan-kode-program-di-diskusiweb-com
- Cara posting gambar/image di post Anda: http://www.diskusiweb.com/discussion/47345/cara-menyisipkan-menyertakan-image-pada-posting/p1

[ASK] JAVA baca stream data serial via COMPort

salam kenal master java,

saya punya alat yg selalu menirimkan data serial terus menerus, data tersebut di alirkan kurang lebih selama 15 menit.
datanya berupa bit2 HEX spt dibawah ini.

E0 04 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3F 80 00 00 08 49 49 F1 38 5E E9 E3 1F 51 DB 3F 00 00 00 00 00 00 00 00 00 00 00 00 3F 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 06 4A B0 08 81 57 60 83 B3 60 B4 22 00 93 80 03 91 01 02 03 04 E8 A0 FF FF FF FF FF FF FF A1 23 45 67 00 F4 00 00 00 06 00 80 00 00 02 98 00 00 00 09 00 00 00 00 00 00 00 00 00 00 00 00 3F 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3F 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 09 00 01 03 9D 00 00 00 00 00 00 00 00 00 00 00 00 3F 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3F 80 00 00 00 00 00 00 3F 80 00 00 00 00 00 00 00 00 00 00 7F A0 00 00 7F A0 00 00 7F A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3F 80 00 00 08 49 49 F1 38 5E E9 E3 1F 51 DB 3F 00 00 00 00 00 00 00 00 00 00 00 00 3F 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 06 4A B0 08 81 57 60 83 B3 60 B4 22 00 93 80 03 91 01 02 03 04 E8 8D FF FF FF FF FF FF FF A1 23 45 67 00 F5 00 00 00 06 00 80 00 00 02 9B 00 00 00 09 00 00 00 00 00 00 00 00 00 00 00 00 3F 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3F 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 09 00 01 04 AB 00 00 00 00 00 00 00 00 00 00 00 00 3F 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3F 80 00 00 00 00 00 00 3F 80 00 00 00 00 00 00 00 00 00 00 7F A0 00 00 7F A0 00 00 7F A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3F 80 00 00 08 49 49 F1 38 5E E9 E3 1F 51 DB 3F 00 00 00 00 00 00 00 00 00 00 00 00 3F 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 06 4A B0 08 81 57 60 83 B3 60 B4 22 00 93 80 03 90 01 02 03 04 E8 7B FF FF FF FF FF FF FF FF A1 23 45 67 00 F6 00 00 00 06 00 80 00 00 02 9E 00 00 00 09 00 00 00 00 00 00 00 00 00 00 00 00 3F 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3F 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 09 00 01 05 B9 00 00 00 00 00 00 00 00 00 00 00 00 3F 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3F 80 00 00 00 00 00 00 3F 80 00 00 00 00 00 00 00 00 00 00 7F A0 00 00 7F A0 00 00 7F A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3F 80 00 00 08 49 49 F1 38 5E E9 E3 1F 51 DB 3F 00 00 00 00 00 00 00 00 00 00 00 00 3F 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 06 4A B0 08 81 57 60 83 B3 60 B4 21 C0 93 80 03 91 01 02 03 04 E7 A8 FF FF FF FF  EA 17 FF FF FF FF 00 00 00 7F A0 00 00 7F A0 00 00 00 00 00 00 00 00 00 00

pola datanya selalu dimulai dgn A1234567 dan diakhiri dgn FFFFFFFFF

bagaimana cara membaca pola data serial tsb agar bisa di save kedalam txt atau database...?

mohon pencerahannya, tks :)
Tagged:

Comments

  • data itu masuk terbaca pake aplikasi apa ?
    apa ada aplikasi tertentu yg memantau port tertentu ?
  • paka Java juga aplikasinya, data yg diatas itu bacanya paka HTERM (aplikasi utk simulasi kom.serial/comport).

    yg saya buat hasilnya spt ini :
     
    4000004164ab0881576083b360b422093803911234e82fffffffffffffffffa12345670fa00062002a800090000000000003
    f80000000000000003f8000000000020000002141002ac222b76418080021042696021280c202b7e41808000406
    36810ac226b7618080024202110240c0420d37cc00002118100090823cafd220212120084800280214c4fa48088
    0000636010806002d76482c008006360200202143

    itupun kadang2 terbacanya :(

     @Override // CHAR TO
        public void serialEvent(SerialPortEvent evt) {
            char  dataSerial; // Untuk menampung input dari serial port
     
            if (evt.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
                try {
                    dataSerial = (char) input.read();               
                   
                    int iChar   = (int) dataSerial;
                    catchData   = Integer.toHexString(iChar);                   
                  
                    serial_gui.txt_Status.append(catchData);
                    System.out.println(catchData);
                   
                } catch (IOException ex) {
                    JOptionPane.showMessageDialog(null, ex.toString());
                }
            }
        }
  • edited November 2014
    kadang-kadang terbaca itu :
    - error ?
    - buffer kosong ?
    atau bagaimana ?

    fungsi / method serialEvent() jalan di trigger apa ?
  • gak error Pak, datanya ada, TAPI gak ada a1234567 dst. nyaa.

    di trigger kalau ada aliran data langsung baca (InputStream)
  • jadi file nya bener terisi dan tersimpan ?

    coba elo post isi file yg berhasil terekam ke pastebin
    posting kemari url nya
  • 1003f800084949f1385ee9e31f51db3f0000000000003f80000000000000004152c1881576083b360b422093803911
    234e8b6ffffffffffffffa12345671e0006080002de0008000001020060446880560a0844324008000412002e1060a83730
    0800804602f4218f678301210228482400815042e488020420210122021840143fa82012102284c2808815042e488
    02408002101220018402143fa22014802121000522360f318082028008c00841143f2820121022848280815042e48
    8020421210122021840143f222014802101080122360f341808002420211008c0420d3be40080000211008c0420d3
    bf6000009020c6808c121437980002808042696021280c202b7e08080208208480841214379020280c00211028c0
    420d3bf6000808420864002c121437d800028012101080122360f3200212100084820280214c4f244808000502112
    02e81301df8220212120084800280214c4f288002018100090823cafd220212120084800280214c4fa448088000011
    202c013035f82202112008480028017840e422012100021880122360f022021120084800280214c4f040100204288
    480002152489130202028c80808015042e42002110008488008012143fa82812120428c80808015042e422021100
    88488000152409182401210028480808015042e4220211000c6880080002b76c1808204240636202023844fa9008
    8032105244080c202b768802408012101220018402143fa8281210028480808015042e4200211000c6880080002b
    768802080021012204218402143fa80012102284c2808015042e42042211000868808802002b7e6000002011800c
    040a1ff800121022848280815042e480208012101220218402143fa80012102284c2808015042e422422110008688
    08802002b7e8020201012202c040143fa00121022848280815042e4802080021012204218402143fa0012102284c2
    808015042e480202110122029040143f20848020a086360210ac222b7e80808202a1069601280101ffd2002144012
    101080122360f3200212100084820280214c4fa480800040211202e81301df8220212100084820280212143792002
    808042696021280c202b7e880028002101080122360f3220212100084820280214c4fa480800040636810ac22d6f8
    46062080680063023c00d37cc00002118100290803caf34612121401001880122360f3200212100084820280214c4
    fa20021120084800280214c4fa8800201810009023cafd200212120084800280214c4f2448088008006360100600ad
    7644c28800006360280202149f026028088480202150489129212120084800280214c4f24480880000211202c020d
    7e80808002101880102360f02202112008480028017840e422012100021880122360f022021120084800280214c4f0
    228112008c80008015040e4220121002181000902960fd2202112008c80028015840e42002110040848800015240
    9182401210028480808015042e4200211000c6880080002b76c1808204200636202023844fa90088022101244080
    c202b76880208002101220018402143f282401210028480808015042e4220211000c6880880006b7681808204200
    63620202384482880208012101220218402143fa82012102284c2808815042e48802408002101220018402143fa2
    0014812121000122360f3418082028008c008440271be862680860026320b1143f2800121022848280815042e4008
    000086802408015040e4480000284820428212143798020280c00211008c0420d3bf600808000211008c0420d3be
    480000020c6808412143790002808042696021280c202b7e40808020a08636810ac226b7e080800200211008c042
    0d3bf6000800211202e81301ff8220214012101080122360f32202144002101080122360f3200212100084820280214
    c4fa20021120084800280214c4fa98002018100090823caf5220212120084820280214c4f248088002011202c01303
    5f822021120084800280212143f8820121010421880122360f0220212120084800280214c4f2480880000636010806
    002d764828808420211002c0420ad7e41828808420211002c0420ad7e0028080008602c46082d768808802214010
    48808202b7660002024011000c2840a1ff98088022181048808202b766020202811000c24288070202028c8080801
    5042e42002110040848800015240917921210088488000152509130202008c80008015040e4220211

  • itu per baris emang elo buat pake newline ?

    soalnya kalo gw bagi per 2 char :

    10 03 f8 00 08 49 49 f1 38 5e e9 e3 1f 51 db 3f 00 00 00 00 00 00 3f 80 00 00 00 00 00 00 00 41 52 c1 88 15 76 08 3b 36 0b 42 20 93 80 39 11
    23 4e 8b 6f ff ff ff ff ff ff fa 12 34 56 71 e0 00 60 80 00 2d e0 00 80 00 00 10 20 06 04 46 88 05 60 a0 84 43 24 00 80 00 41 20 02 e1 06 0a 83 73 0
    08 00 80 46 02 f4 21 8f 67 83 01 21 02 28 48 24 00 81 50 42 e4 88 02 04 20 21 01 22 02 18 40 14 3f a8 20 12 10 22 84 c2 80 88 15 04 2e 48 8
    02 40 80 02 10 12 20 01 84 02 14 3f a2 20 14 80 21 21 00 05 22 36 0f 31 80 82 02 80 08 c0 08 41 14 3f 28 20 12 10 22 84 82 80 81 50 42 e4 8
    80 20 42 12 10 12 20 21 84 01 43 f2 22 01 48 02 10 10 80 12 23 60 f3 41 80 80 02 42 02 11 00 8c 04 20 d3 be 40 08 00 00 21 10 08 c0 42 0d 3
    bf 60 00 00 90 20 c6 80 8c 12 14 37 98 00 02 80 80 42 69 60 21 28 0c 20 2b 7e 08 08 02 08 20 84 80 84 12 14 37 90 20 28 0c 00 21 10 28 c0
    42 0d 3b f6 00 08 08 42 08 64 00 2c 12 14 37 d8 00 02 80 12 10 10 80 12 23 60 f3 20 02 12 10 00 84 82 02 80 21 4c 4f 24 48 08 00 05 02 11 2
    02 e8 13 01 df 82 20 21 21 20 08 48 00 28 02 14 c4 f2 88 00 20 18 10 00 90 82 3c af d2 20 21 21 20 08 48 00 28 02 14 c4 fa 44 80 88 00 00 11
    20 2c 01 30 35 f8 22 02 11 20 08 48 00 28 01 78 40 e4 22 01 21 00 02 18 80 12 23 60 f0 22 02 11 20 08 48 00 28 02 14 c4 f0 40 10 02 04 28 8
    48 00 02 15 24 89 13 02 02 02 8c 80 80 80 15 04 2e 42 00 21 10 00 84 88 00 80 12 14 3f a8 28 12 12 04 28 c8 08 08 01 50 42 e4 22 02 11 00
    88 48 80 00 15 24 09 18 24 01 21 00 28 48 08 08 01 50 42 e4 22 02 11 00 0c 68 80 08 00 02 b7 6c 18 08 20 42 40 63 62 02 02 38 44 fa 90 08
    80 32 10 52 44 08 0c 20 2b 76 88 02 40 80 12 10 12 20 01 84 02 14 3f a8 28 12 10 02 84 80 80 80 15 04 2e 42 00 21 10 00 c6 88 00 80 00 2b
    76 88 02 08 00 21 01 22 04 21 84 02 14 3f a8 00 12 10 22 84 c2 80 80 15 04 2e 42 04 22 11 00 08 68 80 88 02 00 2b 7e 60 00 00 20 11 80 0c
    04 0a 1f f8 00 12 10 22 84 82 80 81 50 42 e4 80 20 80 12 10 12 20 21 84 02 14 3f a8 00 12 10 22 84 c2 80 80 15 04 2e 42 24 22 11 00 08 68 8
    08 80 20 02 b7 e8 02 02 01 01 22 02 c0 40 14 3f a0 01 21 02 28 48 28 08 15 04 2e 48 02 08 00 21 01 22 04 21 84 02 14 3f a0 01 21 02 28 4c 2
    80 80 15 04 2e 48 02 02 11 01 22 02 90 40 14 3f 20 84 80 20 a0 86 36 02 10 ac 22 2b 7e 80 80 82 02 a1 06 96 01 28 01 01 ff d2 00 21 44 01 2
    10 10 80 12 23 60 f3 20 02 12 10 00 84 82 02 80 21 4c 4f a4 80 80 00 40 21 12 02 e8 13 01 df 82 20 21 21 00 08 48 20 28 02 12 14 37 92 00 2
    80 80 42 69 60 21 28 0c 20 2b 7e 88 00 28 00 21 01 08 01 22 36 0f 32 20 21 21 00 08 48 20 28 02 14 c4 fa 48 08 00 04 06 36 81 0a c2 2d 6f 8
    46 06 20 80 68 00 63 02 3c 00 d3 7c c0 00 02 11 81 00 29 08 03 ca f3 46 12 12 14 01 00 18 80 12 23 60 f3 20 02 12 10 00 84 82 02 80 21 4c 4
    fa 20 02 11 20 08 48 00 28 02 14 c4 fa 88 00 20 18 10 00 90 23 ca fd 20 02 12 12 00 84 80 02 80 21 4c 4f 24 48 08 80 08 00 63 60 10 06 00 ad
    76 44 c2 88 00 00 63 60 28 02 02 14 9f 02 60 28 08 84 80 20 21 50 48 91 29 21 21 20 08 48 00 28 02 14 c4 f2 44 80 88 00 00 21 12 02 c0 20 d
    7e 80 80 80 02 10 18 80 10 23 60 f0 22 02 11 20 08 48 00 28 01 78 40 e4 22 01 21 00 02 18 80 12 23 60 f0 22 02 11 20 08 48 00 28 02 14 c4 f0
    22 81 12 00 8c 80 00 80 15 04 0e 42 20 12 10 02 18 10 00 90 29 60 fd 22 02 11 20 08 c8 00 28 01 58 40 e4 20 02 11 00 40 84 88 00 01 52 40
    91 82 40 12 10 02 84 80 80 80 15 04 2e 42 00 21 10 00 c6 88 00 80 00 2b 76 c1 80 82 04 20 06 36 20 20 23 84 4f a9 00 88 02 21 01 24 40 80
    c2 02 b7 68 80 20 80 02 10 12 20 01 84 02 14 3f 28 24 01 21 00 28 48 08 08 01 50 42 e4 22 02 11 00 0c 68 80 88 00 06 b7 68 18 08 20 42 00
    63 62 02 02 38 44 82 88 02 08 01 21 01 22 02 18 40 21 43 fa 82 01 21 02 28 4c 28 08 81 50 42 e4 88 02 40 80 02 10 12 20 01 84 02 14 3f a2
    00 14 81 21 21 00 01 22 36 0f 34 18 08 20 28 00 8c 00 84 40 27 1b e8 62 68 08 60 02 63 20 b1 14 3f 28 00 12 10 22 84 82 80 81 50 42 e4 00 8
    00 00 86 80 24 08 01 50 40 e4 48 00 00 28 48 20 42 82 12 14 37 98 02 02 80 c0 02 11 00 8c 04 20 d3 bf 60 08 08 00 02 11 00 8c 04 20 d3 be
    48 00 00 02 0c 68 08 41 21 43 79 00 02 80 80 42 69 60 21 28 0c 20 2b 7e 40 80 80 20 a0 86 36 81 0a c2 26 b7 e0 80 80 02 00 21 10 08 c0 42
    0d 3b f6 00 08 00 21 12 02 e8 13 01 ff 82 20 21 40 12 10 10 80 12 23 60 f3 22 02 14 40 02 10 10 80 12 23 60 f3 20 02 12 10 00 84 82 02 80 21 4
    c4 fa 20 02 11 20 08 48 00 28 02 14 c4 fa 98 00 20 18 10 00 90 82 3c af 52 20 21 21 20 08 48 20 28 02 14 c4 f2 48 08 80 02 01 12 02 c0 13 03
    5f 82 20 21 12 00 84 80 02 80 21 21 43 f8 82 01 21 01 04 21 88 01 22 36 0f 02 20 21 21 20 08 48 00 28 02 14 c4 f2 48 08 80 00 06 36 01 08 06
    00 2d 76 48 28 80 84 20 21 10 02 c0 42 0a d7 e4 18 28 80 84 20 21 10 02 c0 42 0a d7 e0 02 80 80 00 86 02 c4 60 82 d7 68 80 88 02 21 40 10
    48 80 82 02 b7 66 00 02 02 40 11 00 0c 28 40 a1 ff 98 08 80 22 18 10 48 80 82 02 b7 66 02 02 02 81 10 00 c2 42 88 07 02 02 02 8c 80 80 80 1
    50 42 e4 20 02 11 00 40 84 88 00 01 52 40 91 79 21 21 00 88 48 80 00 15 25 09 13 02 02 00 8c 80 00 80 15 04 0e 42 20 21 1     


    ada yg cuma 1 char
    dan panjang tiap baris juga kagak sama

    A1234567 ada,
    tapi bentuknya lain

    6f ff ff ff ff ff ff fa 12 34 56 71

    jadi kemungkinan ini masalah panjang char nya
  • bukan new line pak, aslinya spt dibawah ini, itu tdi waktu ngopi ke sini saya kasih ENTER...

    ini yg baru saya perbaiki code-nya, data yg diterima sperti ini, itu pun lagi2 hanya sesekali saja, tidak continue spt kalau menggunakan HTERM....

     22 0 93 80 3 91 1 2 3 4 e8 55 ff ff ff ff ff ff ff a1 23 45 67 0 f8 0 0 0 6 0 80 0 0 2 a3 0 0 0 9 0 0 0 0 0 0 0 0 20 0 3f 80 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3f 80 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 0 1 7 0 2 23 0 2 28 1 21 43 79 2 2 0 2 c0 80 0 61 60 1 2 80 1 0 1f fd 1 80 82 0 2 0 0 69 60 1 2 80 1 0 1f fd a2 0 1 21 0 2 2 84 80 8 0 80 15 0 42 e4 22 0 21 1 0 0 0 84 88 0 0 0 5 0 44 fa 9 82 80 0 8 8 0 0 86 0 2 84 60 88 80 3 9 21 21 0 0 8 84 88 0 0 2 15 2 48 91 91 0 21 1 2 0 0 84 80 0 2 80 21 21 43 f8 0 0 1 21 0 1 0 0 18 8 0 12 2 3 60 f3 20 0 21 1 2 0 0 84 80 0 2 80 21 4 c4 fa 4 80 88 0 0 8 2 0 86 40 0 2c 1 21 43 7d 0 0 0 2 80 80 42 69 60 21 2 80 c0 0 6b be 42 8 0 0 0 0 2 21 52 8 0 c0 13 0 1f fd 1 80 80 0 2 0 0 69 60 1 2 80 1 0 1f fd a0 0 1 21 0 2 2 84 c2 8 0 80 15 0 42 e4 20 0 21 1 0 0 0 84 88 0 0 80 1 21 43 fa 80 8 1 1 2 0 0 8c 80 0 0 80 15 0 40 e4 22 0 21 1 0 0 40 84 88 0 0 2 15 2 48 91 91 0 21 1 2 0 0 8c 80 0 2 80 17 8 40 e4 80 0 1 21 0 0 0 0 18 8 0 12 2 3 60 f3 22 0 21 21 0 0 0 84 82 0 2 80 21 21 43 f9 9 0 0 0 2 1 1 0 10 0 2 90 40 0 4c 7d 80 0 0 2 80 c0 0 21 10 2 40 c0 42 0 d3 be a6 0 8 0 0 0 0 21 10 0 8 c0 42 0 d3 be 48 0 0 0 0 48 0 21 10 42 8 c0 42 0 d3 bf 60 0 0 0 0 82 2 0 84 8 0 84 1 21 43 79 2 2 0 2 80 80 0 69 60 1 2 80 1 0 1f fd a2 0 1 21 0 2 2 84 c2 8 0 80 15 0 42 e4 22 0 21 1 0 0 0 84 88 0 0 80 1 21 43 fa 4e 84 0 2 0 2 0 c6 88 0 0 80 0 0 2b 76 c1 80 82 0 0 8 8 0 84 2 0 86 1 21 43 f0 82 8 1 1 2 0 0 8c 80 0 2 80 15 8 40 e4 22 0 1 21 0 1 0 42 18 8 0 12 2 3 60 f0 22 0 21 1 2 0 0 84 80 0 2 80 21 4 c4 f0 6 2 1 21 0 1 0 0 18 8 0 12 2 3 60 f3 20 0 21 21 0 0 0 84 82 0 2 80 21 21 43 f9 9 0 0 0 2 0 1 0 10 0 2 90 40 0 4c 79 80 0 0 2 80 80 42 69 60 21 2 80 c2 0 2b be 2 8 0 8 0 0 2 21 12 8 0 c8 13 0 1f fd a0 0 1 21 0 2 2 84 c2 8 0 80 15 0 42 e4 8 0 2 0 42 1 21 0 12 20 42 18 40 21 43 fa 0 40 1 21 0 0 2 c4 80 8 0 80 15 0 42 e4 20 0 21 1 0 0 40 84 88 0 0 2 15 2 48 91 91 0 21 1 2 0 0 8c 80 0 2 80 15 8 40 e4 80 0 21 21 0 0 21 8 10 0 0 90 2 1 60 fd 22 0 21 1 2 0 0 84 80 0 2 80 21 4 c4 fa 44 80 88 0 0 8 2 0 86 0 0 2c 1 21 43 7d 80 0 0 2 80 c0 0 21 10 2 8 c0 42 0 d3 bf 60 0 0 8 0 0 2 1 12 0 2 e8 13 0 1f f8 22 0 21 4 40 1 21 0 10 8 0 12 2 3 60 f3 1 80 82 0 2 a1 0 69 60 1 2 80 1 0 1f fd 41 80 82 0 2 0 0 0 8c 0 0 84 1 1 43 fa 20 0 1 4 8 0 21 2 10 0 0 52 2 3 60 f3 1 80 82 0 2 0 0 21 18 0 8 c0 40 0 d3 bf 14 68 60 0 0 60 2 0 63 0 0 9 c0 40 40 7 0 21 1 0 0 8 84 88 0 0 2 15 2 48 91 3 0 21 1 0 0 0 84 88 0 0 0 15 2 40 91 7 9 21 21 0 1 21 40 10 4 8 80 82 0 23 76 c1 80 80 8 0 42 0 1 10 2 0 c2 42 0 2d 76 1 88 80 0 0 42 0 1 10 2 0 c2 42 0 2d 76 4 80 88 0 0 4 0 63 60 1 0 80 60 0 ad 76 41 88 80 0 0 42 0 21 10 2 0 c0 42 0 d3 7c 0 80 80 0 2 0 42 69 60 21 2 80 c2 0 2b bf 42 80 80 0 2 0 2 69 60 21 2 80 c2 0 2b 7e 40 80 80 2 0 8 2 40 84 8 0 84 1 21 8 7e 0 84 80 2 0 8 2 21 10 8 0 c0 3 0 1f fd 4a 10 0 2 0 2 0 c6 88 0 0 80 0 0 2b 76 8 0 2 40 80 1 21 0 12 20 0 18 2 9 60 be 8 2 40 0 8 1 1 2 50 0 0 8 1 40 35 fd 42 10 0 2 0 42 8 84 80 0 0 2 15 42 48 91 91 0 21 1 2 0 0 84 80 0 2 80 21 4 c4 f2 22 0 21 1 2 0 0 8c 80 0 2 80 21 21 43 f8 0 0 1 21 0 0 0 0 18 8 0 12 2 3 60 f3 22 0 21 21 0 0 0 84 82 0 2 80 21 21 43 7d 80 0 0 2 80 c0 0 21 10 2 8 c0 42 0 d3 bf 60 0 0 0 0 0 2 1 12 0 42 e8 13 0 1f f8 22 0 1 4 8 1 21 2 10 8 0 12 2 3 60 f3 1 80 82 0 2 a1 0 63 60 1 2 80 1 0 1f fd 41 80 82 0 2 0 0 0 8c 0 0 84 1 1 43 fa 20 0 1 4 8 0 21 2 10 0 0 12 2 3 60 f3 1 80 82 0 2 0 0 21 18 0 8 c0 40 0 d3 bf 14 68 60 0 0 60 2 0 63 0 0 9 c0 40 40 7 0 21 1 0 0 40 84 88 0 0 0 15 2 48 91 82 0 42 8 80 2 21 0 52 4 40 80 c2 0 2b 76 c1 80 82 8 0 8 0 0 84 2 0 86 1 21 43 f0 82 0 21 1 2 0 0 84 80 0 2 80 21 4 c4 f0 6 2 1 21 0 1 0 0 18 8 0 12 2

    seharusnya yg bener datanya, ada counter yg jalan (bold biru)

    ff ff ff ff ff ff ff a1 23 45 67 0 f8 ....
    ff ff ff ff ff ff ff a1 23 45 67 0 f9 ....
    ff ff ff ff ff ff ff a1 23 45 67 0 fA ....

    data kalau pakai HTERM...

    image
  • oia, data diatas saya menggunakan INPUTSTREAM...

    nyobain pakai BUFFEREDREADER hasilnya spt ini...

     0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 0 1 f 37 0 0 0 0 0 0 0 0 0 0 0 0 3f fffd 0 0 0 0 0 0 0 0 0 0 0 fffd 0 0 0 0 3f fffd 0 0 0 0 0 0 3f fffd 0 0 0 0 0 0 0 0 0 0 7f fffd 0 0 7f fffd 0 0 7f fffd 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 2 1 0 fffd fffd 44 fffd fffd 2 0 50 2 21 12 40 0 fffd 13 0 1f fffd 20 0 21 4 0 1 21 0 10 8 0 12 2 3 60 fffd 41 fffd fffd 0 2 8 0 0 fffd 0 0 fffd 40 2 71 fffd 8 62 68 0 8 60 0 2 63 2 0 5b 1 21 43 fffd 40 1 21 0 0 2 100 8 0 fffd 15 0 42 fffd 8 0 2 0 fffd 1 21 0 12 20 0 18 40 21 43 fffd 0 8 1 21 2 0 2 fffd fffd 8 0 fffd 15 0 42 fffd 20 0 21 1 0 0 8 fffd fffd 0 0 2 15 2 48 fffd fffd 0 1 1 2 0 0 fffd fffd 0 2 fffd 15 8 40 fffd 22 0 21 21 0 0 8 fffd fffd 0 0 2 15 2 48 fffd fffd 0 21 1 2 0 0 fffd fffd 0 2 fffd 17 8 40 fffd 0 1 21 0 0 0 0 18 8 0 12 2 3 60 fffd 22 0 21 21 42 0 0 fffd fffd 0 2 fffd 21 4 fffd fffd 22 0 21 21 2 0 0 fffd fffd 0 2 fffd 21 4 fffd fffd 44 fffd fffd 0 0 50 2 1 12 0 2 fffd 13 0 1f fffd 22 0 21 4 40 0 21 0 10 8 0 12 2 3 60 fffd 4 2 0 8 0 0 0 fffd fffd 0 2 8 21 21 43 fffd 8 0 0 0 2 1 1 0 10 0 2 fffd 40 1 43 fffd 4 fffd fffd 0 0 0 40 63 68 1 0 a fffd 2 2b 7e 41 fffd fffd 0 2 0 0 0 fffd 0 0 fffd 1 1 43 fffd 0 1 21 0 2 2 fffd fffd 8 0 fffd 15 0 42 fffd 0 2 0 2 0 1 0 12 20 2 18 40 1 43 fffd 0 1 21 0 2 2 fffd fffd 8 0 fffd 15 0 42 fffd 22 0 21 1 0 0 0 fffd fffd 0 0 fffd 1 21 43 fffd 2 8 1 1 2 0 0 fffd fffd 0 0 fffd 15 0 40 fffd 22 0 21 1 0 0 0 fffd fffd 0 0 0 15 2 40 fffd 7 0 21 21 0 2 8 fffd fffd 0 0 2 15 42 48 fffd fffd 0 21 1 2 0 0 fffd fffd 0 2 fffd 21 21 43 fffd 20 0 21 21 0 1 21 8 10 0 0 fffd 2 1 60 fffd 20 0 21 1 2 0 0 fffd fffd 0 2 fffd 21 4 fffd fffd 9 8 0 0 2 0 1 8 10 0 2 fffd fffd 3 fffd fffd 42 8 21 21 8 0 1 0 10 0 2 fffd 40 1 43 fffd 20 0 21 21 42 0 0 fffd fffd 0 2 fffd 21 4 fffd fffd 44 fffd fffd 0 0 fffd 0 63 68 1 0 a fffd 2 2b 76 40 fffd fffd 0 2 0 0 42 fffd 0 0 fffd 40 2 71 fffd 24 8 0 0 fffd 0 2 21 10 8 0 fffd 13 0 1f fffd 41 fffd fffd 0 2 0 0 69 60 1 2 fffd 1 0 1f fffd 22 0 1 21 0 2 2 fffd fffd 8 0 fffd 15 0 42 fffd 22 42 21 1 0 0 0 188 0 0 fffd 0 0 6b 76 40 0 0 2 fffd 2 0 1 10 0 0 84 0 fffd fffd 0 8 1 21 2 0 2 fffd fffd 8 0 fffd 15 0 42 fffd 22 0 21 1 0 0 8 fffd fffd 0 0 2 15 2 48 fffd fffd 0 1 1 2 0 0 fffd fffd 0 2 fffd 15 8 40 fffd 20 0 21 21 0 2 8 fffd fffd 0 0 2 15 2 48 fffd 3 0 2 0 2 0 42 fffd fffd 0 0 fffd 15 0 52 fffd 20 0 21 21 0 1 21 8 10 0 0 fffd 2 1 60 fffd 22 0 21 1 2 0 0 fffd fffd 0 2 fffd 21 4 fffd fffd 9 8 0 0 2 0 1 8 10 0 2 fffd fffd 3 fffd fffd 22 0 1 21 0 1 0 42 18 8 0 12 2 3 60 fffd 22 0 21 21 2 0 0 fffd fffd 0 2 fffd 21 4 fffd fffd 4 fffd fffd 0 0 4 0 63 68 1 0 a fffd 2 6b 76 1 fffd fffd 0 2 42 0 21 10 42 8 fffd 42 0 4fe 60 0 0 0 0 fffd 2 0 fffd 8 0 fffd 1 21 43 79 2 2 0 2 fffd fffd 0 69 60 1 2 fffd
  • agak sulit membandingkan "byte yg hilang" soalnya data nya bukan di posisi yg sama

    misal begini,
    hasil aplikasi di capture mulai counter 1
    hterm juga di capture mulai counter 1 juga
    kalo begitu, bisa dilihat byte keberapa yg hilang dan bikin kacau urutan

    baru kemudian dilacak balik,
    hilangnya apa karena masalah buffer
    atau masalah delay proses yg terlalu lama sehingga buffer terlanjur ketimpa data baru
    atau bagaimana

    tapi yg elo posting posisinya kagak sama

    gw capture sebagian buat dibandingkan, emang ada byte yg hilang ...

    ini dari post awal :

    A1 23 45 67 00 F4 00 00 00 06 00 80 00 00 02 98 00 00 00 09 00 00 00 00 00 00 00 00 00 00 00 00 3F 80 ...
    A1 23 45 67 00 F5 00 00 00 06 00 80 00 00 02 9B 00 00 00 09 00 00 00 00 00 00 00 00 00 00 00 00 3F 80 ...
    A1 23 45 67 00 F6 00 00 00 06 00 80 00 00 02 9E 00 00 00 09 00 00 00 00 00 00 00 00 00 00 00 00 3F 80 ...


    ini dari post terakhir :

    a1 23 45 67 00 f8 00 00 00 06 00 80 00 00 02 a3 00 00 00 09 00 00 00 00 00 00 00 00 20 00 3f 80 00 00 ...

    itu sudah hilang 2 byte

    tapi belum bisa menyimpulkan sesuatu
    soalnya posisi data emang kagak sama
    siapa tau emang datanya kaya begitu
  • edited November 2014
    btw, gw bandingin koding elo dgn koding disini :
    http://en.wikibooks.org/wiki/Serial_Programming/Serial_Java#Reading_of_Data
    itu juga baca port langsung masuk file

    ada yg beda ...

    elo baca .read() cuma sekali

    dataSerial = (char) input.read();

    tapi di referensi yg gw tunjuk .read() dilakukan terus pake loop while sampai data tidak terbaca lagi

    while((c = is.read()) != -1) {
      out.write(c);
    }

    artinya,
    ada kemungkinan data masuk bukan cuma 1 byte
    tapi bisa beruntun sekaligus

    coba elo ubah juga pake while
  •  hasilnya sama aja Pak :(

    @Override
        @SuppressWarnings("empty-statement")
        public void serialEvent(SerialPortEvent evt) {
            if (evt.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
                try {
                    int C;
                    while( (C = input.read()) != -1 ) {
                                         
                        sCatchData   = Integer.toHexString(C);
                       
                        serial_gui.txt_Status.append(" " + sCatchData);                  
                    }
                } catch (IOException ex) {
                    JOptionPane.showMessageDialog(null, ex.toString());
                }
            }
        }

    output-nya...

     81 57 60 83 b3 60 b4 22 0 93 80 3 91 1 2 3 4 e9 27 ff ff ff ff ff ff ff a1 23 45 67 1 8 0 0 0 6 0 80 0 0 2 ce 0 0 0 9 0 10 0 0 0 0 0 0 0 0 0 3f 80 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3f 80 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 88 4 0 61 a 0 0 3f 10 52 a 37 1 2 0 2 0 42 88 4 4 0 0 fe 1 2 2b 7e 0 80 82 0 2 0 0 21 10 0 8 c0 0 d3 be 8 0 8 0 80 2 0 21 18 0 0 c0 0 a1 ff 10 42 21 1 0 0 0 c6 88 0 0 80 0 2b 76 8 0 2 40 80 1 21 0 12 20 0 18 2 43 60 8 2 40 0 8 1 1 2 10 0 42 8 0 35 fd 4e 0 1 1 2 0 0 8c 80 0 0 80 15 0 40 e4 0 21 1 0 0 40 84 88 0 0 0 15 2 40 91 0 2 8 80 11 21 0 12 4 0 80 0 2b 76 81 80 82 40 0 0 0 63 62 0 2 40 23 0 44 f9 0 21 21 0 1 21 8 10 0 0 90 2 3 60 fd 22 0 21 1 2 0 0 84 80 0 2 80 4 c4 fa 22 0 21 1 2 0 0 8c 80 0 2 80 17 8 40 e4 0 1 21 0 1 0 0 18 8 0 12 3 60 f3 22 0 21 21 42 0 0 84 82 0 2 80 4 c4 f2 4 80 80 0 0 2 2 1 12 0 0 e8 13 0 1f f8 22 0 21 21 0 0 0 84 82 0 2 80 21 43 79 2 0 0 2 80 80 42 69 60 21 2 80 0 2b be 2 8 0 8 0 0 2 21 12 8 0 c0 13 0 1f fd 20 0 1 4 8 1 21 2 10 8 0 12 2 3 60 f3 80 82 0 2 8 40 0 8c 0 0 84 1 1 43 f2 0 0 1 21 0 2 2 84 80 8 0 80 15 0 42 e4 0 21 1 0 0 0 84 88 0 0 80 21 43 fa 4a 80 0 2 0 2 0 86 88 0 8 80 0 2b 76 40 0 0 2 0 2 0 1 10 0 0 c2 84 0 a1 ff 9 8 0 8 80 3 21 8 10 4 8 80 88 91 0 21 1 2 0 0 84 80 0 2 80 4 c4 f2 22 8 21 1 2 0 0 8c 80 0 2 80 15 8 40 22 0 1 21 0 0 0 42 18 8 0 12 2 3 60 e0 22 0 21 21 42 0 0 84 82 0 2 80 4 c4 fa 44 80 80 0 0 50 2 1 12 0 42 e8 13 0 1f f8 22 0 21 21 0 0 0 84 82 0 2 80 21 43 7d 80 0 0 2 80 c0 0 21 10 2 8 c0 0 d3 be a6 0 8 0 0 0 0 21 10 0 8 c0 0 d3 be 48 0 0 0 0 48 0 21 10 42 8 c0 0 d3 bf 60 0 0 0 0 82 2 0 c6 8 0 84 21 43 79 2 2 0 2 80 80 0 69 60 1 2 80 1 0 1f fd 22 0 1 21 0 2 2 84 82 8 0 88 15 0 42 e4 0 2 40 80 0 21 0 12 20 0 18 2 9 60 3 0 1 21 0 2 2 84 c2 8 0 80 15 0 42 e4 42 21 1 0 0 0 c6 88 0 0 80 0 2b 76 c1 80 82 40 0 84 0 63 62 0 2 40 23 0 44 f9 0 21 21 0 1 21 8 10 0 0 90 2 1 60 fd 4e 10 0 2 0 2 8 84 88 0 0 2 15 2 48 91 0 21 1 2 0 0 8c 80 0 2 80 17 8 40 0 1 21 0 1 0 42 18 8 0 12 2 3 60 e0 0 21 1 2 0 0 84 80 0 2 80

    sebelum2nya saya kalau buat aplikasi interface communication via COMPORT selalu pakai methode seperti itu, dan blm ada maslah jg Pak...

    hasil googling saya sejauh ini ada 2 cara utk membaca data serialport. melalui INPUTSTREAM atau BUFFEREDREADER, keduanya sudah saya coba dan hasilnya blm sesuai yg diharapkan...

    apa cara pembacaan data itu tergantung dari tipe data yg dikirim oleh alat-nya...? misalnya data yg dikirim bentuknya ASCII atau CHART, ditampung dlm tipe apa...? dan kemudian di casting dalam tipe apa...? begitu mungkin ya..?

    btw thank you atas responnya pak @lobster
  • misal begini,
    hasil aplikasi di capture mulai counter 1
    hterm juga di capture mulai counter 1 juga
    kalo begitu, bisa dilihat byte keberapa yg hilang dan bikin kacau urutan

    alatnya ngirim data secara acak namun beruntun,  kita tidak bisa ngeset alat agar counter mulainya spt yg kita inginkan pak... misal ff ff ff ff ff ff ff a1 23 45 67 0 00 ...

    misal, waktu dinyalakan alatnya dan program secara bersamaan

    ff ff ff ff ff ff ff a1 23 45 67 0 20 ....
    ff ff ff ff ff ff ff a1 23 45 67 0 21 ....
    ff ff ff ff ff ff ff a1 23 45 67 0 22 ....

    counternya acak mulainya namun setelah itu berurutan
  • ada beda ...

    awal, pake hterm :
    A1 23 45 67 00 F4 00 00 00 06 00 80 00 00 02 98 00 00 00 09 00 00 00 00 00 00 00 00 00 00 00 00 3F 80 ...
    A1 23 45 67 00 F5 00 00 00 06 00 80 00 00 02 9B 00 00 00 09 00 00 00 00 00 00 00 00 00 00 00 00 3F 80 ...
    A1 23 45 67 00 F6 00 00 00 06 00 80 00 00 02 9E 00 00 00 09 00 00 00 00 00 00 00 00 00 00 00 00 3F 80 ...


    sebelum pake while, hilang 2 byte :
    a1 23 45 67 00 f8 00 00 00 06 00 80 00 00 02 a3 00 00 00 09 00 00 00 00 00 00 00 00 20 00 3f 80 00 00 ...

    pake while cuma hilang 1 byte
    a1 23 45 67 01 08 00 00 00 06 00 80 00 00 02 ce 00 00 00 09 00 10 00 00 00 00 00 00 00 00 00 3f 80 00 ...



    btw, setting bits per seconds nya di set berapa ?
  • oiaaa, pola antara HTERM dan app bergeser...

    baud pakai default 9600, koneksi port serial pakai USB to serial adapter ATEN pak,
    saya jg nyobain bbrp tipe data utk nampung input stream, selain pakai byte juga lagi nyobain pakai char, msh blm sesuai yg diharapkan :(
  • edited November 2014
    .read() itu kalo data yg terbaca sudah habis return nya apa ?
    gw cari rujukan di dokumentasi oracle kagak ketemu

    -1 seingat gw kalo hexa byte itu = 7F atau FF (gw lupa mana yg bener)

    kalo pas data yg masuk beneran ada -1 nya, pasti keluar dari while
    karena dianggap sudah habis

    coba syarat while diganti
    bukan != -1
    tapi != null



    kalo liat data hterm, data 7F itu ada
    tapi hasil yg pake while kagak ada
    yg tanpa while juga kagak ada

    kalo FF, ada semua
  • edited December 2014
    oke Pak @lobster, solved :)

    pertanyaan tambahan nih :) mohon clue-nya Pak...

    bagaimana caranya untuk ambil datanya pak, yg dimulai dgn a1234567.......... dan berakhiran ..... ffffffffffff
    spy bisa disimpan di TXT atau database langsung...? maksud saya sorting data-nya pak. masih mencoba menggunakan REGEX tapi blm sesuai dgn yg diharapkan.

    tks
  • napa kagak coba bikin state machine saja ?
    langsung diproses di java nya sekalian saat capture data yg diterima dari device

    algoritma awal sederhananya begini :

    state1 = 0
    state2 = 0

    IF (data == A1) {
      IF (state1 == 0) { state1 = 1 } ELSE { state1 = 0 }
    }


    IF (data == 23) {
      IF (state1 == 1) { state1 = 2 } ELSE { state1 = 0 }
    }

    IF (data == 45) {
      IF (state1 == 2) { state1 = 3 } ELSE { state1 = 0 }
    }

    IF (data == 67) {
      IF (state1 == 3) { state1 = 4 } ELSE { state1 = 0 }
    }

    IF (state1 == 3) {
      IF (data == FF and state2 >= 0 and state2 < 6) {
        state2 = state2 + 1
      }
      ELSE IF (data == FF and state2 == 6) {
        ...
        ...
        ...
      }
      ELSE {
        ...
        ...
        ...
      }
    }

    yg ... itu coba dipikirkan logikanya
  • maaf baru buka2 lagi hehehe...

    solved pak @lobster makasih ya, kurang lebih kyk state yg diatas, tapi cuma pakai IF ELSE biasa :)
Sign In or Register to comment.