K8096 connection

Hi! I have a small problem.

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?

ps: I use Free Pascal + Lazarus

Regards, Yuriy

You will need to check before connecting, not while connected

What check?

My current code:

        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;

ps: SMC_ConnectErrorMessage shows error dialog

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.

There is no way to check the abscence or presence of a K8096 by calling any of the methods in the DLL.

SMCConnect will always return True because you are connecting to a valid COM port, which is expected to be of a K8096.

Use the Windows Setup API to check if the VID/PID combination of the port matches with a K8096. Or check the correct port number in Device Manager.

Ok. Thanks for your explanation.

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;

I use yours description for Pascal API (calls)

Still have trouble with checking:

  1. make success connect to SMC K8096

  2. make chek of connection

SMCSetTorque (0,TRUE); // Set torque to ON case SMCGetTorque (0) of TRUE : Writeln ('Success'); FALSE: begin Writeln ('Unsuccess'); end; end;

Despite the state of FALSE (Unsuccess), TORQUE mode is switched on (audible ‘zzzzzz’ from stepper motor).

Could you help me with that trouble?

ps: The same with DEMO…

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.

The same behavior in C++ & C#. But all works Ok in yours MotorDemo.exe
Still waiting your recommendations.

Please make sure that you are checking the correct values for true and false (see also: viewtopic.php?f=3&t=9168).