本文主要是介绍Canoe之CAPL编程--控制HSPY-36-03程控电源,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
variables
{
int i;
byte UART_Port = 1;
dword Power_baudrate = 9600;
int my_RS232Flag;
}
int RS232Init(dword port,dword baudrate,dword numberOfDataBits,dword numberOfStopBits,dword parity)
{
dword ConfigureFlag;
dword RS232OpenFlag;
int flag=0;
RS232OpenFlag=RS232Open(port);
if(RS232OpenFlag!=1)
{
flag=1;
}
else
{
ConfigureFlag = RS232Configure(port,baudrate,numberOfDataBits,numberOfStopBits,parity);
if(ConfigureFlag==0)
{
flag=2;
}
}
return flag;
}
void RS232SetVoltage(float import_voltage)
{
byte VoltageSet[8];
byte C1;
byte C2;
word tmp=0xFFFF;
int n;
int i;
byte V1;
byte V2;
int Input;
tmp=0xFFFF;
if(my_RS232Flag==0)
{
if(import_voltage>30)
{
import_voltage=30;
write("Voltage too hign,we change it to 30V for protect the ECU!");
}
Input=100*import_voltage;
write("Input=%d",Input);
V1=(Input)>>8;
V2=(Input)&0xFF;
VoltageSet[0]=0x00;
VoltageSet[1]=0x06;
VoltageSet[2]=0x00;
VoltageSet[3]=0x00;
VoltageSet[4]=V1;
VoltageSet[5]=V2;
for(n=0;n<6;n++)
{
tmp=VoltageSet[n]^tmp;
for(i=0;i<8;i++)
{
if(tmp&0x01)
{
tmp=tmp>>1;
tmp=(tmp^0xA001);
}
else
{
tmp=tmp>>1;
}
}
write("tmp=%x",tmp);
}
C1=tmp&0xFF;
C2=tmp>>8;
VoltageSet[6]=C1;
VoltageSet[7]=C2;
RS232Send(UART_Port,VoltageSet,8);
testStepPass("Volt","Set Voltage Succeed: %2.2fV",import_voltage);
}
else
{
testStepFail("Volt","Set Voltage Fail - PORT %dCANNOT OPEN",UART_Port);
}
}
void maintest()
{
my_RS232Flag=RS232Init(UART_Port,Power_baudrate,8,1,0);
if(my_RS232Flag==0) /* Jugde if the Power connect and UART connect OK */
{
for(i=0;i<15;i++)
{
RS232SetVoltage(i*1.00);
testWaitForTimeout(2000);
}
}
else
{
testStepFail("Volt","Power Supply - PORT %dCANNOT OPEN",UART_Port);
}
CloseRS232(UART_Port);/* Close Port */
这篇关于Canoe之CAPL编程--控制HSPY-36-03程控电源的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!