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
This diff is collapsed.
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
This diff is collapsed.
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