用CAPL通过RS232远程控制ALR3220程控电源

2024-02-07 06:50

本文主要是介绍用CAPL通过RS232远程控制ALR3220程控电源,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

用CAPL通过RS232远程控制ALR3220程控电源

  • 1. ALR3220程控电源
  • 2. ALR3220 远程控制命令
  • 3. 用CAPL控制ALR3220
    • 3.1 首先需要用Panel Designer设计一个控制面板![在这里插入图片描述](https://img-blog.csdnimg.cn/20200711160738847.JPG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2Zhcm1lcjAw,size_16,color_FFFFFF,t_70#pic_center)
    • 3.2 编写CAPL

1. ALR3220程控电源

在这里插入图片描述
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.

  • Automatic constant voltage operation adjustable voltage of 0 to 32V(0 to ±10mV) with 10mV resolution
  • Automatic constant current operation adjustable current from 0Amps to 20Amps with 10mA resolution
  • Input voltage of 230Volts ±10%, 50 / 60Hz
  • Power consumption of 770W
  • 16 memory configurations
  • USB, RS232 and RS485 interface & 0-10V insulated interface
  • Complies with EN 61326-1, EN 55011, EN 61010-1 and CAT II standards
  • Operating temperature range from +5°C to +40°C
  • Dimension is 155mm x 250mm x 335mm and weight is 3.15Kg
  • LabVIEW drivers and executable provided

由于ALR3220支持RS232通信,那么就可以在开发测试中通过CAPL远程控制输出的电压电流,满足不同的测试要求。

2. ALR3220 远程控制命令

Code0Code1Code2Code3Code4Code5Code6Code7
[address]<sp>Parameter<sp>Command<sp>[Value]<CR>

其中:
[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).
<SP> = 20h (space).
[Value] = ASCII characters.
<CR> = 0Dh (Enter)
Example 1 : 0 VOLT WR 1250 --> Writing setpoint 1,25 V on RS232 or USB port

Code0Code1Code2Code3Code4Code5Code6Code7
0VOLTWR1250
0x300x200x56,0x4F,0x4C,0x540x200x57,0x520x200x31,0x32,0x35,0x300x0d

Example 2 : 1 CURR MES --> Current measurement request on address 1 from the RS485 port

Answer :
[Address] <SP>Status<SP>Value<CR>
[Address] = characters ASCII 0 (RS232 or USB)
characters ASCII 1 to 31 (RS485)
Status = OK- ERR- Local (ASCII characters).

  • OK Command valid.
  • ERR Syntax error in the command.
  • Local Command impossible, the power supply is in local mode.
    <SP> = 20h (space).
    [Value] = characters ASCII.
    <CR> = 0Dh (retour chariot)
    Example 3 : 0 OK   Back of example 1
    Example 4 : 1 OK 450   Back of example 2 current measurement : 450 mA

3. 用CAPL控制ALR3220

3.1 首先需要用Panel Designer设计一个控制面板在这里插入图片描述

3.2 编写CAPL

variables
{dword  gPortNo=14; /*COM14*/dword  gBaudRate=9600;dword  gDataBits=8;dword  gStopBits=2;dword  gParity = 0;/*0-NOPARITY,1-ODDPARITY,2-EVENPARITY*/// GLOBALconst 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 variablebyte gSending = 0;// timer for indication of data reception msTimer tBytesReceived;byte Alr32320CmdEnter= 0x0d;/*<CR> = 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 stategSending = 1;}
}
on timer tBytesReceived
{/*Process receive data--begin*//*Process receive data--end*/// reset buffergNumberOfReceivedBytes = 0;// reset data indicationputValue(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);    elsewriteLineEx(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);    elsewriteLineEx(0,kERROR,"An error occurred during opening of the serial port %d.", gPortNo);// configure the serial port// - just take the panel contentif(Rs232Configure(gPortNo,gBaudRate,gDataBits,gStopBits,gParity)==1)writeLineEx(0,kINFO, "Serial port %d successfully initialized.", gPortNo);    elsewriteLineEx(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);    elsewriteLineEx(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 itif ( (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 receptionputValue(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 stategSending = 0;writeLineEx(0,kINFO,"Transmission of %d bytes from port %d completed !", number, port);
}RS232OnError( dword port, dword errorFlags )
{// set stategSending = 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);
}

这篇关于用CAPL通过RS232远程控制ALR3220程控电源的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/686869

相关文章

Spring Security 基于表达式的权限控制

前言 spring security 3.0已经可以使用spring el表达式来控制授权,允许在表达式中使用复杂的布尔逻辑来控制访问的权限。 常见的表达式 Spring Security可用表达式对象的基类是SecurityExpressionRoot。 表达式描述hasRole([role])用户拥有制定的角色时返回true (Spring security默认会带有ROLE_前缀),去

控制反转 的种类

之前对控制反转的定义和解释都不是很清晰。最近翻书发现在《Pro Spring 5》(免费电子版在文章最后)有一段非常不错的解释。记录一下,有道翻译贴出来方便查看。如有请直接跳过中文,看后面的原文。 控制反转的类型 控制反转的类型您可能想知道为什么有两种类型的IoC,以及为什么这些类型被进一步划分为不同的实现。这个问题似乎没有明确的答案;当然,不同的类型提供了一定程度的灵活性,但

深入解析秒杀业务中的核心问题 —— 从并发控制到事务管理

深入解析秒杀业务中的核心问题 —— 从并发控制到事务管理 秒杀系统是应对高并发、高压力下的典型业务场景,涉及到并发控制、库存管理、事务管理等多个关键技术点。本文将深入剖析秒杀商品业务中常见的几个核心问题,包括 AOP 事务管理、同步锁机制、乐观锁、CAS 操作,以及用户限购策略。通过这些技术的结合,确保秒杀系统在高并发场景下的稳定性和一致性。 1. AOP 代理对象与事务管理 在秒杀商品

PostgreSQL中的多版本并发控制(MVCC)深入解析

引言 PostgreSQL作为一款强大的开源关系数据库管理系统,以其高性能、高可靠性和丰富的功能特性而广受欢迎。在并发控制方面,PostgreSQL采用了多版本并发控制(MVCC)机制,该机制为数据库提供了高效的数据访问和更新能力,同时保证了数据的一致性和隔离性。本文将深入解析PostgreSQL中的MVCC功能,探讨其工作原理、使用场景,并通过具体SQL示例来展示其在实际应用中的表现。 一、

vue2实践:el-table实现由用户自己控制行数的动态表格

需求 项目中需要提供一个动态表单,如图: 当我点击添加时,便添加一行;点击右边的删除时,便删除这一行。 至少要有一行数据,但是没有上限。 思路 这种每一行的数据固定,但是不定行数的,很容易想到使用el-table来实现,它可以循环读取:data所绑定的数组,来生成行数据,不同的是: 1、table里面的每一个cell,需要放置一个input来支持用户编辑。 2、最后一列放置两个b

远程工具-SecureCRT/SecureFX

下载地址: https://www.portablesoft.org/securecrt-securefx-integrated/

【微服务】Ribbon(负载均衡,服务调用)+ OpenFeign(服务发现,远程调用)【详解】

文章目录 1.Ribbon(负载均衡,服务调用)1.1问题引出1.2 Ribbon负载均衡1.3 RestTemplate整合Ribbon1.4 指定Ribbon负载均衡策略1.4.1 配置文件1.4.2 配置类1.4.3 定义Ribbon客户端配置1.4.4 自定义负载均衡策略 2.OpenFeign面向接口的服务调用(服务发现,远程调用)2.1 OpenFeign的使用2.1 .1创建

【电机控制】数字滤波算法(持续更新)

文章目录 前言1. 数字低通滤波 前言 各种数字滤波原理,离散化公式及代码。 1. 数字低通滤波 滤波器公式 一阶低通滤波器的输出 y [ n ] y[n] y[n] 可以通过以下公式计算得到: y [ n ] = α x [ n ] + ( 1 − α ) y [ n − 1 ] y[n] = \alpha x[n] + (1 - \alpha) y[n-1]

OpenStack离线Train版安装系列—3控制节点-Keystone认证服务组件

本系列文章包含从OpenStack离线源制作到完成OpenStack安装的全部过程。 在本系列教程中使用的OpenStack的安装版本为第20个版本Train(简称T版本),2020年5月13日,OpenStack社区发布了第21个版本Ussuri(简称U版本)。 OpenStack部署系列文章 OpenStack Victoria版 安装部署系列教程 OpenStack Ussuri版

OpenStack离线Train版安装系列—1控制节点-环境准备

本系列文章包含从OpenStack离线源制作到完成OpenStack安装的全部过程。 在本系列教程中使用的OpenStack的安装版本为第20个版本Train(简称T版本),2020年5月13日,OpenStack社区发布了第21个版本Ussuri(简称U版本)。 OpenStack部署系列文章 OpenStack Victoria版 安装部署系列教程 OpenStack Ussuri版