edouard@629: /* edouard@629: This file is part of CanFestival, a library implementing CanOpen Stack. edouard@629: edouard@629: Copyright (C): Cosateq GmbH & Co.KG edouard@629: http://www.cosateq.com/ edouard@629: http://www.scale-rt.com/ edouard@629: edouard@629: See COPYING file for copyrights details. edouard@629: edouard@629: This library is free software; you can redistribute it and/or edouard@629: modify it under the terms of the GNU Lesser General Public edouard@629: License as published by the Free Software Foundation; either edouard@629: version 2.1 of the License, or (at your option) any later version. edouard@629: edouard@629: This library is distributed in the hope that it will be useful, edouard@629: but WITHOUT ANY WARRANTY; without even the implied warranty of edouard@629: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU edouard@629: Lesser General Public License for more details. edouard@629: edouard@629: You should have received a copy of the GNU Lesser General Public edouard@629: License along with this library; if not, write to the Free Software edouard@629: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA edouard@629: */ edouard@629: edouard@629: /* edouard@629: example for application with CO-PCICAN card. edouard@629: */ edouard@629: edouard@629: #include edouard@629: #include edouard@629: #include edouard@629: #include "canfestival.h" edouard@629: edouard@629: /* only for mdelay() */ edouard@629: #include edouard@629: edouard@629: MODULE_LICENSE("GPL"); edouard@629: edouard@629: #define CHTX 2 /* channel number of the CO-PCICAN */ edouard@629: #define CHRX 0 /* channel number of the CO-PCICAN */ edouard@629: edouard@629: void mySyncHandler( CO_Data* d ) edouard@629: { edouard@629: printk( "test_copcican_comedi: got a SYNC message...\n" ); edouard@629: } edouard@629: edouard@629: static int main( void ) edouard@629: { edouard@629: s_BOARD bd; edouard@629: CO_Data myData; edouard@629: CAN_PORT port; edouard@629: Message myMessage; edouard@629: const char busname[] = "/dev/comedi0"; edouard@629: const char baudrate[] = "1M"; edouard@629: comedi_t *dev; edouard@629: edouard@629: memset( &myData, 0x00, sizeof(CO_Data) ); edouard@629: myData.CurrentCommunicationState.csSYNC = 1; edouard@629: myData.post_sync = mySyncHandler; edouard@629: bd.busname = (char*)busname; edouard@629: bd.baudrate = (char*)baudrate; edouard@629: edouard@629: printk( "test_copcican_comedi: This example sends three SYNCs from port#%u to port#%u with a CO-PCICAN card\n", CHTX, CHRX ); edouard@629: edouard@629: /* direction: 0=RX, 1=TX */ edouard@629: co_pcican_select_channel( CHRX, 0 ); edouard@629: co_pcican_select_channel( CHTX, 1 ); edouard@629: edouard@629: port = canOpen( &bd, &myData ); edouard@629: edouard@629: if( port == NULL ) edouard@629: { edouard@629: /* something strange happenend */ edouard@629: return 0; edouard@629: } edouard@629: edouard@629: /* get device pointer to control the opened device */ edouard@629: dev = get_dev_of_port( port ); edouard@629: edouard@629: co_pcican_enter_config_mode( dev ); edouard@629: co_pcican_configure_selected_channel( dev, &bd, 0 ); edouard@629: co_pcican_configure_selected_channel( dev, &bd, 1 ); edouard@629: co_pcican_enter_run_mode( dev ); edouard@629: edouard@629: memset( &myMessage, 0x00, sizeof(Message) ); edouard@629: myMessage.cob_id = 0x80; /* SYNC message */ edouard@629: myMessage.len = 1; edouard@629: myMessage.data[0] = 0xA5; edouard@629: edouard@629: /* SEND HERE */ edouard@629: canSend( port, &myMessage ); edouard@629: edouard@629: myMessage.data[0] = 0x5A; edouard@629: canSend( port, &myMessage ); edouard@629: edouard@629: myMessage.data[0] = 0xA5; edouard@629: canSend( port, &myMessage ); edouard@629: edouard@629: /* mySyncHandler() is called by the receive thread and shows a received SYNC message in the kernel log */ edouard@629: mdelay( 1*1000 ); /* 1s */ edouard@629: edouard@629: canClose( &myData ); edouard@629: edouard@629: return 0; edouard@629: } edouard@629: edouard@629: static int init(void) edouard@629: { edouard@629: printk("test_copcican_comedi for CanFestival loaded\n"); edouard@629: edouard@629: return main(); edouard@629: } edouard@629: edouard@629: static void exit(void) edouard@629: { edouard@629: printk("test_copcican_comedi unloaded\n"); edouard@629: } edouard@629: edouard@629: module_init(init); edouard@629: module_exit(exit);