代码库2对象 [英] code library 2 object

查看:79
本文介绍了代码库2对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我已经成功设计了一个代码库来驱动步进电机在不同的控制模式下,

但我有一个问题,如果在进一步的项目我怎么办?需要控制更多的一个步进电机。

是否有一种方法可以将此库转换为c#或c ++中的类对象。但我正在使用ANSI c



提前谢谢

Hello everyone,
I have successfully designed a code library to drive stepper motor in different control mode,
but i have a problem, what if in further projects i need to control more that one stepper motor.
Is there a method to convert this library to object like class in c# or c++. but i am using ANSI c

Thanks in advance

推荐答案

您可以将其转换为C ++类,但是如果你需要在C,C ++和C#中使用它,最好将它保留为C.从C ++访问C库与从C语言中访问C#需要一些额外的工作 [ ^ ],但并不太难。
You could convert it to a C++ class, but if you need to use it from C, C++ and C# it is best to leave it as C. Accessing a C library from C++ is just the same as from ANSI C. Accessing from C# requires a little extra work[^], but is not too difficult.


c code你可以在c ++的类中包装吗? - >静态函数。



c#的唯一方法:你可以尝试构建一个c-dll并从c#中调用它。

c code can you wrap in classes for c++. -> static functions.

The only way in c#: you can try to build a c-dll and call it from c#.

Good luck :-)


如果您正在控制多个电机,那么将代码转换为C ++几乎没有什么好处。您应该可以在C中完成此操作而无需太多更改。



这里有一些清单:

- 确保你的数据不存储在全局和/或静态变量/结构中。

- 让所有API传递一个上下文变量来识别哪个电机(等)正在被控制。



您不需要C ++或C#来执行此操作。这些语言会让你更难以做正确的事情,但你可以用C语言完成所有这些......
If you are controlling more than one motor, then converting your code to C++ will offer little benefit. You should be able to do this in C without much change.

Here are a few things for checklist:
- Make sure that your data is not stored in global and/or static variables/structures.
- Make all of your APIs pass around a context variable identifying which motor (etc.) is being controlled.

You don't need C++ or C# to do this. These languages will push you a little harder to do the right thing but you can do it all in C...


这篇关于代码库2对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆