drivers/can_peak_win32/can_peak_win32.c
author greg
Fri, 17 Jul 2009 13:47:39 +0200
changeset 569 ecaac955c16a
parent 566 365d555fc0c6
child 570 c18397a2b035
permissions -rwxr-xr-x
fix message dialog when objdictedit can't find the pdf reader
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents:
diff changeset
     1
/*
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
     2
This file is part of CanFestival, a library implementing CanOpen Stack.
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
     3
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
     4
Copyright (C): Edouard TISSERANT and Francis DUPIN
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
     5
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
     6
See COPYING file for copyrights details.
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
     7
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
     8
This library is free software; you can redistribute it and/or
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
     9
modify it under the terms of the GNU Lesser General Public
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    10
License as published by the Free Software Foundation; either
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    11
version 2.1 of the License, or (at your option) any later version.
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    12
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    13
This library is distributed in the hope that it will be useful,
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    14
but WITHOUT ANY WARRANTY; without even the implied warranty of
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    16
Lesser General Public License for more details.
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    17
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    18
You should have received a copy of the GNU Lesser General Public
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    19
License along with this library; if not, write to the Free Software
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    20
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
38
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents:
diff changeset
    21
*/
9b5bb1dcb4f5 Cygwin port. Still untested. Compiles and link.
etisserant
parents:
diff changeset
    22
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    23
#if defined(WIN32) && !defined(__CYGWIN__)
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    24
#define usleep(micro) Sleep(micro%1000 ? (micro/1000) + 1 : (micro/1000))
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    25
#else
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    26
#include <stdio.h>
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    27
#include <string.h>
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    28
#include <errno.h>
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    29
#include <fcntl.h>
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    30
#endif
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    31
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    32
#include "cancfg.h"
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    33
#include "can_driver.h"
267
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
    34
#include "def.h"
41
e70439f50539 First working cygwin/pcan_light commit. can_peak_win32.c is obfuscated.
etisserant
parents: 38
diff changeset
    35
#ifndef extra_PCAN_init_params
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    36
	#define extra_PCAN_init_params /**/
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    37
#else
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    38
	#define extra_PCAN_init_params\
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    39
		,getenv("PCANHwType") ? strtol(getenv("PCANHwType"),NULL,0):0\
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    40
		,getenv("PCANIO_Port") ? strtol(getenv("PCANIO_Port"),NULL,0):0\
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    41
		,getenv("PCANInterupt") ? strtol(getenv("PCANInterupt"),NULL,0):0
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    42
#endif
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    43
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    44
static s_BOARD *first_board = NULL;
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    45
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    46
//Create the Event for the first board
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    47
HANDLE hEvent1 = NULL;
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    48
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    49
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    50
#ifdef PCAN2_HEADER_
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    51
	static s_BOARD *second_board = NULL;
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    52
	HANDLE hEvent2 = NULL;
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    53
#endif
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    54
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    55
// Define for rtr CAN message
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    56
#define CAN_INIT_TYPE_ST_RTR MSGTYPE_STANDARD | MSGTYPE_RTR
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    57
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    58
/***************************************************************************/
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    59
int TranslateBaudeRate(char* optarg){
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    60
	if(!strcmp( optarg, "1M")) return CAN_BAUD_1M;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    61
	if(!strcmp( optarg, "500K")) return CAN_BAUD_500K;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    62
	if(!strcmp( optarg, "250K")) return CAN_BAUD_250K;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    63
	if(!strcmp( optarg, "125K")) return CAN_BAUD_125K;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    64
	if(!strcmp( optarg, "100K")) return CAN_BAUD_100K;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    65
	if(!strcmp( optarg, "50K")) return CAN_BAUD_50K;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    66
	if(!strcmp( optarg, "20K")) return CAN_BAUD_20K;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    67
	if(!strcmp( optarg, "10K")) return CAN_BAUD_10K;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    68
	if(!strcmp( optarg, "5K")) return CAN_BAUD_5K;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    69
	if(!strcmp( optarg, "none")) return 0;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    70
	return 0x0000;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    71
}
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    72
566
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
    73
UNS8 canInit (s_BOARD *board)
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    74
{
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    75
	int baudrate;
566
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
    76
	int ret = 0;
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    77
329
7717252e3ed9 Changes to compile for win32
greg
parents: 301
diff changeset
    78
#ifdef PCAN2_HEADER_
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    79
	// if not the first handler
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    80
	if(second_board == (s_BOARD *)board) {
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
    81
		if(baudrate = TranslateBaudeRate(board->baudrate))
566
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
    82
		{
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
    83
			ret = CAN2_Init(baudrate, CAN_INIT_TYPE_ST extra_PCAN_init_params);
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
    84
			if(ret != CAN_ERR_OK)
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
    85
				return 0;
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
    86
		}
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    87
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    88
		//Create the Event for the first board
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    89
		hEvent2 = CreateEvent(NULL, // lpEventAttributes
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    90
							FALSE,  // bManualReset
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    91
							FALSE,  // bInitialState
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    92
							"");    // lpName
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    93
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    94
		//Set Event Handle for CANReadExt
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    95
		CAN2_SetRcvEvent(hEvent2);
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    96
	}
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    97
	else
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    98
#endif
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
    99
	if(first_board == (s_BOARD *)board) {
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   100
		if(baudrate = TranslateBaudeRate(board->baudrate))
566
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   101
		{
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   102
			ret = CAN_Init(baudrate, CAN_INIT_TYPE_ST extra_PCAN_init_params);
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   103
			if(ret != CAN_ERR_OK)
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   104
				return 0;
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   105
		}
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   106
		//Create the Event for the first board
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   107
		hEvent1 = CreateEvent(NULL, // lpEventAttributes
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   108
							FALSE,  // bManualReset
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   109
							FALSE,  // bInitialState
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   110
							"");    // lpName
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   111
		//Set Event Handle for CANReadExt
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   112
		CAN_SetRcvEvent(hEvent1);
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   113
	}
566
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   114
	return 1;
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   115
}
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   116
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   117
/********* functions which permit to communicate with the board ****************/
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   118
UNS8 canReceive_driver (CAN_HANDLE fd0, Message * m)
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   119
{
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   120
	int ret=0;
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   121
	UNS8 data;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   122
	TPCANMsg peakMsg;
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   123
	TPCANTimestamp peakRcvTime;
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   124
	DWORD Res;
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   125
	DWORD result;
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   126
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   127
#ifdef PCAN2_HEADER_
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   128
	// if not the first handler
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   129
	if(second_board == (s_BOARD *)fd0) {
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   130
		//wait for CAN msg...
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   131
		result = WaitForSingleObject(hEvent2, INFINITE);
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   132
		if (result == WAIT_OBJECT_0)
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   133
			Res = CAN2_ReadEx(&peakMsg, &peakRcvTime);
566
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   134
			if(Res == (CAN_ERR_QRCVEMPTY | CAN_ERRMASK_ILLHANDLE))
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   135
			{
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   136
				ResetEvent(hEvent2);
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   137
				return 1;
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   138
			}
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   139
	}
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   140
	else
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   141
#endif
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   142
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   143
	// We read the queue looking for messages.
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   144
	if(first_board == (s_BOARD *)fd0) {
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   145
		result = WaitForSingleObject(hEvent1, INFINITE);
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   146
		if (result == WAIT_OBJECT_0)
566
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   147
		{
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   148
			Res = CAN_ReadEx(&peakMsg, &peakRcvTime);
566
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   149
			if(Res == (CAN_ERR_QRCVEMPTY | CAN_ERRMASK_ILLHANDLE))
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   150
			{
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   151
				ResetEvent(hEvent1);
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   152
				return 1;
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   153
			}
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   154
		}
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   155
	}
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   156
	else
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   157
		Res = CAN_ERR_BUSOFF;
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   158
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   159
	// A message was received : we process the message(s)
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   160
	if (Res == CAN_ERR_OK)
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   161
	{
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   162
		// if something different that 11bit or rtr... problem
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   163
		if (peakMsg.MSGTYPE & ~(MSGTYPE_STANDARD | MSGTYPE_RTR))
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   164
		{
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   165
			if (peakMsg.MSGTYPE == CAN_ERR_BUSOFF)
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   166
			{
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   167
				printf ("!!! Peak board read : re-init\n");
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   168
				canInit((s_BOARD*) fd0);
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   169
				usleep (10000);
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   170
			}
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   171
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   172
			// If status, return status if 29bit, return overrun
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   173
			return peakMsg.MSGTYPE ==
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   174
				MSGTYPE_STATUS ? peakMsg.DATA[2] : CAN_ERR_OVERRUN;
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   175
		}
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   176
		m->cob_id = peakMsg.ID;
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   177
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   178
		if (peakMsg.MSGTYPE == CAN_INIT_TYPE_ST)	/* bits of MSGTYPE_ */
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   179
			m->rtr = 0;
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   180
		else
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   181
			m->rtr = 1;
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   182
		m->len = peakMsg.LEN;	/* count of data bytes (0..8) */
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   183
		for (data = 0; data < peakMsg.LEN; data++)
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   184
			m->data[data] = peakMsg.DATA[data];	/* data bytes, up to 8 */
341
7ff01f109bbc Windows related enhancements
etisserant
parents: 329
diff changeset
   185
#if defined DEBUG_MSG_CONSOLE_ON
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   186
		MSG("in : ");
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   187
		print_message(m);
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   188
#endif
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   189
	}
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   190
	else
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   191
	{
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   192
		if (!(Res & CAN_ERR_QRCVEMPTY
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   193
				|| Res & CAN_ERR_BUSLIGHT
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   194
				|| Res & CAN_ERR_BUSHEAVY))
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   195
		{
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   196
			printf ("canReceive returned error (%d)\n", Res);
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   197
			return 1;
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   198
		}
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   199
	}
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   200
	return 0;
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   201
}
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   202
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   203
/***************************************************************************/
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   204
UNS8 canSend_driver (CAN_HANDLE fd0, Message * m)
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   205
{
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   206
	UNS8 data;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   207
	TPCANMsg peakMsg;
365
9b76e0881beb Changed cob_id from struct{UNS32} to UNS16
etisserant
parents: 341
diff changeset
   208
	peakMsg.ID = m->cob_id;	/* 11/29 bit code */
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   209
	if (m->rtr == 0)
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   210
		peakMsg.MSGTYPE = CAN_INIT_TYPE_ST;	/* bits of MSGTYPE_ */
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   211
	else
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   212
	{
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   213
		peakMsg.MSGTYPE = CAN_INIT_TYPE_ST_RTR;	/* bits of MSGTYPE_ */
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   214
	}
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   215
	peakMsg.LEN = m->len;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   216
	/* count of data bytes (0..8) */
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   217
	for (data = 0; data < m->len; data++)
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   218
		peakMsg.DATA[data] = m->data[data];	/* data bytes, up to 8 */
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   219
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   220
	do
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   221
	{
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   222
#ifdef PCAN2_HEADER_
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   223
		// if not the first handler
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   224
		if(second_board == (s_BOARD *)fd0)
267
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
   225
		{
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   226
			errno = CAN2_Write (&peakMsg);
267
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
   227
		}
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   228
		else
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   229
#endif
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   230
		if(first_board == (s_BOARD *)fd0)
267
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
   231
			{
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
   232
				errno = CAN_Write (&peakMsg);
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
   233
			}
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   234
		else
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   235
			goto fail;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   236
		if (errno)
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   237
		{
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   238
			if (errno == CAN_ERR_BUSOFF)
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   239
			{
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   240
				printf ("!!! Peak board write : re-init\n");
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   241
				canInit((s_BOARD*)fd0);
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   242
				usleep (10000);
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   243
			}
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   244
			usleep (1000);
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   245
		}
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   246
	}
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   247
	while (errno != CAN_ERR_OK);
341
7ff01f109bbc Windows related enhancements
etisserant
parents: 329
diff changeset
   248
#if defined DEBUG_MSG_CONSOLE_ON
454
bc000083297a - add RTAI support
greg
parents: 384
diff changeset
   249
	MSG("out : ");
341
7ff01f109bbc Windows related enhancements
etisserant
parents: 329
diff changeset
   250
	print_message(m);
7ff01f109bbc Windows related enhancements
etisserant
parents: 329
diff changeset
   251
#endif
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   252
	return 0;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   253
fail:
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   254
	return 1;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   255
}
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   256
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   257
/***************************************************************************/
384
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 365
diff changeset
   258
UNS8 canChangeBaudRate_driver( CAN_HANDLE fd, char* baud)
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 365
diff changeset
   259
{
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 365
diff changeset
   260
	printf("canChangeBaudRate not yet supported by this driver\n");
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 365
diff changeset
   261
	return 0;
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 365
diff changeset
   262
}
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 365
diff changeset
   263
83793fc7ce48 added canChangeBaudRate to the driver interface
groke6
parents: 365
diff changeset
   264
/***************************************************************************/
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   265
CAN_HANDLE canOpen_driver (s_BOARD * board)
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   266
{
267
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
   267
  char busname[64];
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
   268
  char* pEnd;
566
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   269
  int ret;
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   270
267
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
   271
  //printf ("Board Busname=%d.\n",strtol(board->busname, &pEnd,0));
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
   272
  if (strtol(board->busname, &pEnd,0) == 0)
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
   273
  {
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
   274
      first_board = board;
566
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   275
      //printf ("First Board selected\n");
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   276
      ret = canInit(board);
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   277
      if(ret)
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   278
    	  return (CAN_HANDLE)board;
267
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
   279
  }
329
7717252e3ed9 Changes to compile for win32
greg
parents: 301
diff changeset
   280
  #ifdef PCAN2_HEADER_
267
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
   281
  if (strtol(board->busname, &pEnd,0) == 1)
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
   282
  {
329
7717252e3ed9 Changes to compile for win32
greg
parents: 301
diff changeset
   283
      second_board = board;
566
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   284
      //printf ("Second Board selected\n");
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   285
      ret = canInit(board);
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   286
      if(ret)
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   287
    	  return (CAN_HANDLE)board;
267
96c688ebcde7 Add win32 target (--can=win32) to compile with msys and mingw32
greg
parents: 145
diff changeset
   288
  }
329
7717252e3ed9 Changes to compile for win32
greg
parents: 301
diff changeset
   289
  #endif
7717252e3ed9 Changes to compile for win32
greg
parents: 301
diff changeset
   290
  return NULL;
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   291
}
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   292
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   293
/***************************************************************************/
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   294
int canClose_driver (CAN_HANDLE fd0)
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   295
{
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   296
#ifdef PCAN2_HEADER_
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   297
	// if not the first handler
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   298
	if(second_board == (s_BOARD *)fd0)
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   299
	{
566
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   300
		SetEvent(hEvent2);
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   301
		CAN2_Close ();
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   302
		second_board = (s_BOARD *)NULL;
563
394440e3b6e4 update canReceive_driver to match with Peak new read function (event)
greg
parents: 454
diff changeset
   303
	}else
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   304
#endif
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   305
	if(first_board == (s_BOARD *)fd0)
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   306
	{
566
365d555fc0c6 fixed : unlock and terminate CanReceive loop thread when canclose is called.
greg
parents: 563
diff changeset
   307
		SetEvent(hEvent1);
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   308
		CAN_Close ();
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   309
		first_board = (s_BOARD *)NULL;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   310
	}
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   311
	return 0;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 42
diff changeset
   312
}