/*  Copyright (C) MOXA Inc. All rights reserved.

    This software is distributed under the terms of the
    MOXA License.  See the file COPYING-MOXA for details.
*/
/*
    mxcan_read.cpp

    This is for the read of canbus data.

    2010-10-31	Epson Chiang
		new release
*/

#include "stdafx.h"
#include "stdafx.h"
#include <windows.h>
#include "..\SDK\mxcanbus.h"


int _tmain(int argc, _TCHAR* argv[])
{
	unsigned int nRet;
	int fd;
	int port = 0;
	CANBST stat;

	printf("Enter can port number:");
	scanf("%d",&port);

	/*Open can port*/
	fd = mxcan_open(port);

	/*Get the bus timing*/
	nRet=mxcan_get_stat(fd,&stat);
	if(nRet){
		printf("mxcan_get_stat fail.\r\n");
	}

	printf("bus_error_count=%d\r\n",stat.bus_error_count);
	printf("data_overrun_count=%d\r\n",stat.data_overrun_count);
	printf("error_warning_limit=%d\r\n",stat.error_warning_limit);
	printf("rx_errors=%d\r\n",stat.rx_errors);
	printf("status_error_count=%d\r\n",stat.status_error_count);
	printf("tx_errors=%d\r\n",stat.tx_errors);
	printf("warning_error_count=%d\r\n",stat.warning_error_count);


	/*Close can port*/
	mxcan_close(fd);
	return 0;
}

