tags:

views:

80

answers:

6

Hi Guys,

I am writing an application which need to send data to a Serial Device attached to COM Port. I am just confuse what is the best way to deal with such device?

shall i write the communication module in C++ or shall i write this in JAVA?

I want to run the application on Windows as well as Linux.

+1  A: 

COM port is just a plain bit pipe. The APIs are expected to be fairly simple. In C++, the world has much more experience with writing to ports.

Other question would be - do you know what port number it is? There're several ways to find out which one is yours, like setup API on windows.

Pavel Radzivilovsky
SOrry to interrupt, but i think his application is multi operating system based... C++ has big minus in this scenario!
thatsalok
@thatsalok: I disagree. I always made multi-operating system C++ software that uses COM ports. `C++` is perfectly suitable for that task.
ereOn
A: 

My suggestion, if you want to run you application in both linux and Windows, go for JAVA!. you can run your program without any need of compilation. otherwise you have to distribute seperate binary for both Windows and Linux.

Also programming model in both windows and linux for accessing SerialPort in C++, As i am preliminary a Windows C++ developer, you can use CreateFile WIn32 Api to access serial port.

thatsalok
Which serial comms library would you expect to work on Linux and Windows with a single binary?
Jon Skeet
I haven't about any! thats why recommended JAVA for cross plateform development.There is something called minigw, but still you have compile your application!
thatsalok
+2  A: 

You can write the module in c++ by specyfying the #ifndef "_WINDOWS_CODE" for windows code and else part for the linux code.

while compiling in Vc++ put the (_WINDOWS_CODE)macros in the projecty settings and in gc++ remove the macro from project file

Dharma
+2  A: 

On Linux I would recommend libserial. You could also consider using Python. There is a multi platform pySerial module. If you decide for Java, rxtx is a multi platform library. On Windows you may use the Windows API for serial communications and combine it with libserial using #ifndef as @Dharma suggested.

zoli2k
I've used rxtx cross-platform in the past and it worked fine.
Catchwa
+2  A: 

I recommend you:

Boost ASIO

QextSerialPort (based on Qt)

Ricardo Muñoz
A: 

shall i write the communication module in C++ or shall i write this in JAVA?

Which are you more familiar with? Are you limited to these two languages? You could also use python with pyserial.

Are you doing this as a personal project? Is it for work? Is someone else working on this with you? What are they more familiar with?

For C++ you could use Boost.Asio.

For Java ... I don't know.

utnapistim