The ALR3220 from ELC is a 0V to 32V, 0 to 20A programmable power supply. It provides protection against short-circuits, by current regulation, against overtemperature by fan and thermal circuit-breaker and against overcurrent on main input, by internal fuses. It has 4 digit graphic LCD 128 x 64 pixels display with white backlight for clear view.
由于ALR3220支持RS232通信,那么就可以在开发测试中通过CAPL远程控制输出的电压电流,满足不同的测试要求。
Code0 | Code1 | Code2 | Code3 | Code4 | Code5 | Code6 | Code7 |
---|---|---|---|---|---|---|---|
[address] | Parameter | Command | [Value] |
其中:
[Address] = characters ASCII 0 (RS232 or USB)
characters ASCII 1 to 31 (RS485)
Parameters = VOLT- CURR- OVP-OCP- OUT-RCL-STO (ASCII characters).
Command = WR- RD- MES (ASCII characters).
[Value] = ASCII characters.
Example 1 : 0 VOLT WR 1250 --> Writing setpoint 1,25 V on RS232 or USB port
Code0 | Code1 | Code2 | Code3 | Code4 | Code5 | Code6 | Code7 |
---|---|---|---|---|---|---|---|
0 | VOLT | WR | 1250 | ||||
0x30 | 0x20 | 0x56,0x4F,0x4C,0x54 | 0x20 | 0x57,0x52 | 0x20 | 0x31,0x32,0x35,0x30 | 0x0d |
Example 2 : 1 CURR MES --> Current measurement request on address 1 from the RS485 port
Answer :
[Address]
[Address] = characters ASCII 0 (RS232 or USB)
characters ASCII 1 to 31 (RS485)
Status = OK- ERR- Local (ASCII characters).
variables
{
dword gPortNo=14; /*COM14*/
dword gBaudRate=9600;
dword gDataBits=8;
dword gStopBits=2;
dword gParity = 0;/*0-NOPARITY,1-ODDPARITY,2-EVENPARITY*/
// GLOBAL
const int kBUFFER_SIZE = 1000;
const int kINFO = 1;
const int kWARN = 2;
const int kERROR = 3;
// data is copied from callback buffer to gReceiverBuffer (collects data)
byte gReceiverCallbackBuffer[kBUFFER_SIZE];
byte gReceiverBuffer[kBUFFER_SIZE];
byte gEmptyBuffer [kBUFFER_SIZE];
long gNumberOfReceivedBytes = 0;
// state variable
byte gSending = 0;
// timer for indication of data reception
msTimer tBytesReceived;
byte Alr32320CmdEnter= 0x0d;/* = 0Dh (Enter)*/
byte Alr32320CmdSp = 0x20;
byte Alr32320WRCmd[2]= {0x57,0x52};/*WR*/
byte Alr32320RDCmd[2]= {0x52,0x44};/*RD*/
byte AlR3220Volt_Cmd[7]={0x30,0x20,0x56,0x4F,0x4C,0x54,0x20};/*0 VOLT */
byte AlR3220Curr_Cmd[7]={0x30,0x20,0x43,0x55,0x52,0x52,0x20};/*0 CURR */
byte AlR3220OVP_Cmd[6]={0x30,0x20,0x4F,0x56,0x50,0x20};/*0 OVP */
byte AlR3220OCP_Cmd[6]={0x30,0x20,0x4F,0x43,0x50,0x20};/*0 OCP */
byte AlR322OutputOnCmd[10]={0x30,0x20,0x4F,0x55,0x54,0x20,0x57,0x52,0x20,0x31};/*0 OUT WR 1*/
byte AlR322OutputOffCmd[10]={0x30,0x20,0x4F,0x55,0x54,0x20,0x57,0x52,0x20,0x30};/*0 OUT WR 0*/
}
on preStart
{
InitSerialPort();
}
on envVar EnvSetVoltage
{
long numberOfBytes;
byte buffer[kBUFFER_SIZE];
char volbuf[10];
long setvol=0;
int i=0;
if ( !gSending )
{
CopyBuffer(buffer,0,AlR3220Volt_Cmd,elCount(AlR3220Volt_Cmd));
numberOfBytes = elCount(AlR3220Volt_Cmd);
setvol = getValue(EnvSetVoltage);
CopyBuffer(buffer,numberOfBytes,Alr32320WRCmd,elCount(Alr32320WRCmd));
numberOfBytes+=elCount(Alr32320WRCmd);
buffer[numberOfBytes]=Alr32320CmdSp;
numberOfBytes = numberOfBytes+1;
ltoa(setvol,volbuf,10);
for (i=0; i<5; i++)
{
buffer[numberOfBytes+i] = volbuf[i];
}
numberOfBytes = numberOfBytes+5;
buffer[numberOfBytes]=Alr32320CmdEnter;
numberOfBytes = numberOfBytes+1;
if(0==Rs232Send(gPortNo, buffer, numberOfBytes))
{
writeLineEx(0,kERROR,"An error occurred during write of block of data to the serial port %d.", gPortNo);
return;
} else {
writeLineEx(0,kINFO, "Write block of bytes to serial port %d worked well.", gPortNo);
}
// set state
gSending = 1;
}
}
on timer tBytesReceived
{
/*Process receive data--begin*/
/*Process receive data--end*/
// reset buffer
gNumberOfReceivedBytes = 0;
// reset data indication
putValue(EnvReceptionIndication,0);
}
void InitSerialPort()
{
// close serial port (port may have changed, former port shall not remain open)
if(Rs232Close(gPortNo)==1)
writeLineEx(0,kINFO, "Serial port %d successfully closed.", gPortNo);
else
writeLineEx(0,kERROR,"An error occurred during closing of the serial port %d.", gPortNo);
// set state (close aborts all open requests)
gSending = 0;
// open the serial port (comes up with Windows defaults)
if(Rs232Open(gPortNo)==1)
writeLineEx(0,kINFO, "Serial port %d successfully opened.", gPortNo);
else
writeLineEx(0,kERROR,"An error occurred during opening of the serial port %d.", gPortNo);
// configure the serial port
// - just take the panel content
if(Rs232Configure(gPortNo,gBaudRate,gDataBits,gStopBits,gParity)==1)
writeLineEx(0,kINFO, "Serial port %d successfully initialized.", gPortNo);
else
writeLineEx(0,kERROR,"An error occurred during initialization of the serial port %d.", gPortNo);
// set buffer for reception (otherwise callback would not work)
if(Rs232Receive(gPortNo, gReceiverCallbackBuffer, kBUFFER_SIZE))
writeLineEx(0,kINFO, "Receiver buffer for serial port %d successfully set.", gPortNo);
else
writeLineEx(0,kERROR,"An error occurred during setting the receiver buffer for serial port %d.", gPortNo);
}
RS232OnReceive( dword port, byte buffer[], dword number )
{
dword numberOfBytesToCopy;
// collect data as long as buffer has space for it
if ( (gNumberOfReceivedBytes+number)>kBUFFER_SIZE )
{
numberOfBytesToCopy = kBUFFER_SIZE-gNumberOfReceivedBytes; // no more than that ! it is full now
} else {
numberOfBytesToCopy = number;
}
if ( numberOfBytesToCopy==0 )
{
return; // nothing to add
}
CopyBuffer(gReceiverBuffer,gNumberOfReceivedBytes,buffer,numberOfBytesToCopy);
gNumberOfReceivedBytes += numberOfBytesToCopy;
// indicate data reception
putValue(EnvReceptionIndication,1);
cancelTimer(tBytesReceived);
setTimer(tBytesReceived,500);
}
CopyBuffer( byte destBuffer[], dword destOffset, byte srcBuffer[], dword srcNumber )
{
dword i;
for (i=0; i<srcNumber; i++)
{
destBuffer[destOffset+i] = srcBuffer[i];
}
}
RS232OnSend( dword port, byte buffer[], dword number )
{
// set state
gSending = 0;
writeLineEx(0,kINFO,"Transmission of %d bytes from port %d completed !", number, port);
}
RS232OnError( dword port, dword errorFlags )
{
// set state
gSending = 0;
writeLineEx(0,kERROR,"Error handler called with error code %d !", errorFlags);
if ( errorFlags & 1 )
writeLineEx(0,1,"%d informs of send error",errorFlags);
if ( errorFlags & 2 )
writeLineEx(0,1,"%d informs of receive error",errorFlags);
if ( errorFlags & 4 )
writeLineEx(0,1,"%d informs of frame error",errorFlags);
if ( errorFlags & 8 )
writeLineEx(0,1,"%d informs of parity error",errorFlags);
if ( errorFlags & 16 )
writeLineEx(0,1,"%d informs of overrun error",errorFlags);
if ( errorFlags & 32 )
writeLineEx(0,1,"%d informs of receiver overrun error",errorFlags);
if ( errorFlags & 64 )
writeLineEx(0,1,"%d informs of break state",errorFlags);
if ( errorFlags & 128 )
writeLineEx(0,1,"%d informs of send timeout error",errorFlags);
}