Project

General

Profile

Files » port.c

Frédéric Blanc, 2016-01-29 09:58

 

#include "inst.h"
#include "var.h"
//***************************************************************************************************
/**
* @brief initialisation du panneau de l'interface de communication
* @param structure com
* @return 0
* @date 25/02/2010
*
*/
int init_port(struct S_COM *ptr_port)
{
ptr_port->instrDescr[0]='\0';
ptr_port->typeCOM=-1;
//RS232
ptr_port->numCOM=1;
ptr_port->baudRate=9600;
ptr_port->parity='1';
ptr_port->dataBits='8';
ptr_port->stopBits='2';
ptr_port->flow='1';
ptr_port->termchar='\n';
//USB
ptr_port->numUSB[0]='\0';
//GPIB
ptr_port->numGPIB=1;
ptr_port->numcarteGPIB=0;
//ETHER
sprintf(ptr_port->numETH,"192.168.0.3");
ptr_port->numcarteETH=0;
//LANG
ptr_port->language=SCPI;
return 0;
}
//***************************************************************************************************
/**
* @brief configuration du panneau de l'interface de communication
* @param structure com
* @return 0
* @date 25/02/2010
*
*/
int set_panel_port(int panel,struct S_COM *ptr_port)
{
SetCtrlVal(panel,P_PORT_IDQUERY,ptr_port->instrDescr);
check_type (panel,ptr_port->typeCOM);
//RS232
SetCtrlVal (panel,P_PORT_PORCOM,ptr_port->numCOM);
SetCtrlVal (panel,P_PORT_RS232BAUD,ptr_port->baudRate);
SetCtrlVal (panel,P_PORT_RS232PARITY,ptr_port->parity);
SetCtrlVal (panel,P_PORT_RS232BITS,ptr_port->dataBits);
SetCtrlVal (panel,P_PORT_RS232STOP,ptr_port->stopBits);
SetCtrlVal (panel,P_PORT_RS232HAND,ptr_port->flow);
SetCtrlVal (panel,P_PORT_RS232TERMCHAR,ptr_port->termchar);
//USB
SetCtrlVal (panel,P_PORT_PORUSB,ptr_port->numUSB);
//GPIB
SetCtrlVal (panel,P_PORT_PORGPIB,ptr_port->numGPIB);
SetCtrlVal (panel,P_PORT_PORGPIB_2,ptr_port->numcarteGPIB);
//ETHER
SetCtrlVal (panel,P_PORT_PORETH,ptr_port->numETH);
SetCtrlVal (panel,P_PORT_PORETH_2,ptr_port->numcarteETH);
//LANG
SetCtrlVal (panel,P_PORT_LANG,ptr_port->language);
return 0;
}
//***************************************************************************************************
/**
* @brief lecture du panneau de l'interface de communication
* @param structure com
* @return 0
* @date 25/02/2010
*
*/
int get_panel_port(int panel,struct S_COM *ptr_port)
{
//RS232
GetCtrlVal (panel,P_PORT_PORCOM,&ptr_port->numCOM);
GetCtrlVal (panel,P_PORT_RS232BAUD,&ptr_port->baudRate);
GetCtrlVal (panel,P_PORT_RS232PARITY,&ptr_port->parity);
GetCtrlVal (panel,P_PORT_RS232BITS,&ptr_port->dataBits);
GetCtrlVal (panel,P_PORT_RS232STOP,&ptr_port->stopBits);
GetCtrlVal (panel,P_PORT_RS232HAND,&ptr_port->flow);
GetCtrlVal (panel,P_PORT_RS232TERMCHAR,&ptr_port->termchar);
//USB
GetCtrlVal (panel,P_PORT_PORUSB,ptr_port->numUSB);
//GPIB
GetCtrlVal (panel,P_PORT_PORGPIB,&ptr_port->numGPIB);
GetCtrlVal (panel,P_PORT_PORGPIB_2,&ptr_port->numcarteGPIB);
//ETHER
GetCtrlVal (panel,P_PORT_PORETH,ptr_port->numETH);
GetCtrlVal (panel,P_PORT_PORETH_2,&ptr_port->numcarteETH);
//LANG
GetCtrlVal (panel,P_PORT_LANG,&ptr_port->language);
return 0;
}
//***************************************************************************************************
/**
* @brief gestion des type de portCOM
* @param type
* @return 0
* @date 25/02/2010
*
*/
int check_type (int panel,int type)
{
if(type==RS232)
{
SetCtrlVal (panel,P_PORT_COM,1);
SetCtrlAttribute(panel,P_PORT_PORCOM,ATTR_DIMMED,0);
SetCtrlAttribute(panel,P_PORT_RS232BAUD,ATTR_DIMMED,0);
SetCtrlAttribute(panel,P_PORT_RS232PARITY,ATTR_DIMMED,0);
SetCtrlAttribute(panel,P_PORT_RS232BITS,ATTR_DIMMED,0);
SetCtrlAttribute(panel,P_PORT_RS232STOP,ATTR_DIMMED,0);
SetCtrlAttribute(panel,P_PORT_RS232HAND,ATTR_DIMMED,0);
}else
{
SetCtrlVal (panel,P_PORT_COM,0);
SetCtrlAttribute(panel,P_PORT_PORCOM,ATTR_DIMMED,1);
SetCtrlAttribute(panel,P_PORT_RS232BAUD,ATTR_DIMMED,1);
SetCtrlAttribute(panel,P_PORT_RS232PARITY,ATTR_DIMMED,1);
SetCtrlAttribute(panel,P_PORT_RS232BITS,ATTR_DIMMED,1);
SetCtrlAttribute(panel,P_PORT_RS232STOP,ATTR_DIMMED,1);
SetCtrlAttribute(panel,P_PORT_RS232HAND,ATTR_DIMMED,1);
}
if(type==USB)
{
SetCtrlVal (panel,P_PORT_USB,1);
SetCtrlAttribute(panel,P_PORT_PORUSB,ATTR_DIMMED,0);
}else
{
SetCtrlVal (panel,P_PORT_USB,0);
SetCtrlAttribute(panel,P_PORT_PORUSB,ATTR_DIMMED,1);
}
if(type==GPIB)
{
SetCtrlVal (panel,P_PORT_GPIB,1);
SetCtrlAttribute(panel,P_PORT_PORGPIB,ATTR_DIMMED,0);
SetCtrlAttribute(panel,P_PORT_PORGPIB_2,ATTR_DIMMED,0);
}else
{
SetCtrlVal (panel,P_PORT_GPIB,0);
SetCtrlAttribute(panel,P_PORT_PORGPIB,ATTR_DIMMED,1);
SetCtrlAttribute(panel,P_PORT_PORGPIB_2,ATTR_DIMMED,1);
}
if(type==ETH)
{
SetCtrlVal (panel,P_PORT_ETH,1);
SetCtrlAttribute(panel,P_PORT_PORETH,ATTR_DIMMED,0);
SetCtrlAttribute(panel,P_PORT_PORETH_2,ATTR_DIMMED,0);
}else
{
SetCtrlVal (panel,P_PORT_ETH,0);
SetCtrlAttribute(panel,P_PORT_PORETH,ATTR_DIMMED,1);
SetCtrlAttribute(panel,P_PORT_PORETH_2,ATTR_DIMMED,1);
}
return 0;
}
//***************************************************************************************************
/**
* @brief initialisation du portCOM
* @param structure com
* @return 0
* @date 25/02/2010
*
*/
int initcom(struct S_COM *ptr_port)
{
char buffer [1024];
char message [1024];
int nbbitlu;
switch (ptr_port->typeCOM)
{

case RS232:
sprintf(ptr_port->instrDescr,"ASRL%d::INSTR::%d-%c-%c-%c-%c-%c",ptr_port->numCOM,ptr_port->baudRate,ptr_port->dataBits,ptr_port->parity,ptr_port->stopBits,ptr_port->flow,ptr_port->termchar);
break;
case USB:
sprintf(ptr_port->instrDescr,"%s",ptr_port->numUSB); //descripteur connection instrument);
break;
case GPIB:
sprintf(ptr_port->instrDescr,"GPIB%d::%d::INSTR",ptr_port->numcarteGPIB,ptr_port->numGPIB); //descripteur connection instrument);
break;
case ETH:
sprintf(ptr_port->instrDescr,"TCPIP%d::%s::INSTR",ptr_port->numcarteETH,ptr_port->numETH); //descripteur connection instrument);
break;
}
ptr_port->handle=0;
if(inst_init ((ViChar*)ptr_port->instrDescr, VI_FALSE, VI_FALSE,&ptr_port->handle ))
return -1;
if(ptr_port->handle)
{
//IDQUERY
sprintf(message,"*IDN?");
if (ptr_port->language==ARPS)
{
sprintf(message,"ID?");
}
inst_WriteInstrData (ptr_port->handle,message );
if(inst_ReadInstrData (ptr_port->handle, 100,ptr_port->instrDescr, &nbbitlu))
return -1;
return 0;
}
return -1;
}
(20-20/25)