java - Serial communication (RS232) between two applications on the same computer (serial loop back) -


i have application (app1) just gives input data serial port. don't have external device sends input data through serial port application, want make java application (app2) can communicating through serial port first app (app1) sending input data app1. don't know how can communicating serial ports between 2 applications. it's local network communication socket programming on 127.0.0.1 ip (loop back). know there libraries rxtx , jssc not find loop serial port in documentations. can give me solution? thank you.

simple diagram: |app2| =======(serial communication)======> |app1|

no java content in answer, years of bitter experience...

there's bit more serial communications meets eye if you're used sockets.

null modem cable

you'll need 2 serial ports on computer, 1 each application. need null modem cable join them together. there no internal loopback serial ports, have go via cable.

baud, parity, etc

then have pick baud rate, number of stop bits, , parity use. have how big word - 5, 7 or 8 bits (5 historic, 7 less so, 8 norm these days). these have match either end otherwise applications won't able communicate. each application has set serial port.

handshaking

you have decide handshaking mechanism use - xon/xoff, hardware or none. xon/xoff no if you're sending binary data, needs rx/tx/gnd wires. hardware better if correctly wired , correctly set in applications. lot of crummy cheap usb serial port adapters don't hardware flow control properly. no handshaking @ easiest going, needing rx/tx/gnd, hardest live in software; if 1 application isn't reading whilst other writing, data gets lost.

synchronisation

then have synchronisation problem. have write applications can synchronise each other. if have chosen no handshaking, there's nothing stop app2 sending before app1 ready listen. sure, can start app1 before app2, that's kinda unsatisfactory, , doesn't work if have 2 way communications (data going in both directions). can't start both apps first.

start up

then there's problem if using hardware handshaking in applications, there's no guarantee serial ports set os way before run them. example, may start app2 first, , serial port app1 may saying "clear send" because os has app1's serial port set way before you've had chance run app1. app2 thinks can send , so, before app1 starts up, configures port, , app2 realise it's send data early, , data has been lost.

in short, need synchronisation protocol between apps involved in 2 way communications can sure app other end there , listening.

this lot harder using socket. tcp socket, stacks ensure data flows if there's other end ready read it.

you could have "start now" button on applications' user interfaces. user can tell each application other running , cable plugged in.

conclusions

serial ports more annoying use socket!


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -