首页 新闻 搜索 专区 学院

C#下如何获取485口通讯句柄?

0
悬赏园豆:50 [已解决问题] 解决于 2014-04-18 08:02

C#下如何获取485口通讯句柄?不知道怎么获取,求大神助力啊

Dranched的主页 Dranched | 初学一级 | 园豆:23
提问于:2014-04-15 09:46
< >
分享
最佳答案
0

建议给出完整DLL文档,比较好判断具体的调用规则,

否则不清楚你需要的通讯口句柄到底是传入还是传出,是DLL中已有API生成该句柄还是需要C#生成该句柄传入。

收获园豆:50
hailants | 小虾三级 |园豆:750 | 2014-04-15 11:06

海盐盛迪装置通讯dll函数使用说明
目录
================
1、安装说明
2、函数调用说明
3、特别说明
4、调用举例
================
1、安装说明
可把hscom.dll拷贝至system32目录下也可放在你的程序目录下
2、函数调用说明
文件名 : hscom.dll
函数名 说明 参数
========================================================================================
Adjust_UI : 负载点调整 Phase , Rated_Volt , Rated_Curr , Rated_Freq , PhaseSequence ,
Revers , Volt_Per , Curr_Per ,IABC,CosP , SModel , Dev_Port
Adjust_CUST : 负载点调整(可任意设定,四线状态) Phase , Rate_Freq , Volt1 , Volt2 , Volt3 , Curr1 , Curr2 , Curr3 ,
Uab , Uac , Ang1 , Ang2 , Ang3 , SModel , Dev_Port
Set_Harmonic_Data: 设置输出谐波数据 HAng , HNum ,HVolt , HCur
StdMeter_Read : 指示仪表读取 SData , SModel , Dev_Port
Set_485_Channel : 485通道切换(只单个通道吸合) Meter_No , Open_Flag , Dev_Port
Set_485_ChannelS : 485通道切换(可多个通道吸合) Meter_No , Open_Flag , Dev_Port
Set_Pulse_Channel: 脉冲采样通道切换 Meter_No , Channel_Flag , Dev_Port
Error_Start : 开始测试误差 Meter_No , Constant , Pulse , Dev_Port
Error_Read : 误差读取 MError , Meter_No , Dev_Port
Dll_Port_Close : 关闭与装置通讯的串口
----------------------------2008.04.03新增----------------------------------
Search_mark :开始寻标 Meter_No,Dev_Port
Search_mark_Result: 读取寻标脉冲 Meter_No,Dev_Port
CRPSTA_start :开始潜动或起动 Meter_No,Dev_Port
CRPSTA_Result :潜动或起动脉冲读取 Meter_No,Dev_Port
CRPSTA_clear :潜动或起动状态复位 Meter_No,Dev_Port
Error_Clear :误差仪总清 Dev_Port
Power_Off :降电压电流 Dev_Port
Power_Pause :降电流,电压保持 Dev_Port
----------------------------2008.04.03新增(常数校核)----------------------------------
ConstTest_Start :开始常数校核 Meter_No , Constant , Dev_Port
ConstPulse_Read :读取常数校核电量 MeterKWH , StdKWH , Constant , Meter_No , Dev_Port
//-------------------------BB3100标准表增强专用函数-------------------------Set_BB3100_Baud :设置BB3100的通讯波特率 SMBaud
Comm_BB3100_All :读取标远表测量数据 SData,SendCmd,WaitBAck,SModel,Dev_Port
StrToFloat_BB3100 :BB3100的10进制浮点数转换 CStr
----------------------------2008.05.22新增(电表试验台专用)--------------------------------Set_VoltPara :设置缓升缓降参数 UpTimd,FullTime,DownTime,LowTime,LowValue,TestTimes
VoltFall :电压跌落命令 Dev_Port,ErrAddr,ZeroTime,FullTime,FallTimes
----------------------------2008.08.01新增(高压装置专用)----------------------------------Set_HMC_CT1 :设置高压表1次侧CT额定电流值 RateValue,Dev_Port
Set_HMC_New :设置新高压表装置用以判断标准表切换档位 NewValue
----------------------------2008.09.18新增(485表通讯)----------------------------------Open485CommPort:打开485通讯口 LngHdcComm , BaudRate , Meter_Port
Set485CommPort :更改485口波特率 LngHdcComm , BaudRate
Close485CommPort:关闭485通讯口 LngHdcComm
Send485Data :发送485数据(16进制) LngHdcComm , MeterData
Recv485Data :接收485数据(16进制) LngHdcComm , MeterData , recv_len
----------------------------2008.11.28新增(自定义谐波)----------------------------------SetHarmValue :设置自定义谐波含量值(可多次调用) UIChannel , HarmNum , HarmValue , HarmAng
----------------------------2009.02.06新增----------------------------------SelectCircuit :选择电流回路 CircuitNo , Dev_Port
CutNeutral :断零线 CuttingFlag , Dev_Port
----------------------------2010.03.04新增----------------------------------SetRefClock :标准时钟仪切换 SetFlag , Dev_Port
Clock_Error_Start:开始测试时钟误差 Meter_No , TheoryFreq , TestTime , Dev_Port
Clock_Error_Read:读取时钟误差 MError , TheoryFreq , ErrorType , Meter_No , Dev_Port
----------------------------2010.04.01新增----------------------------------Set_OutPutMode : V型输出 IsVMode
Adjust_UI2 : 负载点调整(三相电压电流可分别设置) Phase , Rated_Volt , Rated_Curr , Rate_Freq , PhaseSequence ,
Revers ,Volt_Per1 , Volt_Per2 , Volt_Per3 , Curr_Per1 ,
Curr_Per2 , Curr_Per3 , IABC , CosP , SModel , Dev_Port
----------------------------2010.05.17新增----------------------------------Adjust_UI3 : 负载点调整(可以直接付值角度) Phase,Rate_Freq,PhaseSequence,Revers,Volt,Curr,IABC,COSP(角度),
SModel,Dev_Port
----------------------------2010.06.10新增----------------------------------Adjust_UI4 : 负载点调整(三相电压电流可分别设置) Phase , Rated_Volt , Rated_Curr , Rate_Freq , PhaseSequence ,
(可以直接付值角度) Revers ,Volt_Per1 , Volt_Per2 , Volt_Per3 , Curr_Per1 ,
Curr_Per2 , Curr_Per3 , IABC , COSP(角度) , SModel , Dev_Port
----------------------------2011.06.25新增----------------------------------SetStdFreq : 设置时钟仪高频频率 StdFreq
----------------------------2011.08.03新增----------------------------------Set_ReviseMode :小电流修正方式 ReviseMode
----------------------------2012.03.13新增----------------------------------Set_ReviseTime :源修正等待时间(不调用时默认5s) ReviseTime
----------------------------2012.05.24新增----------------------------------Count_Start :误差仪计数开始 Meter_No , Dev_Port
Count_Read :误差仪累计脉冲读取 MPulse , Meter_No , Dev_Port
参数说明:
Dev_Port : 装置通讯口 如:COM1则为1,COM2为2,...
Phase : 相线
0 单相
1 三相四线有功
2 三相三线有功
3 90度无功
4 60度无功
5 四线正弦无功
6 三线正弦无功
7 单相无功
Rated_Volt : 被校表额定电压 如220V 则为220
Rated_Curr : 被校表额定电流 如1.5(6)A则为1.5
Rated_Freq : 被校表额定频率,范围45~65
PhaseSequence: 相序 0-正相序 1-逆相序
Revers : 电流方向 0-正相 1-反相
Volt_Per : 负载点电压百分数 100表示100%
Curr_Per : 负载点电流百分数 100表示100%
IABC : 负载点合分元 H-合元 A-分A B-分B C-分C
CosP : 负载点功率因数 取值:1.0 0.5L 0.8C ....
HNum : 谐波次数 (3、5、7次可任意叠加,传送时高次在前,其它次数只能发送单次,且放在第一位)
HAng : 谐波相位
HVolt : 电压谐波含量(总含量不能超40%)
HCur : 电流谐波含量(总含量不能超40%)
Volt1 , Volt2 , Volt3 : A、B、C三相电压值(V)
Curr1 , Curr2 , Curr3 : A、B、C三相电流值(A)
Uab , Uac : Ua和Ub的夹角,Ua和Uc的夹角
Ang1 , Ang2 , Ang3 : A、B、C三相的电压电流夹角(°)
SModel : 装置配置的标准表型号 如:HY5303C-22 BB3100 等,按照校验系统设置里的表达方式
三相装置: HY5303C-22 、HS5300 、HS5320 、TC-3000D(便携式内置)
单相装置: HY5101C-22 、HY5101C-23 、HS5100 、TC-3000C(便携式内置)
SData : 指示仪表返回数据
Meter_No : 挂表位,1..96
Constant : 被校表常数
Pulse : 校验时采样圈数
Channel_Flag: 脉冲采样通道 0-有功正向/反向,1-有功反向,2-无功正向/反向,3-无功反向,4-时钟,5-投切,6-需量
单相表误差脉冲通道一般发0即可,正反向都在同一个端子输出。
Open_Flag : 485通道切换状态 1-吸合 0-断开
MError : 误差读取返回误差数据
//2008.09.04
MeterKWH : 电表走字量
StdKWH : 标准表走字量
//BB3100标准表增强专用函数
SMBaud : 标准表波特率
SendCmd : 下发命令
WaitBAck : 是否等待应答并返回应答数据
//2008.05.22新增
UpTime : 电压上升时间 (0.01~999.9s)
FullTime : 电压保持时间 (0.01~999.9s)
DownTime : 电压下降时间 (0.01~999.9s)
LowTime : 低值电压保持时间 (0.01~999.9s)
LowValue : 电压低值
TestTimes : 试验次数 ( 1~9999)
ErrAddr : 控制地址
ZeroTime : 跌落保持时间 (0.1~6000s)
FullTime : 电压恢复保持时间 (0.1~6000s)
FallTimes : 跌落次数 ( 1~10000)
//2008.08.01新增
RateValue : 高压表CT1次侧额定电流值
//2008.09.18
LngHdcComm : 485通讯口句柄 ,也可以LongWord型
BaudRate : 波特率,如 1200,e,8,1
Meter_Port : 485通讯口 如:COM1则为1,COM2为2,...
recv_len : 接收数据长度(实际接收字符的2倍,1个字节为2位)
MeterData : 接收数据,16进制ASCII表示,如Chr(13)Chr(10)回车和换行2个字符 ,则为0D0A
//2008.11.28
UIChannel : 谐波通道 UI、U、I
HarmNum : 谐波次数
HarmValue : 谐波含量值
HarmAng : 谐波初始相角
//2009.02.06
CircuitNo : 回路号0(1-2)、1(4-3)、2(1-2-4-3) 3(1-4)、4(3-2)、5(1-4-3-2)、6(3-4)
CuttingFlag : 断零线标志0--不断 1--断
NewValue : 新高压装置 False--老装置 True--新装置
//2010.03.04
SetFlag : 切换标志 0--切开 1--切上
TheoryFreq : 被校表时钟理论输出频率(Hz)
TestTime : 测试时间(s)
ErrorType : 时钟误差返回类型 0--频率(Hz) 1--日计时误差(s/d) 2--相对误差(%)
IsVMode : True-V型输出 False-Y型输出
Volt_Per1,Volt_Per2,Volt_Per3:负载点电压百分数 100表示100%
Curr_Per1,Curr_Per2,Curr_Per3:负载点电流百分数 100表示100%
COSP : 功因对应的角度,如0,30,60
//2011.06.25
StdFreq : 时钟仪内部高频频率,单位kHz,取值:50 , 250
ReviseMode : 0--不修正 1--正常修正 2--精确修正(带扩展CT装置) 3--精确修正(不带扩展CT的非便携式装置)
ReviseTime : 取值范围 >4.5
//2012.05.24
MPulse : 表累计脉冲数
每个函数返回都是布尔型,返回True表示成功,False表示失败。
3、特别说明
a) 指示仪表读取返回格式(","分隔,有功功率单位W,无功功率单位var,视在功率单位VA):
三相:
Ua,Ub,Uc,Ia,Ib,Ic,φa,φb,φc,有功功率(总),无功功率(总),视在功率(总)
注:
TC-3000表返回 Ua,Ub,Uc,Ia,Ib,Ic,φa,φb,φc,Pa,Pb,Pc,Qa,Qb,Qc,Sa,Sb,Sc,有功功率(总),无功功率(总),视在功率(总),频率,{电压档位},电流档位
TC-6300表返回 Ua,Ub,Uc,Ia,Ib,Ic,PFa,PFb,PFc,Pa,Pb,Pc,Qa,Qb,Qc,Sa,Sb,Sc,有功功率(总),无功功率(总),视在功率(总),功因(a,b,c,总),Uab,Uac
BB3100表返回 Ua,Ub,Uc,Uab,Ubc,Uca,Ia,Ib,Ic,φa,φb,φc,有功功率,无功功率,视在功率, 频率
HS5320表返回 Ua,Ub,Uc,Ia,Ib,Ic,(ΦUaUb) (ΦUaUc) (ΦUaIa) (ΦUaIb) (ΦUaIc) ,有功功率(a,b,c,总),无功功率(a,b,c,总),
视在功率(a,b,c,总), 频率,功因(a,b,c,总)
HY5303表返回 Ua,Ub,Uc,Ia,Ib,Ic,φa,φb,φc,Pa,Pb,Pc,Qa,Qb,Qc,Sa,Sb,Sc,有功功率(总),无功功率(总),视在功率(总),频率,
功因(a,b,c,总),ΦUab,ΦUbc
HS5300/5302表 Ua,Ub,Uc,Ia,Ib,Ic,φa,φb,φc,Pa,Pb,Pc,Qa,Qb,Qc,Sa,Sb,Sc,有功功率(总),无功功率(总),视在功率(总),频率,
功因(a,b,c,总),ΦUab,ΦUbc
单相:
HY5101C-22 U,I,φ
HY5101C-23 U,I,φ,有功功率,无功功率,视在功率,频率
HS5100/5102 U,I,φ,有功功率,无功功率,视在功率,频率
b) 误差采样流程说明:
脉冲采样通道切换--> 负载点调整-->开始测试误差-->误差读取
相关函数:
Set_Pulse_Channel:脉冲采样通道切换
Error_Start :开始测试误差
Error_Read :读取误差
c) 误差返回格式:
次数+","+误差 如2,-0.024 表示误差为-0.024,是第二次误差,第0次误差表示误差还没有,需要丢弃。
d) 寻标流程说明:
发开始寻标命令-->负载点调整(A相,最大电流<=5A)-->循环读取检查寻标是否结束
e) 潜动或起动流程说明:
发潜动或起动开始命令-->负载点调整--> 循环读取潜动或起动脉冲是否到来
可通过CRPSTA_clear复位潜动或起动状态,重新采样试验脉冲,可做多脉冲试验
f)误差仪总清 Error_Clear
误差仪退出试验状态,返回显示表位号。建议每项试验结束后调用。
g)日计时误差采样流程说明(2010.03.04):
脉冲采样通道切换--> 负载点调整(可只升电压)-->切上标准晶振-->开始测试时钟误差-->误差读取 ...>结束后切开标准晶振
相关函数:
Set_Pulse_Channel:脉冲采样通道切换
SetRefClock :标准时钟仪切换
Clock_Error_Start:开始测试时钟误差
Clock_Error_Read :读取时钟误差
Delphi声明:
Function Adjust_UI(Phase:Integer;Rated_Volt,Rated_Curr,Rated_Freq:Double;
PhaseSequence,Revers:Integer;
Volt_Per,Curr_Per:Double;IABC,CosP:PChar;
SModel:PChar;Dev_Port:Byte):Boolean;stdcall;external 'hscom.DLL';
Function Adjust_CUST(Phase:Integer;Rate_Freq:Double;
Volt1,Volt2,Volt3,Curr1,Curr2,Curr3:Double;
Uab,Uac,Ang1,Ang2,Ang3:Double;
SModel:PChar;Dev_Port:Byte):Boolean;stdcall;external 'hscom.DLL';
Procedure Set_Harmonic_Data(HAng:Array of Double;HNum:Array of Integer;HVolt,HCur:Array of Double);stdcall;external 'hscom.DLL';
说明:所有参数为三维数组,在升源命令前调用
举例:Set_Harmonic_Data([0,0,0],[7,3,5],[0,0,0],[10,15,30])
Function StdMeter_Read(var SData:Pchar;SModel:PChar;Dev_Port:Byte):Boolean;stdcall;external 'hscom.DLL';
Function Error_Read(var MError:PChar;Meter_No,Dev_Port:Byte):Boolean;stdcall;external 'hscom.DLL';
Function Error_Start(Meter_No:Integer;Constant:Double;Pulse:Integer;Dev_Port:Byte):Boolean;stdcall;external 'hscom.DLL';
Function Set_Pulse_Channel(Meter_No,Channel_Flag,Dev_Port:Byte):Boolean;stdcall;external 'hscom.DLL';
Function Set_485_Channel(Meter_No,Open_Flag,Dev_Port:Byte):Boolean;stdcall;external 'hscom.DLL';
----------------------------2008.04.03新增----------------------------------
Function Search_mark(Meter_No,Dev_Port:Byte):Boolean;stdcall;external 'hscom.DLL';
Function CRPSTA_start(Meter_No,Dev_Port:Byte):Boolean;stdcall;external 'hscom.DLL';
Function CRPSTA_clear(Meter_No,Dev_Port:Byte):Boolean;stdcall;external 'hscom.DLL';
Function Search_mark_Result(Meter_No,Dev_Port:Byte):Boolean;stdcall;external 'hscom.DLL';
Function CRPSTA_Result(Meter_No,Dev_Port:Byte):Boolean;stdcall;external 'hscom.DLL';
Function Error_Clear(Dev_Port:Byte):Boolean;stdcall;external 'hscom.DLL';
Function Power_Off(Dev_Port:Byte):Boolean;stdcall;external 'hscom.DLL';
Function Power_Pause(Dev_Port:Byte):Boolean;stdcall;external 'hscom.DLL';
procedure Dll_Port_Close;stdcall;external 'hscom.DLL';
//-------------------------BB3100标准表增强专用函数---------------------------Procedure Set_BB3100_Baud(SMBaud:Integer);stdcall;external 'hscom.DLL';
Function Comm_BB3100_All(var SData:PChar;SendCmd:PChar;WaitBAck:Boolean;SModel:PChar;Dev_Port:Byte):Boolean;stdcall;external 'hscom.DLL';
Function StrToFloat_BB3100(CStr:PChar):Double;stdcall;external 'hscom.DLL';
//-------------------------2008.05.22新增-------------------------------------Function VoltFall(Dev_Port,ErrAddr:Byte;ZeroTime,FullTime:Double;FallTimes:Integer):Boolean;stdcall;external 'hscom.DLL';
Procedure Set_VoltPara(UpTimd,FullTime,DownTime,LowTime,LowValue:Double;TestTimes:Integer);stdcall;external 'hscom.DLL';
//-------------------------2008.08.01新增-------------------------------------Function Set_HMC_CT1(RateValue:Integer;Dev_Port:Byte):Boolean;stdcall;external 'hscom.DLL';
Function Set_HMC_CT2(RateValue:Integer):Boolean;stdcall;external 'hscom.DLL';
//-------------------------2008.09.04新增-------------------------------------Function ConstTest_Start(Meter_No:Byte;Constant:Double;Dev_Port:Byte):Boolean;stdcall;external 'hscom.DLL';
Function ConstPulse_Read(var MeterKWH:Double;var StdKWH:Double;Constant:Double;Meter_No,Dev_Port:Byte):Boolean;stdcall;external 'hscom.DLL';
//-------------------------2008.09.18新增-------------------------------------
Function Open485CommPort(var LngHdcComm:THandle;BaudRate:PChar;Meter_Port:Byte):Boolean;stdcall;external 'hscom.DLL';
Function Close485CommPort(var LngHdcComm:THandle):Boolean;stdcall;external 'hscom.DLL';
Function Set485CommPort(var LngHdcComm:THandle;BaudRate:PChar):Boolean;stdcall;external 'hscom.DLL';
Function Send485Data(LngHdcComm:THandle;MeterData:PChar):Boolean;stdcall;external 'hscom.DLL';
Function Recv485Data(LngHdcComm:THandle;var MeterData:PChar;recv_len:Integer):Boolean;stdcall;external 'hscom.DLL';
//-------------------------2008.11.28新增-------------------------------------
procedure SetHarmValue(UIChannel:Pchar;HarmNum:Integer;HarmValue,HarmAng:Double);stdcall;external 'hscom.dll';
//-------------------------2009.02.06新增-------------------------------------
Function SelectCircuit(CircuitNo,Dev_Port:Byte):Boolean;stdcall; external 'hscom.DLL';
Function CutNeutral(CuttingFlag,Dev_Port:Byte):Boolean;stdcall; external 'hscom.DLL';
//-------------------------2010.03.04新增-------------------------------------
Function SetRefClock(SetFlag,Dev_Port:Byte):Boolean;stdcall; external 'hscom.DLL';
Function Clock_Error_Start(Meter_No:Byte;TheoryFreq:Double;TestTime:Integer;Dev_Port:Byte):Boolean;stdcall; external 'hscom.DLL';
Function Clock_Error_Read(var MError:PChar;TheoryFreq:Double;ErrorType,Meter_No,Dev_Port:Byte):Boolean;stdcall; external 'hscom.DLL';
//-------------------------2010.04.01新增-------------------------------------
Procedure Set_OutPutMode(IsVMode:Boolean);stdcall;external 'hscom.DLL';
Function Adjust_UI2(Phase:Integer;Rated_Volt,Rated_Curr,Rate_Freq:Double;
PhaseSequence,Revers:Byte;
Volt_Per1,Volt_Per2,Volt_Per3,Curr_Per1,Curr_Per2,Curr_Per3:Double;IABC,CosP:PChar;
SModel:PChar;Dev_Port:Byte):Boolean;stdcall;external 'hscom.DLL';
//-------------------------2010.05.17新增-------------------------------------
Function Adjust_UI3(Phase:Integer;Rate_Freq:Double;PhaseSequence,Revers:Byte;
Volt,Curr:Double;IABC:PChar;COSP:Double;
SModel:PChar;Dev_Port:Byte):Boolean;stdcall;external 'hscom.DLL';
//-------------------------2010.06.10新增-------------------------------------
Function Adjust_UI4(Phase:Integer;Rated_Volt,Rated_Curr,Rate_Freq:Double;
PhaseSequence,Revers:Byte;
Volt_Per1,Volt_Per2,Volt_Per3,Curr_Per1,Curr_Per2,Curr_Per3:Double;IABC:PChar;COSP:Double;
SModel:PChar;Dev_Port:Byte):Boolean;stdcall;external 'hscom.DLL';
//-------------------------2011.06.25新增-------------------------------------
procedure SetStdFreq(StdFreq:Double);stdcall;external 'hscom.DLL'; //单位 kHz
//-------------------------2011.08.03新增-------------------------------------
procedure Set_ReviseMode(ReviseMode:Integer);stdcall;external 'hscom.DLL';
//-------------------------2012.03.13新增-------------------------------------
Procedure Set_ReviseTime(ReviseTime:Double);stdcall;external 'hscom.DLL';
//-------------------------2012.05.24新增-------------------------------------
Function Count_Read(var MPulse:Integer;Meter_No,Dev_Port:Byte):Boolean;stdcall;external 'hscom.DLL';
Function Count_Start(Meter_No:Byte;Dev_Port:Byte):Boolean;stdcall;external 'hscom.DLL';
VB 声明:
Private Declare Function Adjust_UI Lib "hscom.dll" (ByVal Phase As Integer, ByVal Rated_Volt As Double, ByVal Rated_Curr As Double,
ByVal Rated_Freq As Double, ByVal PhaseSequence As Integer, ByVal Revers As Integer,
ByVal Volt_Per As Double, ByVal Curr_Per As Double, ByVal IABC As String,
ByVal CosP As String, ByVal SModel As String, ByVal Dev_Port As Integer) As Boolean
Private Declare Function StdMeter_Read Lib "hscom.dll" (SData As String, ByVal SModel As String, ByVal Dev_Port As Integer) As Boolean
Private Declare Function Error_Read Lib "hscom.dll" (MError As String, ByVal Meter_No As Integer, ByVal Dev_Port As Integer) As Boolean
Private Declare Function Error_Start Lib "hscom.dll" (ByVal Meter_No As Integer, ByVal Constant As Double, ByVal Pulse As Integer,
ByVal Dev_Port As Integer) As Boolean
Private Declare Function Set_Pulse_Channel Lib "hscom.dll" (ByVal Meter_No As Integer, ByVal Channel_Flag As Integer,
ByVal Dev_Port As Integer) As Boolean
Private Declare Function Set_485_Channel Lib "hscom.dll" (ByVal Meter_No As Integer, ByVal Open_Flag As Integer,
ByVal Dev_Port As Integer) As Boolean
----------------------------2008.04.03新增----------------------------------
Private Declare Function Search_mark Lib "hscom.dll" (ByVal Meter_No As Integer,ByVal Dev_Port As Integer) As Boolean
Private Declare Function CRPSTA_start Lib "hscom.dll" (ByVal Meter_No As Integer,ByVal Dev_Port As Integer) As Boolean
Private Declare Function CRPSTA_clear Lib "hscom.dll" (ByVal Meter_No As Integer,ByVal Dev_Port As Integer) As Boolean
Private Declare Function Search_mark_Result Lib "hscom.dll" (ByVal Meter_No As Integer,ByVal Dev_Port As Integer) As Boolean
Private Declare Function CRPSTA_Result Lib "hscom.dll" (ByVal Meter_No As Integer,ByVal Dev_Port As Integer) As Boolean
Private Declare Function Error_Clear Lib "hscom.dll" (ByVal Dev_Port As Integer) As Boolean
Private Declare Function Power_Off Lib "hscom.dll" (ByVal Dev_Port As Integer) As Boolean
Private Declare Function Power_Pause Lib "hscom.dll" (ByVal Dev_Port As Integer) As Boolean
//-------------------------2008.09.04新增-------------------------------------Private Declare Function ConstTest_Start Lib "hscom.dll" (ByVal Meter_No As Integer, ByVal Constant As Double,
ByVal Dev_Port As Integer) As Boolean
Private Declare Function ConstPulse_Read Lib "hscom.dll" (MeterKWH As Double , StdKWH As Double , ByVal Constant As Double,
ByVal Meter_No As Integer,ByVal Dev_Port As Integer) As Boolean
//-------------------------2009.02.06新增-------------------------------------Private Declare Function SelectCircuit Lib "hscom.dll" (ByVal CircuitNo As Integer,ByVal Dev_Port As Integer) As Boolean
Private Declare Function CutNeutral Lib "hscom.dll" (ByVal CuttingFlag As Integer,ByVal Dev_Port As Integer) As Boolean
//-------------------------2010.03.04新增-------------------------------------
Private Declare Function SetRefClock Lib "hscom.dll" (ByVal SetFlag As Integer,ByVal Dev_Port As Integer) As Boolean
Private Declare Function Clock_Error_Start Lib "hscom.dll" (ByVal Meter_No As Integer,ByVal TheoryFreq As Double,ByVal TestTime As Integer,
ByVal Dev_Port As Integer) As Boolean
Private Declare Function Clock_Error_Read Lib "hscom.dll" (MError As String,ByVal TheoryFreq as Double,ByVal ErrorType As Integer,
ByVal Meter_No As Integer,ByVal Dev_Port As Integer) As Boolean
//-------------------------2010.04.01新增-------------------------------------
Private Declare Sub Set_OutPutMode Lib "hscom.dll" (ByVal IsVMode As Boolean)
4、调用举例:
Delphi:
//读误差 注意参数str要分配空间,否则可能内存数据错误
procedure TForm1.Button5Click(Sender: TObject);
var
tt:Boolean;
str:PChar;
begin
Edit1.text:='';
getmem(str,20);
tt:=Error_Read(str,1,Strtointdef(Edit2.text,2));
if tt then
Edit1.text:=StrPas(str)
else
Edit1.text:='ERROR';
freemem(str);
end;
C++ Builder:
//读误差 注意参数*cstrData 要分配空间,否则可能内存数据错误
void __fastcall TFrmMain::MMOprErrorReadClick(TObject *Sender)
{
StatusBarMain->Panels->Items[0]->Text = "";
bool tt = false;
AnsiString strPort = ComboBoxPort->Text.SubString(4, ComboBoxPort->Text.Length()-3);
char *cstrData = new char[20];
memset(cstrData, 0, 20);
boRes = Error_Read(&cstrData, 2, StrToIntDef(strPort, 2));
if (tt)
Edit1->Text = AnsiString(cstrData);
else
Edit1->Text = "ERROR";
delete [] cstrData;
}
VB:
'读取指示仪表数据,注意aa也要分配长度
Private Sub Command6_Click()
Dim aa As String, bb As Boolean
Text1.Text = ""
aa = Space(1500)
bb = StdMeter_Read(aa, Combo1.Text, Val(Text2.Text))
If bb Then
Text1.Text = aa
End If
End Sub
End Sub
C#:
//读取误差数据,注意strP要开辟空间
[DllImport("hscom.dll")]
public static extern bool Error_Read(ref StringBuilder MError, int Meter_No, int Dev_Port);
private void button1_Click(object sender, EventArgs e)
{
bool a;
int c;
int b=1;
StringBuilder strP = new StringBuilder();
for (c = 1; c <= 20; c++)
for (b = 1; b <= 48; b++)
{
a = Error_Read(ref strP, b, 8);
if (a)
{
listBox1.Items.Add(b.ToString() + strP);
}
else if (a == false)
{
listBox1.Items.Add(b.ToString() + "no");
}
}
}

Dranched | 园豆:23 (初学一级) | 2014-04-15 11:19

@Dranched:

看这几个个函数分析:

Function Open485CommPort(var LngHdcComm:THandle;BaudRate:PChar;Meter_Port:Byte):Boolean;stdcall;external 'hscom.DLL';
Function Close485CommPort(var LngHdcComm:THandle):Boolean;stdcall;external 'hscom.DLL';
Function Set485CommPort(var LngHdcComm:THandle;BaudRate:PChar):Boolean;stdcall;external 'hscom.DLL';
Function Recv485Data(LngHdcComm:THandle;var MeterData:PChar;recv_len:Integer):Boolean;stdcall;external 'hscom.DLL';

Open485CommPort其实你可以理解为打开串口,至于所标的485,意义不大,可以是在PC上加485扩展卡,也可以是原有的232外接232/485转换器的。
看参数,这个DLL是用DELPHI写的,THandle就是longword,4字节无符号32位,在C#中可以用IntPtr代替,PChar也可以IntPtr,var 相当于C#中的ref

[DllImport("hscom.dll")]
public static extern bool Open485CommPort(ref IntPtr LngHdcComm, StringBuilder BaudRate, byte Meter_Port);

调用Open485CommPort获得的LngHdcComm再传入Close485CommPort、Set485CommPort、Recv485Data中使用,
Meter_Port参数是你要操作的串口号。

hailants | 园豆:750 (小虾三级) | 2014-04-15 15:15

@hailants: 还是不太懂,我需要怎么操作来获得LngHdcComm,因为open485commport也需要这个参数

Dranched | 园豆:23 (初学一级) | 2014-04-17 16:44

@Dranched: 

IntPtr ldComm;

Open485CommPort(ref ldComm,BaudRate,Meter_Port);

Set485CommPort(ref ldComm,BaudRate);

hailants | 园豆:750 (小虾三级) | 2014-04-18 16:15
其他回答(2)
0

http://blog.csdn.net/hsstc/article/details/8940234

爱编程的大叔 | 园豆:30753 (高人七级) | 2014-04-15 09:50

里边没有获取通讯句柄的例子啊?

支持(0) 反对(0) Dranched | 园豆:23 (初学一级) | 2014-04-15 10:00
0

通讯句柄是个什么东西?

Launcher | 园豆:45045 (高人七级) | 2014-04-15 10:08

我不知道啊,知道就不用问了。是给的dll调用文档里边的,函数里·需要调用485口通讯句柄

支持(0) 反对(0) Dranched | 园豆:23 (初学一级) | 2014-04-15 10:12

@Dranched: 串口通信:http://blog.csdn.net/chinaclock/article/details/5714473

你先搞明白是让你打开 485 端口,还是让你使用一个已经打开的 485 端口。

支持(0) 反对(0) Launcher | 园豆:45045 (高人七级) | 2014-04-15 10:40

@Launcher: 这个我明白,这个是已经打开的串口。

支持(0) 反对(0) Dranched | 园豆:23 (初学一级) | 2014-04-15 11:19

@Dranched: 如果是已经打开的,它应该有句柄保存下来,你直接拿来用。但是,我看了下你给出的文档,我发现一个函数:

Open485CommPort:打开485通讯口

也就是说你的程序应该是这样的:

HANDLE handle = Open485CommPort(....);

这就是你需要的东西。

支持(0) 反对(0) Launcher | 园豆:45045 (高人七级) | 2014-04-15 11:23
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册