Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    juzweb
    @juzweb
    1. I am able to send message command to the sms modem
    1. however, I am not able to receive the serialevent from the modem
    I wonder if anyone experience this issue.
    This is my initialize code :
    public void initialize() {
    LOGGER.info("SMS : Initializing...");
    try {
    Enumeration<CommPortIdentifier> ports = CommPortIdentifier.getPortIdentifiers();
    LOGGER.info("Ports has more element: " + ports.hasMoreElements());
    while (ports.hasMoreElements()) {
    LOGGER.info("In Loop : ");
    String _port = ports.nextElement().getName();
    if ("COM4".equals(_port)) {
    serial = new NRSerialPort("COM4", 9600);
    serial.connect();
    serial.notifyOnDataAvailable(true);
    serial.addEventListener(this);
                    br = new DataInputStream(serial.getInputStream());
                    bw = new BufferedWriter(new OutputStreamWriter(
                            serial.getOutputStream()));
    
                }
            }
        } catch (Exception ex) {
            LOGGER.info(ex.toString());
        } catch (Error er) {
            LOGGER.info(er.toString());
        }
        LOGGER.info("SMS : Finish Initialization.");
    }
    this class extends SerialPortEventListener
    public class SMSWorker implements SerialPortEventListener
    Below is my serialEvent method:
    @Override
    public void serialEvent(SerialPortEvent event) {
    // TODO Auto-generated method stub
    LOGGER.info("XXXXXXXXXXXXX EVENT HAPPEN XXXXXXXXXXXXX"
                + event.getEventType());
        if (event.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
            LOGGER.info(" SMS : DATA AVAILABLE");
            try {
                int available = br.available();
                if (available > 0) {
                    byte data[] = new byte[available];
                    br.read(data);
    
                    StringBuffer mybuf = new StringBuffer();
                    for (int i = 0; i < data.length; i++) {
                        buffer.append((char) data[i]);
                        mybuf.append(String.valueOf(data[i]) + " ");
                    }
                    LOGGER.info("SMS DATA : " + mybuf.toString());
                    LOGGER.info(" SMS: BUFFER : " + buffer.toString());
                    processBuffer();
                }
            } catch (Exception e) {
                LOGGER.info(" SMS : ERROR IN SERIAL EVENT : " + e.toString());
            }
        } else {
            LOGGER.info("OTHER EVENT OCCUR");
        }
    }
    Problem : It did not print the message LOGGER.info("XXXXXXXXXXXXX EVENT HAPPEN XXXXXXXXXXXXX" + event.getEventType());
    When I close down this application, and connect PUTTY to the port, PUTTY will consume the Write Buffer.
    Is there anything wrong that can come to your mind?
    Thanks.
    juzweb
    @juzweb
    BTW, this Component is called by a Controller. after calling it I did have a pause on the main thread, such as :
    @RequestMapping(value = "/sms/test", method = RequestMethod.POST)
    public String testSms() {
        SMSWorker worker = new SMSWorker();
    
        if (worker.isConnected()) {
            worker.sendSMS("Hello from smartLED");
        } else {
            worker.initialize();
            if (worker.isConnected()) {
                worker.sendSMS("Hello from smartLED");
            } else {
                LOGGER.info("SMS fail to connect after initialize.");
            }
        }
    
        try {
            Thread.currentThread().sleep(20000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    
        return "sms/testSms";
    }
    Kevin Harrington
    @madhephaestus
    Yeah, i have heard other people compain about inconsistsnt event listener behavior
    it seems to depend on how your driver interfaces with the serial port at the OS level. The method that always works is to make your own polling/loading thread
    get the stream and use the stream interface for accessing bytes is the best method for critical timing over a serial port.
    stream class manages the publisher/subscriber problem. By making a SINGLE thread that talks to the port, then managing multiple threads at your packet level ensures partial packet read faults do nto happen
    juzweb
    @juzweb
    Thanks Kevin for the reply. I will give it a try. Just information sharing, I have tried on JSSC, my previous implementation logics works perfectly with that lib.
    cR0Ckr0x
    @cR0Ckr0x
    Hello, I am trying to implement a simple writer to my arduino nano board, I want to send "1" or "0"
    After including the library using maven , I get this when connecting: java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path
    I'd like to point out I am using nrjavaserial because I read about this updated fork with x64 version of rxtxSerial. So where do I get it?
    Kevin Harrington
    @madhephaestus
    you need to make sure rxtxSerial is fullly removed from the system, this is a fork and conflicts with the old and unupdated binaries of 2.2
    you get that error when you are either using the rxtx jar, or something in your code of build or install has placed the rxtxserial binary in the classpath. nrjavaserial uses a different binary name, so it most likely seems like you have the legacy rxtx bundled into your application, or included a jar that has it bundeled in there.
    Dylan Vorster
    @dylanvorster
    hey guys
    is anyone here available to talk about a possible issue regarding threaded usage of this library?
    Kevin Harrington
    @madhephaestus
    Hello
    what sort of thread usage issues are you having @dylanvorster ?
    Dylan Vorster
    @dylanvorster
    Nevermind, got it all sorted :)
    Janne Valkealahti
    @jvalkeal
    threading issues with serial interface, that can't ever happen :)
    I've never understood how thread safe this codebase is.
    Kevin Harrington
    @madhephaestus
    You should not assume this library is thread safe.
    Steven Riedl
    @riedlse
    Would like to make a small mod to allow parity to be set, either on connect by having multiple versions (could make baud rate default, parity, may be good to add data and stop bits at the same time) I haven't really contributed to a public library, so what works for this? pull, change, test, merge request or something like that?
    Janne Valkealahti
    @jvalkeal
    U should try to do PR against github repo.
    Jason Liu
    @Jason84Liu_twitter
    hey, does nrjavaserial need any dlls?
    Janne Valkealahti
    @jvalkeal
    yes, DLLs for win and SOs for linux. this just tries to automate loading of those libs.
    Ricardo Andere de Mello
    @quilombodigital
    hi... I have a question... I need to implement 9 bit communication. I know I can do this in linux using native MARK/SPACE/PARITY hacking, and in windows using a specific driver, but not the windows serial driver, since it is 8 bit only. Can I use the nrjavaserial to solve this issue? does it allows access to the mark/space/parity? does it uses the windows serial driver, or bypasses it?
    Kevin Harrington
    @madhephaestus
    the windows dll used the windows serial rdiver nuder the hood
    Ricardo Andere de Mello
    @quilombodigital
    hum... ok... so I guess it will not work... thanks...
    Kevin Harrington
    @madhephaestus
    np :)
    thigg
    @thigg
    Hey, I'm trying to run your lib under a current arch linux and am running into the /var/lock issue. What do you suggest to do?
    Kevin Harrington
    @madhephaestus
    there is a dep of the lockfile library, im not sure what its called in arch...
    -DLIBLOCKDEV has to exist
    er, -llockdev must exist
    in the system library path
    https://www.archlinux.org/packages/community/x86_64/lockdev/ i think...? again, im not super familiar with arch
    BritP
    @pairforce1_twitter
    Hi. I am running into an issue running nrjavaserial 5.1. in ubuntu core 18. Lock and tmp files are attempting to be created in /run/lock which is restricted on ubuntu core. Is there a way to change this location? Either to /var/lock or even to a subdirectory inside /run/lock like /run/lock/lockdev?
    4 replies
    AntaoCai
    @AntaoCai
    I use nrjavaserial 5.1.1, after typing into a jar package with maven, use java -jar xxx.jar. A java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path appears. But I can use the idea to run.