When I use SMCConnect (PChar(ComPortName),1), it return TRUE for almost any existing COM-port. However, I would like to be able to verify that it is connected K8096. I tried to add a check on SMCGetMotorCount and SMCGetInputCount, but they also return TRUE.
Can you suggest some sort of procedure for checking the connection?
if SMCConnect (PChar(ComPortName),1) then
if SMCConnected then
if SMCGetMotorCount = 1 then
if SMCGetInputCount = 5 then begin
// Show success connect
end else SMC_ConnectErrorMessage
else SMC_ConnectErrorMessage
else SMC_ConnectErrorMessage
else SMC_ConnectErrorMessage;
Some notes about your code:
[ul][li]The motor count will always be 1 and the input count will always be 5 for the K8096, so you are effectively checking values that never change.[/li][li]If SMCConnect returns True, you do not need to check again if you are connected (because you are) with SMCConnected.[/li][/ul]
if SMCConnect(PChar(ComPortName), 1) then
begin
// OK
end else
SMC_ConnectErrorMessage;
There is no way to check the connection by calling any of the methods in the DLL.
The only way I know possible is by using the Windows Setup API to check if the VID/PID combination of the port matches with a K8096. And of cource, this will be a complex piece of code.
Re-read upper: when I use SMCConnect (PChar(ComPortName),1), it return TRUE for almost any existing COM-port. Not only for SMS. So I tried to add additional checks. The failure of determining the presence-absence of SMC on the COM-port has brought me with this question on your forum.
Checking combination of VID/PID is not as easy as would like.
Therefore, an alternative method was used:
if SMCConnect (PChar(ComPortName),1) then begin
// SMC сhecking by torque enabling
SMCSetTorque(1,TRUE);
// 'shhhh' pause, ornamentally
Sleep (2000);
if SMCGetTorque (1) then begin
// Show success connect here
// and disabe torque
SMCSetTorque(1,FALSE);
end else SMC_ConnectErrorMessage
end else SMC_ConnectErrorMessage;
Could you make any comments for boolean status getting problem?
I do not want to use visual studio.
It is advisable to write a program using Free Pascal.