Commit 265c9b23 authored by claes's avatar claes

Motion Control USB I/O added

parent 6c50d8d5
include $(pwre_dir_symbols)
ifndef variables_mk
-include $(pwre_croot)/src/tools/bld/src/$(os_name)/$(hw_name)/variables.mk
endif
ifndef variables_mk
include $(pwre_croot)/src/tools/bld/src/$(os_name)/variables.mk
endif
ifndef rules_mk
-include $(pwre_croot)/src/tools/bld/src/$(os_name)/$(hw_name)/rules.mk
endif
ifndef rules_mk
include $(pwre_croot)/src/tools/bld/src/$(os_name)/rules.mk
endif
.PHONY : all init copy lib exe clean realclean\
$(clean_c)
all : init copy lib
init :
copy : $(lib_dir)/libusbio.a $(inc_dir)/libusbio.h
lib :
exe :
clean :
realclean : clean $(clean_obj)
.SUFFIXES:
$(lib_dir)/libusbio.a : ../libusbio.a
@ echo "Copying libusbio.a"
@ $(cp) $(cpflags) $(source) $(target)
$(inc_dir)/libusbio.h : ../libusbio.h
@ echo "Copying libusbio.h"
@ $(cp) $(cpflags) $(source) $(target)
/*************************************************************
* *
* COPYRIGHT © 2007 Motion Control i Västerås AB, Sweden *
* *
* All rights including ownership and copyright to the *
* software herein are held by Motion Control i Västerås AB. *
* The software may be used and/ or copied only with the *
* written permission from Motion Control i Västerås AB or *
* in accordance with the terms and conditions stipulated *
* agreement/ contract under which the software has been *
* supplied. *
*------------------------------------------------------------*
* Programenhet : USBIO driver for Linux 2.6 *
* Filnamn : libusbio.h *
* Tillhörande libusbio.c *
* filer : *
*----------------------------------------------------------- *
* Beskrivning : Detta är H-filen för supportbiblioteket *
* till USB I/O enheten. *
*------------------------------------------------------------*
* Programhistoria : *
* Ver, Datum, Utförd av, *
* 1.0 07-01-29 Marcus Tönnäng *
* 1.2 07-02-06 Johan Zetterlund portad till Linux. *
* *
**************************************************************/
//Communication
int USBIO_Open(int *Handle);
// int USBIO_OpenBySerialNr(int *Handle, int Serial[]);
// int USBIO_OpenByIdNr(int *Handle, int IdNr);
int USBIO_Close(int *Handle);
int USBIO_IsConnected(int *Handle);
// int USBIO_SetTimeOut(int *Handle, unsigned int TimeOut);
// int USBIO_ListAll(int *Antal, int IdNr[]); //Ändra, mer info
//Read
int USBIO_ReadDI( int *Handle, int Port, int *Value);
int USBIO_ReadChannelDI( int *Handle, int Port, int Channel, int *Value);
int USBIO_ReadAI( int *Handle, int Channel, float *Value);
int USBIO_ReadAllAI( int *Handle, float AIValue[]);
int USBIO_ReadADVal( int *Handle, int Channel, int *Value);
int USBIO_ReadAllADVal( int *Handle, int ADValue[]);
int USBIO_ReadCounter( int *Handle, unsigned int *Value, int *Overflow);
int USBIO_ReadUART( int *Handle, int *Nr, unsigned char Value[], int *Overflow);
// int USBIO_ReadFreq( int *Handle, float *Value, float *Width);
//Write
int USBIO_WriteDO(int *Handle, int Port, int Value);
int USBIO_WriteChannelDO(int *Handle, int Port, int Channel, int Value);
int USBIO_WriteAO( int *Handle, int Channel, float Value);
int USBIO_WritePWM( int *Handle, int Channel, int Value);
int USBIO_WriteLowFreq( int *Handle, int Freq, unsigned char PortA, unsigned char PortB, unsigned char PortC);
int USBIO_WriteUART( int *Handle, unsigned char Value);
int USBIO_WriteLED( int *Handle, int Value);
//Configure
int USBIO_ConfigDIO(int *Handle, int Port, int Value);
int USBIO_ConfigAI(int *Handle, int Value);
int USBIO_ConfigAO(int *Handle, int Value);
int USBIO_ConfigPWM(int *Handle, int Value, int Freq);
int USBIO_ConfigCounter(int *Handle, int Value);
int USBIO_ConfigUART(int *Handle, int BaudRate);
//int USBIO_Reset(int *Handle);
int USBIO_SoftReset(int *Handle);
int USBIO_SetIdNr(int *Handle, int IdNr, char Description[]);
int USBIO_ConfigWatchdog(int *Handle, int Active, int TimeOut, int Reset, unsigned char PortMask[], unsigned char Port[], int AOfunction);
int USBIO_ResetWatchdog(int *Handle);
//Status
int USBIO_GetStatus(int *Handle, int Value[]);
int USBIO_GetFirmwareVersion(int *Handle, char *Version);
int USBIO_GetHardwareVersion(int *Handle, char *Version);
int USBIO_GetSerialNr(int *Handle, unsigned int *Serial);
int USBIO_GetLibVersion(char *Version);
int USBIO_GetIdNr(int *Handle, int *IdNr, char *Description);
//Error
int USBIO_GetErrorString(int Error, char *ErrorMessage , int *StringLength);
//Advanced functions
int USBIO_WriteAndRead(int *Handle, unsigned char WriteBuffer[], unsigned char ReadBuffer[]);
include $(pwre_dir_symbols)
-include $(pwre_kroot)/tools/bld/src/$(os_name)/$(hw_name)/$(type_name)_generic.mk
ifeq ($($(type_name)_generic_mk),)
-include $(pwre_kroot)/tools/bld/src/$(os_name)/$(type_name)_generic.mk
endif
ifeq ($($(type_name)_generic_mk),)
include $(pwre_kroot)/tools/bld/src/$(type_name)_generic.mk
endif
-include ../../special.mk
-include ../special.mk
-include special.mk
/*
* Proview $Id: rt_io_m_motioncontrol_usb.c,v 1.1 2007-11-22 13:28:59 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* rt_io_m_motioncontrol_usbio.c -- I/O methods for class MotionControl_USBIO. */
#include "pwr.h"
#include "pwr_basecomponentclasses.h"
#include "pwr_otherioclasses.h"
#include "rt_io_base.h"
#include "rt_io_rack_init.h"
#include "rt_io_rack_close.h"
#include "rt_io_msg.h"
#include "libusbio.h"
#include "rt_io_m_motioncontrol_usb.h"
static pwr_tStatus IoRackInit( io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp)
{
io_sLocalUSB *local;
int status;
int i;
unsigned int snum;
int found;
io_sCard *cp;
pwr_sClass_MotionControl_USB *op = (pwr_sClass_MotionControl_USB *)rp->op;
local = (io_sLocalUSB *) calloc( 1, sizeof(io_sLocalUSB));
rp->Local = local;
for ( i = 0; i < (int)sizeof(local->USB_Handle); i++) {
status = USBIO_Open( &local->USB_Handle[i]);
if ( status) {
if ( i == 0)
op->Status = status;
break;
}
/* Check is this card is configured */
status = USBIO_GetSerialNr( &local->USB_Handle[i], &snum);
if ( !status) {
found = 0;
for ( cp = rp->cardlist; cp; cp = cp->next) {
if ( ((pwr_sClass_MotionControl_USBIO *)cp->op)->Super.Address == snum) {
local->snum[i] = snum;
found = 1;
break;
}
}
if ( !found) {
errh_Info( "USBIO Serial number %d not configured", snum);
op->Status = USBIO_Close( &local->USB_Handle[i]);
i--;
continue;
}
}
else
errh_Error( "USBIO Serial number error '%s'", rp->Name);
}
errh_Info( "Init of USBIO rack '%s'", rp->Name);
return IO__SUCCESS;
}
static pwr_tStatus IoRackClose( io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp)
{
io_sLocalUSB *local = rp->Local;
pwr_sClass_MotionControl_USB *op = (pwr_sClass_MotionControl_USB *)rp->op;
int i;
for ( i = 0; i < (int)sizeof(local->USB_Handle); i++) {
if ( local->USB_Handle[i])
USBIO_Close( &local->USB_Handle[i]);
else
break;
}
op->Status = 0;
return IO__SUCCESS;
}
/* Every method should be registred here. */
pwr_dExport pwr_BindIoMethods(MotionControl_USB) = {
pwr_BindIoMethod(IoRackInit),
pwr_BindIoMethod(IoRackClose),
pwr_NullMethod
};
/* ra_io_m_motioncontrol_usb.h -- I/O methods for class MotionControl_USBIO. */
#ifndef ra_io_m_motioncontrol_usb_h
#define ra_io_m_motioncontrol_usb_h
#define USB_MAX_CARDS 50
typedef struct {
int USB_Handle[USB_MAX_CARDS];
unsigned int snum[USB_MAX_CARDS];
} io_sLocalUSB;
#endif
/*
* Proview $Id: rt_io_m_motioncontrol_usbio.c,v 1.1 2007-11-22 13:28:59 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* rt_io_m_motioncontrol_usbio.c -- I/O methods for class MotionControl_USBIO. */
#include "pwr.h"
#include "pwr_basecomponentclasses.h"
#include "pwr_otherioclasses.h"
#include "rt_io_base.h"
#include "rt_io_card_init.h"
#include "rt_io_card_close.h"
#include "rt_io_card_read.h"
#include "rt_io_card_write.h"
#include "rt_io_msg.h"
#include "libusbio.h"
#include "rt_io_m_motioncontrol_usb.h"
typedef struct {
pwr_tTime ErrTime;
int USB_Handle;
int portA_hasDi;
int portA_hasDo;
int portA_diMask;
int portA_doMask;
int portB_hasDi;
int portB_hasDo;
int portB_hasAi;
int portB_diMask;
int portB_doMask;
int portB_aiMask;
int portC_hasDi;
int portC_hasDo;
int portC_hasAo;
int portC_hasIi;
int portC_diMask;
int portC_doMask;
int portC_aoMask;
} io_sLocal;
static pwr_tStatus IoCardInit( io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp)
{
int found = 0;
int i;
unsigned char port_mask[3] = {255,255,63};
unsigned char port[3] = {0,0,0};
int active;
int timeout;
io_sLocal *local;
io_sLocalUSB *localUSB = (io_sLocalUSB *)rp->Local;
pwr_sClass_MotionControl_USBIO *op = (pwr_sClass_MotionControl_USBIO *)cp->op;
local = (io_sLocal *) calloc( 1, sizeof(io_sLocal));
cp->Local = local;
/* Find the handle in rack local data */
for ( i = 0; i < (int)sizeof(localUSB->USB_Handle); i++) {
if ( localUSB->snum[i] == op->Super.Address) {
found = 1;
local->USB_Handle = localUSB->USB_Handle[i];
break;
}
}
if ( !found) {
errh_Error( "Io init error, USBIO card not found '%s'", cp->Name);
op->Status = pwr_eMotionControl_StatusEnum_FindDevice;
return 0;
}
op->Status = USBIO_SoftReset( &local->USB_Handle);
if ( op->Status)
errh_Error( "IO Init Card '%s', Status %d", cp->Name, op->Status);
/* Configure port A */
local->portA_hasDi = 0;
local->portA_hasDo = 0;
local->portA_diMask = 0;
local->portA_doMask = 0;
for ( i = 0; i < 8; i++) {
if ( cp->chanlist[i].cop &&
cp->chanlist[i].sop &&
cp->chanlist[i].ChanClass == pwr_cClass_ChanDi) {
local->portA_hasDi = 1;
local->portA_diMask |= (1 << i);
}
else if ( cp->chanlist[i].cop &&
cp->chanlist[i].sop &&
cp->chanlist[i].ChanClass == pwr_cClass_ChanDo) {
local->portA_hasDo = 1;
local->portA_doMask |= (1 << i);
}
}
if ( local->portA_hasDi || local->portA_hasDo) {
op->Status = USBIO_ConfigDIO( &local->USB_Handle, 1, local->portA_diMask);
if ( op->Status)
errh_Error( "IO Init Card '%s', Status %d", cp->Name, op->Status);
}
/* Configure port B */
local->portB_hasDi = 0;
local->portB_hasDo = 0;
local->portB_hasAi = 0;
for ( i = 8; i < 16; i++) {
if ( cp->chanlist[i].cop &&
cp->chanlist[i].sop &&
cp->chanlist[i].ChanClass == pwr_cClass_ChanDi) {
local->portB_hasDi = 1;
local->portB_diMask |= (1 << (i - 8));
}
else if ( cp->chanlist[i].cop &&
cp->chanlist[i].sop &&
cp->chanlist[i].ChanClass == pwr_cClass_ChanDo) {
local->portB_hasDo = 1;
local->portB_doMask |= (1 << (i - 8));
}
if ( cp->chanlist[i].cop &&
cp->chanlist[i].sop &&
(cp->chanlist[i].ChanClass == pwr_cClass_ChanAi ||
cp->chanlist[i].ChanClass == pwr_cClass_ChanAit)) {
local->portB_hasAi = 1;
local->portB_aiMask |= (1 << (i - 8));
// Calculate conversion coefficients
io_AiRangeToCoef( &cp->chanlist[i]);
}
}
if ( local->portB_hasAi) {
int num_ai;
for ( i = 0; i < 8; i++) {
if ( local->portB_aiMask & (1 << i))
num_ai = i + 1;
}
op->Status = USBIO_ConfigAI( &local->USB_Handle, num_ai);
if ( op->Status)
errh_Error( "IO Init Card '%s', Status %d", cp->Name, op->Status);
}
else
op->Status = USBIO_ConfigAI( &local->USB_Handle, 0);
if ( local->portB_hasDi || local->portB_hasDo) {
op->Status = USBIO_ConfigDIO( &local->USB_Handle, 2, local->portB_diMask);
if ( op->Status)
errh_Error( "IO Init Card '%s', Status %d", cp->Name, op->Status);
}
/* Configure port C */
local->portC_hasDi = 0;
local->portC_hasDo = 0;
local->portC_hasAo = 0;
for ( i = 16; i < 21; i++) {
if ( cp->chanlist[i].cop &&
cp->chanlist[i].sop &&
cp->chanlist[i].ChanClass == pwr_cClass_ChanDi) {
local->portC_hasDi = 1;
local->portC_diMask |= (1 << (i - 16));
}
else if ( cp->chanlist[i].cop &&
cp->chanlist[i].sop &&
cp->chanlist[i].ChanClass == pwr_cClass_ChanDo) {
local->portC_hasDo = 1;
local->portC_doMask |= (1 << (i - 16));
}
if ( cp->chanlist[i].cop &&
cp->chanlist[i].sop &&
cp->chanlist[i].ChanClass == pwr_cClass_ChanAo) {
local->portC_hasAo = 1;
local->portC_aoMask |= (1 << (i - 16));
// Calculate conversion coefficients
io_AoRangeToCoef( &cp->chanlist[i]);
}
}
if ( cp->chanlist[18].cop &&
cp->chanlist[18].sop &&
cp->chanlist[18].ChanClass == pwr_cClass_ChanIi)
local->portC_hasIi = 1;
if ( local->portC_hasAo) {
op->Status = USBIO_ConfigAO( &local->USB_Handle, local->portC_aoMask >> 3);
if ( op->Status)
errh_Error( "IO Init Card '%s', Status %d", cp->Name, op->Status);
}
else
op->Status = USBIO_ConfigAO( &local->USB_Handle, 0);
if ( local->portC_hasIi) {
op->Status = USBIO_ConfigCounter( &local->USB_Handle, 0);
if ( op->Status)
errh_Error( "IO Init Card '%s', Status %d", cp->Name, op->Status);
}
if ( local->portC_hasDi || local->portC_hasDo) {
op->Status = USBIO_ConfigDIO( &local->USB_Handle, 3, local->portC_diMask);
if ( op->Status)
errh_Error( "IO Init Card '%s', Status %d", cp->Name, op->Status);
}
// Configure Watchdog
if ( op->WatchdogTime > 0)
active = 1;
else
active = 0;
timeout = 1000 * op->WatchdogTime;
op->Status = USBIO_ConfigWatchdog( &local->USB_Handle, active, timeout, 1, port_mask, port, 3);
errh_Info( "Init of USBIO card '%s'", cp->Name);
return IO__SUCCESS;
}
static pwr_tStatus IoCardClose( io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp)
{
free( cp->Local);
return IO__SUCCESS;
}
static pwr_tStatus IoCardRead( io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp)
{
io_sLocal *local = cp->Local;
pwr_sClass_MotionControl_USBIO *op = (pwr_sClass_MotionControl_USBIO *)cp->op;
int value = 0;
int i;
unsigned int m;
pwr_tUInt32 error_count = op->Super.ErrorCount;
if ( local->portA_hasDi) {
op->Status = USBIO_ReadDI( &local->USB_Handle, 1, &value);
if ( op->Status)
op->Super.ErrorCount++;
else {
m = 1;
for ( i = 0; i < 8; i++) {
if ( m & local->portA_diMask)
*(pwr_tBoolean *)cp->chanlist[i].vbp = ((value & m) != 0);
m = m << 1;
}
}
}
if ( local->portB_hasDi) {
op->Status = USBIO_ReadDI( &local->USB_Handle, 2, &value);
if ( op->Status)
op->Super.ErrorCount++;
else {
m = 1;
for ( i = 0; i < 8; i++) {
if ( m & local->portB_diMask)
*(pwr_tBoolean *)cp->chanlist[i+8].vbp = ((value & m) != 0);
m = m << 1;
}
}
}
if ( local->portB_hasAi) {
int ivalue;
pwr_tFloat32 actvalue;
// op->Status = USBIO_ReadAllAI( &local->USB_Handle, avalue);
m = 1;
for ( i = 0; i < 8; i++) {
if ( m & local->portB_aiMask) {
io_sChannel *chanp = &cp->chanlist[i + 8];
pwr_sClass_ChanAi *cop = (pwr_sClass_ChanAi *)chanp->cop;
pwr_sClass_Ai *sop = (pwr_sClass_Ai *)chanp->sop;
if ( cop->CalculateNewCoef)
// Request to calculate new coefficients
io_AiRangeToCoef( chanp);
op->Status = USBIO_ReadADVal( &local->USB_Handle, i + 1, &ivalue);
if ( op->Status)
op->Super.ErrorCount++;
else {
io_ConvertAi( cop, ivalue, &actvalue);
// Filter
if ( sop->FilterType == 1 &&
sop->FilterAttribute[0] > 0 &&
sop->FilterAttribute[0] > ctx->ScanTime) {
actvalue = *(pwr_tFloat32 *)chanp->vbp + ctx->ScanTime / sop->FilterAttribute[0] *
(actvalue - *(pwr_tFloat32 *)chanp->vbp);
}
*(pwr_tFloat32 *)chanp->vbp = actvalue;
sop->SigValue = cop->SigValPolyCoef1 * ivalue + cop->SigValPolyCoef0;
sop->RawValue = ivalue;
}
}
m = m << 1;
}
}
if ( local->portC_hasDi) {
op->Status = USBIO_ReadDI( &local->USB_Handle, 3, &value);
if ( op->Status)
op->Super.ErrorCount++;
else {
m = 1;
for ( i = 0; i < 5; i++) {
if ( m & local->portC_diMask)
*(pwr_tBoolean *)cp->chanlist[i+16].vbp = ((value & m) != 0);
m = m << 1;
}
}
}
if ( local->portC_hasIi) {
int overflow;
unsigned int covalue;
op->Status = USBIO_ReadCounter( &local->USB_Handle, &covalue, &overflow);
if ( op->Status)
op->Super.ErrorCount++;
else {
if ( !overflow) {
*(pwr_tUInt32 *)cp->chanlist[18].vbp = covalue;
}
else {
// Reset counter
op->Status = USBIO_ConfigCounter( &local->USB_Handle, 2);
*(pwr_tUInt32 *)cp->chanlist[18].vbp = 0;
}
}
}
if ( op->Super.ErrorCount >= op->Super.ErrorSoftLimit &&
error_count < op->Super.ErrorSoftLimit)
errh_Warning( "IO Card ErrorSoftLimit reached, '%s'", cp->Name);
if ( op->Super.ErrorCount >= op->Super.ErrorHardLimit) {
errh_Error( "IO Card ErrorHardLimit reached '%s', IO stopped", cp->Name);
ctx->Node->EmergBreakTrue = 1;
return IO__ERRDEVICE;
}
return IO__SUCCESS;
}
static pwr_tStatus IoCardWrite( io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp)
{
io_sLocal *local = cp->Local;
pwr_sClass_MotionControl_USBIO *op = (pwr_sClass_MotionControl_USBIO *)cp->op;
int value = 0;
float fvalue;
int i;
unsigned int m;
pwr_tUInt32 error_count = op->Super.ErrorCount;
if ( local->portA_hasDo) {
m = 1;
value = 0;
for ( i = 0; i < 8; i++) {
if ( m & local->portA_doMask) {
if ( *(pwr_tBoolean *)cp->chanlist[i].vbp)
value |= m;
}
m = m << 1;
}
op->Status = USBIO_WriteDO( &local->USB_Handle, 1, value);
if ( op->Status) op->Super.ErrorCount++;
}
if ( local->portB_hasDo) {
m = 1;
value = 0;
for ( i = 0; i < 8; i++) {
if ( m & local->portB_doMask) {
if (*(pwr_tBoolean *)cp->chanlist[i+8].vbp)
value |= m;
}
m = m << 1;
}
op->Status = USBIO_WriteDO( &local->USB_Handle, 2, value);
if ( op->Status) op->Super.ErrorCount++;
}
if ( local->portC_hasDo) {
m = 1;
value = 0;
for ( i = 0; i < 5; i++) {
if ( m & local->portC_doMask) {
if (*(pwr_tBoolean *)cp->chanlist[i+16].vbp)
value |= m;
}
m = m << 1;
}
op->Status = USBIO_WriteDO( &local->USB_Handle, 3, value);
if ( op->Status) op->Super.ErrorCount++;
}
if ( local->portC_hasAo) {
pwr_sClass_ChanAo *cop;
if ( local->portC_aoMask & 8) {
cop = (pwr_sClass_ChanAo *)cp->chanlist[19].cop;
if ( cop->CalculateNewCoef)
// Request to calculate new coefficients
io_AoRangeToCoef( &cp->chanlist[19]);
fvalue = *(pwr_tFloat32 *)cp->chanlist[19].vbp * cop->OutPolyCoef1 + cop->OutPolyCoef0;
if ( fvalue < 0)
fvalue = 0;
else if (fvalue > 5)
fvalue = 5;
op->Status = USBIO_WriteAO( &local->USB_Handle, 1, fvalue);
if ( op->Status) op->Super.ErrorCount++;
}
if ( local->portC_aoMask & 16) {
cop = (pwr_sClass_ChanAo *)cp->chanlist[20].cop;
if ( cop->CalculateNewCoef)
// Request to calculate new coefficients
io_AoRangeToCoef( &cp->chanlist[20]);
fvalue = *(pwr_tFloat32 *)cp->chanlist[20].vbp * cop->OutPolyCoef1 + cop->OutPolyCoef0;
if ( fvalue < 0)
fvalue = 0;
else if (fvalue > 5)
fvalue = 5;
op->Status = USBIO_WriteAO( &local->USB_Handle, 2, fvalue);
if ( op->Status) op->Super.ErrorCount++;
}
}
if ( op->Super.ErrorCount >= op->Super.ErrorSoftLimit &&
error_count < op->Super.ErrorSoftLimit)
errh_Warning( "IO Card ErrorSoftLimit reached, '%s'", cp->Name);
if ( op->Super.ErrorCount >= op->Super.ErrorHardLimit) {
errh_Error( "IO Card ErrorHardLimit reached '%s', IO stopped", cp->Name);
ctx->Node->EmergBreakTrue = 1;
return IO__ERRDEVICE;
}
return IO__SUCCESS;
}
/* Every method should be registred here. */
pwr_dExport pwr_BindIoMethods(MotionControl_USBIO) = {
pwr_BindIoMethod(IoCardInit),
pwr_BindIoMethod(IoCardClose),
pwr_BindIoMethod(IoCardRead),
pwr_BindIoMethod(IoCardWrite),
pwr_NullMethod
};
MotionControl_USB
MotionControl_USBIO
include $(pwre_dir_symbols)
-include $(pwre_kroot)/tools/bld/src/$(os_name)/$(hw_name)/$(type_name)_generic.mk
ifeq ($($(type_name)_generic_mk),)
-include $(pwre_kroot)/tools/bld/src/$(os_name)/$(type_name)_generic.mk
endif
ifeq ($($(type_name)_generic_mk),)
include $(pwre_kroot)/tools/bld/src/$(type_name)_generic.mk
endif
-include ../../special.mk
-include ../special.mk
-include special.mk
include $(pwre_dir_symbols)
-include $(pwre_kroot)/tools/bld/src/$(os_name)/$(hw_name)/$(type_name)_generic.mk
ifeq ($($(type_name)_generic_mk),)
-include $(pwre_kroot)/tools/bld/src/$(os_name)/$(type_name)_generic.mk
endif
ifeq ($($(type_name)_generic_mk),)
include $(pwre_kroot)/tools/bld/src/$(type_name)_generic.mk
endif
-include ../../special.mk
-include ../special.mk
-include special.mk
Volume OtherIO $ClassVolume 0.0.250.10
Body SysBody 01-JAN-1970 01:00:00.00
Attr NextOix = "_X31"
Attr NextCix = "_X3"
Attr NextTix[0] = "_X2"
EndBody
Object Type $TypeHier 1 15-NOV-2007 14:35:37.90
Object MotionControl_StatusEnum $TypeDef 1 15-NOV-2007 14:36:24.17
Body SysBody 15-NOV-2007 14:36:24.17
Attr TypeRef = "pwrs:Type-$Enum"
Attr Elements = 1
EndBody
Object Success $Value 3 15-NOV-2007 14:36:24.17
Body SysBody 15-NOV-2007 14:36:24.17
Attr Text = "Success"
Attr PgmName = "Success"
EndBody
EndObject
Object FindDevice $Value 4 15-NOV-2007 14:36:24.17
Body SysBody 15-NOV-2007 14:36:24.17
Attr Text = "Unable to find device"
Attr PgmName = "FindDevice"
Attr Value = 1
EndBody
EndObject
Object ConnectDevice $Value 5 15-NOV-2007 14:36:24.17
Body SysBody 15-NOV-2007 14:36:24.17
Attr Text = "Unable to connect to device"
Attr PgmName = "ConnectDevice"
Attr Value = 2
EndBody
EndObject
Object NotConnected $Value 6 15-NOV-2007 14:36:24.17
Body SysBody 15-NOV-2007 14:36:24.17
Attr Text = "Device not connected"
Attr PgmName = "NotConnected"
Attr Value = 8
EndBody
EndObject
Object Write $Value 7 15-NOV-2007 14:36:24.17
Body SysBody 15-NOV-2007 14:36:24.17
Attr Text = "Unable to write to device"
Attr PgmName = "Write"
Attr Value = 10
EndBody
EndObject
Object WriteFind $Value 8 15-NOV-2007 14:36:24.17
Body SysBody 15-NOV-2007 14:36:24.17
Attr Text = "Unable to find device at write"
Attr PgmName = "WriteFind"
Attr Value = 11
EndBody
EndObject
Object Read $Value 9 15-NOV-2007 14:36:24.17
Body SysBody 15-NOV-2007 14:36:24.17
Attr Text = "Unable to read device"
Attr PgmName = "Read"
Attr Value = 12
EndBody
EndObject
Object ReadTimeout $Value 10 15-NOV-2007 14:36:24.17
Body SysBody 15-NOV-2007 14:36:24.17
Attr Text = "Read timeout"
Attr PgmName = "ReadTimeout"
Attr Value = 13
EndBody
EndObject
Object CommandReply $Value 11 15-NOV-2007 14:36:24.17
Body SysBody 15-NOV-2007 14:36:24.17
Attr Text = "Error in command reply"
Attr PgmName = "CommandReply"
Attr Value = 14
EndBody
EndObject
Object Command $Value 12 15-NOV-2007 14:36:24.17
Body SysBody 15-NOV-2007 14:36:24.17
Attr Text = "No such command (USBIO)"
Attr PgmName = "Command"
Attr Value = 15
EndBody
EndObject
Object Parameter $Value 13 15-NOV-2007 14:36:24.17
Body SysBody 15-NOV-2007 14:36:24.17
Attr Text = "Parameter error"
Attr PgmName = "Parameter"
Attr Value = 16
EndBody
EndObject
Object Function $Value 14 15-NOV-2007 14:36:24.17
Body SysBody 15-NOV-2007 14:36:24.17
Attr Text = "Unable to activate function"
Attr PgmName = "Function"
Attr Value = 17
EndBody
EndObject
Object NotActivated $Value 15 15-NOV-2007 14:36:24.17
Body SysBody 15-NOV-2007 14:36:24.17
Attr Text = "Not activated, execute configuration"
Attr PgmName = "NotActivated"
Attr Value = 18
EndBody
EndObject
Object Checksum $Value 16 15-NOV-2007 14:36:24.17
Body SysBody 15-NOV-2007 14:36:24.17
Attr Text = "Checksum error"
Attr PgmName = "Checksum"
Attr Value = 19
EndBody
EndObject
Object SPI $Value 17 15-NOV-2007 14:36:24.17
Body SysBody 15-NOV-2007 14:36:24.17
Attr Text = "SPI error"
Attr PgmName = "SPI"
Attr Value = 21
EndBody
EndObject
Object ADSwitch $Value 18 15-NOV-2007 14:36:24.17
Body SysBody 15-NOV-2007 14:36:24.17
Attr Text = "AD switch error"
Attr PgmName = "ADSwitch"
Attr Value = 22
EndBody
EndObject
Object Hardware $Value 19 15-NOV-2007 14:36:24.17
Body SysBody 15-NOV-2007 14:36:24.17
Attr Text = "Not working in this hardware"
Attr PgmName = "Hardware"
Attr Value = 23
EndBody
EndObject
Object Unknown $Value 20 15-NOV-2007 14:36:24.17
Body SysBody 15-NOV-2007 14:36:24.17
Attr Text = "Unknown error"
Attr PgmName = "Unknown"
Attr Value = 30
EndBody
EndObject
EndObject
EndObject
Object Class $ClassHier 2 15-NOV-2007 14:35:40.72
!/**
! @Version 1.0
! @Group IO
! @Summary Rack object for Motion Control USB I/O.
! Rack object for Motion Control USB I/O.
!
! @classlink MotionControl_USBIO otherio_motioncontrol_usbio.html
! @link Datasheet ../dsh/motioncontrol_usbio.pdf
!*/
Object MotionControl_USB $ClassDef 1 15-NOV-2007 14:36:42.44
Body SysBody 21-NOV-2007 14:53:31.69
Attr Editor = 0
Attr Method = 0
Attr Flags = 10320
EndBody
Object RtBody $ObjBodyDef 1 15-NOV-2007 14:36:42.44
Body SysBody 15-NOV-2007 14:36:42.44
Attr StructName = "MotionControl_USB"
Attr NextAix = "_X13"
EndBody
!/**
! Optional description.
!*/
Object Description $Attribute 9 15-NOV-2007 14:36:42.44
Body SysBody 15-NOV-2007 14:36:42.44
Attr PgmName = "Description"
Attr TypeRef = "pwrs:Type-$String80"
EndBody
EndObject
!/**
! @Summary Process that handles the card. Plc(1), rt_io_comm(2) or application process(4).
! Process that handles the card.
!
! 1: The card is read by the plc process, and is handled by a specific
! thread in the plc, which is specified in the ThreadObject attribute.
! 2: The card is read by the rt_io_comm process.
! 4: The card is handled by an application program.
!*/
Object Process $Attribute 10 15-NOV-2007 14:36:42.44
Body SysBody 15-NOV-2007 14:36:42.44
Attr PgmName = "Process"
Attr TypeRef = "pwrs:Type-$UInt32"
EndBody
EndObject
!/**
! @Summary Plc thread that handles the card.
! The PlcThread object of the plc thread that handles the card.
! The card is read with the scantime of the thread.
!*/
Object ThreadObject $Attribute 11 15-NOV-2007 14:36:42.44
Body SysBody 15-NOV-2007 14:36:42.44
Attr PgmName = "ThreadObject"
Attr TypeRef = "pwrs:Type-$Objid"
EndBody
EndObject
!/**
! Status from the USB I/O driver.
!*/
Object Status $Attribute 12 15-NOV-2007 14:36:42.44
Body SysBody 15-NOV-2007 14:37:27.63
Attr PgmName = "Status"
Attr Flags = 1040
Attr TypeRef = "OtherIO:Type-MotionControl_StatusEnum"
EndBody
EndObject
EndObject
Object ConfiguratorPoson $Menu 21 15-NOV-2007 14:36:42.44
Object Pointed $Menu 22 15-NOV-2007 14:36:42.44
Object Connect $MenuButton 23 15-NOV-2007 14:36:42.44
Body SysBody 15-NOV-2007 14:36:42.44
Attr ButtonName = "Connect PlcThread"
Attr MethodName = "$Objid-Connect"
Attr MethodArguments[0] = "ThreadObject"
Attr MethodArguments[1] = "PlcThread"
Attr FilterName = "$Objid-IsOkConnect"
Attr FilterArguments[0] = "ThreadObject"
Attr FilterArguments[1] = "PlcThread"
EndBody
EndObject
EndObject
EndObject
Object IoMethods $RtMethod 24 15-NOV-2007 14:36:42.44
Object IoRackInit $Method 25 15-NOV-2007 14:36:42.44
Body SysBody 15-NOV-2007 14:36:42.44
Attr MethodName = "MotionControl_USB-IoRackInit"
EndBody
EndObject
Object IoRackClose $Method 26 15-NOV-2007 14:36:42.44
Body SysBody 21-NOV-2007 14:50:39.55
Attr MethodName = "MotionControl_USB-IoRackClose"
EndBody
EndObject
EndObject
Object Template MotionControl_USB 2147975168 01-JAN-1970 01:00:00.00
Body RtBody 15-NOV-2007 14:37:52.21
Attr Process = 1
EndBody
EndObject
EndObject
!/**
! @Version 1.0
! @Group IO
! @Summary Card object for Motion Control USB I/O.
! Card object for Motion Control USB I/O.
!
! Motion Control USB I/O is an I/O connected to the USB bus.
! The device has 21 channels, divided in ports A, B and C.
! The channels are configured by placing channel objects under the
! card object. The Number attribute in the channel object states which
! channel it represents. Below is a list of how the channels can be
! configured.
!
! Channel Type Number
! ------------------------------------------
! A1 ChanDo 0
! A2 ChanDo 1
! A3 ChanDo 2
! A4 ChanDo 3
! A5 ChanDi 4
! A6 ChanDi 5
! A7 ChanDi 6
! A8 ChanDi 7
! B1 ChanDi, ChanDo or ChanAi 8
! B2 ChanDi, ChanDo or ChanAi 9
! B3 ChanDi, ChanDo or ChanAi 10
! B4 ChanDi, ChanDo or ChanAi 11
! B5 ChanDi, ChanDo or ChanAi 12
! B6 ChanDi, ChanDo or ChanAi 13
! B7 ChanDi, ChanDo or ChanAi 14
! B8 ChanDi, ChanDo or ChanAi 15
! C1 ChanDi, ChanDo 16
! C2 ChanDi, ChanDo 17
! C3 ChanDi, ChanDo 18
! C4 ChanDi, ChanDo or ChanAo 19
! C5 ChanDi, ChanDo or ChanAo 20
!
! @b Ai configuration
! The Ai channels has the rawvalue range 0-1023, and the signal value
! range 0 - 5 V, i.e. the RawValRange and ChannelSigValRange should
! be set to:
!
! RawValRangeLow 0
! RawValRangeHigh 1023
! ChannelSigValRangeLow 0
! ChannelSigValRangeHigh 5
!
! For example to get ActualValue range to 0 - 100 set
! SensorSigValRangeLow 0
! SensorSigValRangeHigh 5
! ActValRangeLow 0
! ActValRangeHigh 100
!
! @b Ao configuration
! The Ao channels has the rawvalue range 0 - 5, and the signal value
! range 0 - 5 V, i.e. the RawValRange and ChannelSigValRange should
! be set to:
!
! RawValRangeLow 0
! RawValRangeHigh 5
! ChannelSigValRangeLow 0
! ChannelSigValRangeHigh 5
!
! For example to get ActualValue range to 0 - 100 set
! SensorSigValRangeLow 0
! SensorSigValRangeHigh 5
! ActValRangeLow 0
! ActValRangeHigh 100
!
! @classlink MotionControl_USB otherui_motioncontrol_usb.html
! @link Datasheet ../dsh/motioncontrol_usbio.pdf
!*/
Object MotionControl_USBIO $ClassDef 2 15-NOV-2007 14:36:59.65
Body SysBody 21-NOV-2007 14:53:39.42
Attr Editor = 0
Attr Method = 0
Attr Flags = 18448
EndBody
Object RtBody $ObjBodyDef 1 15-NOV-2007 14:36:59.65
Body SysBody 15-NOV-2007 14:36:59.65
Attr StructName = "MotionControl_USBIO"
Attr NextAix = "_X10"
EndBody
!/**
! Super class.
!*/
Object Super $Attribute 7 15-NOV-2007 14:36:59.65
Body SysBody 15-NOV-2007 14:36:59.65
Attr PgmName = "Super"
Attr Flags = 393216
Attr TypeRef = "BaseComponent:Class-BaseIOCard"
EndBody
EndObject
!/**
! Status from the USB I/O driver.
!*/
Object Status $Attribute 8 15-NOV-2007 14:36:59.65
Body SysBody 15-NOV-2007 14:37:35.55
Attr PgmName = "Status"
Attr Flags = 1040
Attr TypeRef = "OtherIO:Type-MotionControl_StatusEnum"
EndBody
EndObject
!/**
! Watchdog time in seconds.
! If the device is not written to within this time, the device will be reset.
! If WatchdogTime is zero, the watchdog is not activated.
!*/
Object WatchdogTime $Attribute 9 15-NOV-2007 14:36:59.65
Body SysBody 15-NOV-2007 14:36:59.65
Attr PgmName = "WatchdogTime"
Attr TypeRef = "pwrs:Type-$Float32"
EndBody
EndObject
EndObject
Object IoMethods $RtMethod 27 15-NOV-2007 14:36:59.65
Object IoCardInit $Method 28 15-NOV-2007 14:36:59.65
Body SysBody 15-NOV-2007 14:36:59.65
Attr MethodName = "MotionControl_USBIO-IoCardInit"
EndBody
EndObject
Object IoCardClose $Method 29 15-NOV-2007 14:36:59.65
Body SysBody 15-NOV-2007 14:36:59.65
Attr MethodName = "MotionControl_USBIO-IoCardClose"
EndBody
EndObject
Object IoCardRead $Method 30 15-NOV-2007 14:36:59.65
Body SysBody 15-NOV-2007 14:36:59.65
Attr MethodName = "MotionControl_USBIO-IoCardRead"
EndBody
EndObject
Object IoCardWrite $Method 31 15-NOV-2007 14:36:59.65
Body SysBody 15-NOV-2007 14:36:59.65
Attr MethodName = "MotionControl_USBIO-IoCardWrite"
EndBody
EndObject
EndObject
Object Template MotionControl_USBIO 2148237312 01-JAN-1970 01:00:00.00
Body RtBody 15-NOV-2007 14:38:59.75
Attr Super.Specification = "Motion Control USB I/O"
Attr Super.DataSheet = "../dsh/motioncontrol_usbio.pdf"
Attr Super.Process = 1
Attr Super.ErrorSoftLimit = 50
Attr Super.ErrorHardLimit = 100
Attr Super.MaxNoOfChannels = 21
Attr WatchdogTime = 2.000000e+00
EndBody
EndObject
EndObject
EndObject
EndVolume
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment