Monday, 26 August 2013

Checking if I'm connected to a device

Checking if I'm connected to a device

I'm writing a program to control two devices: a trinamic motor via the
PANDrive PD2-110-42-202 and a frequency counter. I use the boost library.
If the user chooses the correct port number I don't have any difficulties
to connecting with it.
However, if the user enters an incorrect port number and the boost library
doesn't throw an exception, I send a command to check, if I'm really
connected to the device and wait for the response. If the response doesn't
come, I assume that the port number is wrong and show an appropriate
message.
This approach generally works, but not when the user wants to connect with
the port which is already connected to the Intel(R) Active Management
Technology SOL.
When I try to connect to this port for the first few times, the boost
library doesn't throw an exception (which is strange for me, because this
port is used, so it should be opened). What's more, I can't send a command
to this device. When I try to do it, my program freezes. I use the
following function:
boost::asio::write(*port,boost::asio::buffer(cmd.c_str(), cmd.length()));
I don't understand, why it happens. Even if I'm not connected to the right
port, I should be able to send a command.
It happens only when the user wants to connect to this, one, port for the
motor and the frequency counter.
I'm not interested in receiving a valid response in this case, so I also
tried to send an empty command. I'm able to do it, my program doesn't
freeze, but I don't fave any response, even If I'm connected to the right
port.
When I try to connect to this port many times, the boost library throws an
exception, that the port is opened.
Is there any general way to check if I'm connected to the device?
Why can't I send a command to this particular port?

No comments:

Post a Comment