Reputation: 1830
I need to integrate my REST (Jersey) and serial port communication. I have now problem with handling server actions. Basically I am using the RXTXcomm.jar library and open port directly in (parameters for serial port are hardcoded):
public class ApplicationConfig extends Application {
public ApplicationConfig () {
// init serial port here
}
}
My problems:
Thanks.
I don't want to pass a data via HTTP requests. Just use some parameter, and later fill serial data internally inside REST resource. Request will be very rare and from one 'client' only.
Upvotes: 0
Views: 1310
Reputation: 5919
If you implement a ServletContextListener
you can initialize your init class just as the server starts.
ServletContextListener
has a contextInitialized(javax.servlet.ServletContextEvent)
method which gets called when the server starts, which you can override to initialize your init class.ServletContextListener
has a contextDestroyed(javax.servlet.ServletContextEvent)
which gets called when the server stops, and you can override it to close your port.Upvotes: 1
Reputation: 11
I would imagine there could be a potential problem, if second request is made while the first is still writting to the serial port.
You could create a standalone application that would receive data over tcp/ip (or named pipes or other means of ipc), buffer it in queue and send it forward to serial port.
Upvotes: 1