I have a SMC 24v12 and want to readout the limit switch values from analog 1&2. I saw the “SmcVariables” in the Protocol.cs and the smc.cs, but don’t know/get them to work. How is this done (I prefer some code snippet).
Can anybody help me with this problem?
For others following this discussion, I just want to clarify that you are using the Pololu USB SDK for the Simple Motor Controller (SMC).
The method you should be looking at is
getSmcVariables in Smc.cs. If you looked at the function definition for
getSmcVariables in the source code, you will see that it returns a struct of type
SmcVariables, which is defined in Protocol.cs. The
SmcVariables struct represents the current state of the SMC, including all input channels (e.g.
analog2) and motor limits. I recommend looking at the source code of SmcCmd, in particular the
printChannelStatus functions, to get an idea on how to read the channel inputs.
I already did that, but I can’t figure it out. How do I call printChannelStatus in the SmcExample1 program? I’m just began programming in c#, please help my futher.
To extract the current state of an input channel (e.g. analog1) on the SMC, you would do the following:
SmcVariables vars = device.getSmcVariables();
SmcChannelVariables analogInput1 = vars.analog1;
printChannelStatus is a function defined in the SmcCmd program, which is completely separate from the SmcExample1 program. You would need to literally copy and paste the function code, then make the necessary modifications to get it to work in the SmcExample1 program.
Since you are having a difficult time understanding the program structure of the SDK for the SMC, it sounds like you might be new to programming, in general, and not just the C# language. I strongly suggest that you learn and understand C# before making any changes to the SmcExample1 program. You can find many online C# tutorials like this one from tutorialspoint.
Thank you. That was the code I was looking for. Now I can read the status of the limitswitches.