DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: laidabin
今日帖子: 1
在线用户: 2
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 sxbug (太阳雨) ★☆☆☆☆ -
盒子活跃会员
2018/5/28 12:45:08
标题:
请教将C的函数转成delphi的,谢谢 浏览:1289
加入我的收藏
楼主:
  public enum PlcMemory
  {
    DI = 1,
    DQ = 2,
    MR = 3,
    SR = 4,
    DR = 5
  }
  
  public enum DataType
  {
    INT16 = 1,
    UINT16 = 2,
    DINT32 = 3,
    HEX32 = 4,
    REAL32 = 5,
    BIN16 = 6
  }
  
  

  
  public short EntLink(string pcIP, ushort pcPort, string plcIP, ushort plcPort, string SN, int Handle, ushort WaitTime = 2000, bool AscMode = false)
  
  public short DeLink(int Handle)

  
  public short CmdRead(int Handle, PlcMemory Memory, DataType ValType, ushort Address, ushort Count, ref object[] Redata)

  
  public short CmdRead(int Handle, PlcMemory Memory, DataType ValType, ushort Address, ushort Count, ref string[] Redata)

  
  public short CmdWrite(int Handle, PlcMemory Memory, DataType ValType, ushort Address, ushort Count, ref object[] Data)


  public short CmdWrite(int Handle, PlcMemory Memory, DataType ValType, ushort Address, ushort Count, ref string[] Data)

  
  public short Bit_Test(int Handle, PlcMemory Memory, ushort Address, ushort Bit, bool State)
  
  public short Bit_Set(int Handle, PlcMemory Memory, ushort Address, ushort Bit)
  
  public short Bit_Reset(int Handle, PlcMemory Memory, ushort Address, ushort Bit)
  
  public short Bit_Test(int Handle, PlcMemory Memory, ushort BitAdd, bool State)
  
  public short Bit_Set(int Handle, PlcMemory Memory, ushort BitAdd)
  
  public short Bit_Reset(int Handle, PlcMemory Memory, ushort BitAdd)

  
  public int SetDataBit(int Data, short Bit, bool SetVal)
  
  public bool GetDataBit(int Data, short Bit)

  public short DataConvert(PlcClient.DataType SourType, object SourData, PlcClient.DataType DestType, object DestData)
----------------------------------------------
-
作者:
男 sxbug (太阳雨) ★☆☆☆☆ -
盒子活跃会员
2018/5/28 12:46:07
1楼: 请高人帮我将上面的C接口写成PAS版的,谢谢。
----------------------------------------------
-
作者:
男 wang_80919 (Flying Wang) ★☆☆☆☆ -
普通会员
2018/5/28 13:00:12
2楼: 没有写 call 类型。
----------------------------------------------
(C)(P)Flying Wang
作者:
男 sxbug (太阳雨) ★☆☆☆☆ -
盒子活跃会员
2018/5/28 13:48:25
3楼: Delphi 32位 调用。不清楚 flying wang 高人的意思,请明示。谢谢
----------------------------------------------
-
作者:
男 sxbug (太阳雨) ★☆☆☆☆ -
盒子活跃会员
2018/5/28 14:08:19
4楼: 随便写几个也可以,主要是数据结构的定义不会。谢谢
----------------------------------------------
-
作者:
男 bahamut8348 (leonna) ★☆☆☆☆ -
普通会员
2018/5/28 14:10:23
5楼: 带public这种定义明显不是c的。
----------------------------------------------
--
作者:
男 sxbug (太阳雨) ★☆☆☆☆ -
盒子活跃会员
2018/5/28 14:15:06
6楼: VB,那就是VB的接口了。我也不是很清楚
----------------------------------------------
-
作者:
男 wang_80919 (Flying Wang) ★☆☆☆☆ -
普通会员
2018/5/28 14:30:46
7楼: 我不知道,也懒得知道 VB 的 CALL 类型。无法帮你。
----------------------------------------------
(C)(P)Flying Wang
作者:
男 go_on (go_on) ★☆☆☆☆ -
盒子活跃会员
2018/5/28 14:57:46
8楼: type PlcMemory=(
    DI = 1,
    DQ = 2,
    MR = 3,
    SR = 4,
    DR = 5
  );
试试
----------------------------------------------
-
作者:
男 bahamut8348 (leonna) ★☆☆☆☆ -
普通会员
2018/5/28 16:48:39
9楼: 这明显就是c#的语法吧。。。

合着兰州自己都没搞明白状况就来问了么???


另外就是,兰州到底要人翻译什么?就几个方法定义么?
还是要人翻译实际的代码?
要人翻译实际代码那是体力活,没报酬估计找不到人
----------------------------------------------
--
作者:
男 ghs_79 (ghs) ★☆☆☆☆ -
盒子活跃会员
2018/5/28 18:46:40
10楼: 声明类型
type
 PlcMemory =(
    DI = 1,
    DQ = 2,
    MR = 3,
    SR = 4,
    DR = 5
);
  
  DataType =(
    INT16 = 1,
    UINT16 = 2,
    DINT32 = 3,
    HEX32 = 4,
    REAL32 = 5,
    BIN16 = 6
  );

定义方法:
//public short EntLink(string pcIP, ushort pcPort, string plcIP, ushort plcPort, string SN, int Handle, ushort WaitTime = 2000, bool AscMode = false)
    function EntLink(pcIP: string; pcPort: Word;plcIP: string; plcPort: Word; SN: string; Handle: THandle; WaitTime:Word = 2000; AscMode: Boolean = false): ShortInt;
    //public short DeLink(int Handle)
    function DeLink(Handle: THandle): ShortInt;
    //public short CmdRead(int Handle, PlcMemory Memory, DataType ValType, ushort Address, ushort Count, ref object[] Redata)
    function CmdRead(Handle: THandle;Memory: PlcMemory; ValType:DataType; Address, Count: Word; var Redata: array of variant):ShortInt; overload; //variant可以是任何类型
    //public short CmdRead(int Handle, PlcMemory Memory, DataType ValType, ushort Address, ushort Count, ref string[] Redata)
    function CmdRead(Handle: THandle;Memory: PlcMemory; ValType:DataType; Address, Count: Word; var Redata: array of string):ShortInt; overload;
    //public short CmdWrite(int Handle, PlcMemory Memory, DataType ValType, ushort Address, ushort Count, ref object[] Data)
    function CmdWrite(Handle: THandle;Memory: PlcMemory; ValType:DataType; Address, Count: Word; var Redata: array of Variant):ShortInt; overload;
    //public short CmdWrite(int Handle, PlcMemory Memory, DataType ValType, ushort Address, ushort Count, ref string[] Data)
    function CmdWrite(Handle: THandle;Memory: PlcMemory; ValType:DataType; Address, Count: Word; var Redata: array of string):ShortInt; overload;
    //public short Bit_Test(int Handle, PlcMemory Memory, ushort Address, ushort Bit, bool State)
    function Bit_Test(Handle: THandle; Memory:PlcMemory; Address, Bit: Word; State: Boolean): ShortInt; overload;
    // short Bit_Set(int Handle, PlcMemory Memory, ushort Address, ushort Bit)
    function Bit_set(Handle: THandle; Memory:PlcMemory; Address, Bit: Word): ShortInt; overload;
    //public short Bit_Reset(int Handle, PlcMemory Memory, ushort Address, ushort Bit)
    function Bit_reset(Handle: THandle; Memory: PlcMemory; Address, Bit: Word): ShortInt; overload;
    //public short Bit_Test(int Handle, PlcMemory Memory, ushort BitAdd, bool State)
    function Bit_Test(Handle: THandle; Memory:PlcMemory; BitAdd: Word; State: Boolean): ShortInt; overload;
    //public short Bit_Set(int Handle, PlcMemory Memory, ushort BitAdd)
    function Bit_Set(Handle: THandle; Memory: PlcMemory; BitAdd: Word): ShortInt; overload;
    //public short Bit_Reset(int Handle, PlcMemory Memory, ushort BitAdd)
    function Bit_Reset(Handle: THandle; Memory: PlcMemory; BitAdd: Word): ShortInt; overload;
    //public int SetDataBit(int Data, short Bit, bool SetVal)
    function SetDataBit(Data: integer; Bit: ShortInt; SetVal: boolean): Integer;
    //public bool GetDataBit(int Data, short Bit)
    function GetDataBit(Data: integer; Bit: ShortInt): Boolean;
    //public short DataConvert(PlcClient.DataType SourType, object SourData, PlcClient.DataType DestType, object DestData)
    function DataConvert(SourType: DataType; SourData: Variant; DestType: DataType; DestData: Variant): ShortInt;

以上代码不一定全对,仅供参考。
----------------------------------------------
Delphi爱好者。
作者:
男 daisutao ((芒果)) ★☆☆☆☆ -
盒子活跃会员
2018/5/29 8:36:07
11楼: 在楼上的基础上,追加cdcel;
----------------------------------------------
-
作者:
男 sxbug (太阳雨) ★☆☆☆☆ -
盒子活跃会员
2018/5/29 17:00:14
12楼: 谢谢。我也试一下,谢谢
----------------------------------------------
-
作者:
男 lovezyp (小焱~) ★☆☆☆☆ -
盒子活跃会员
2018/5/31 16:41:17
13楼: 翻译没问题,但是不一定能用
----------------------------------------------
我爱Delphi,永远的Delphi,哪怕Delphi淘汰了,出局了,被世人淡忘了我也爱,除非我死了否则就是爱Delphi
作者:
男 epzybook (epzybook) ★☆☆☆☆ -
普通会员
2018/5/31 16:49:15
14楼: 推荐你这个东东  

https://blog.grijjy.com/2018/05/29/chet-a-c-header-translator-powered-by-clang/
----------------------------------------------
-
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行76.17188毫秒 RSS