I have asked this question before, but my problem is not yet solved. I have to bother you professional guys again. My situation is that:
I need to build an interface of CAN bus using G120 and CAN_DW modules, the structure is like the picture shows. I read the instructions and write some codes. But, I still can not transmit or receive messages. When I debug the codes, I use Voltage meter to test the related CPU pins, they have no voltage changing. I think it means that the codes does not work. But, since there are very few example on internet, I do not know what to do. I have struggled with it for two weeks, but no improvement.
the codes:
using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Shapes;
using Microsoft.SPOT.Hardware;
using GHI.Premium.Hardware;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
namespace CAN_DW
{
public partial class Program
{
void ProgramStarted()
{
//initialization CAN
Utility.SetLocalTime(new DateTime(2011, 2, 14, 0, 0, 0));
can_dw2.InitializeCAN(15, 8, 20);
//possible events
can_dw2.DataReceived += new GTM.GHIElectronics.CAN_DW.DataReceivedEventHandler(can_dw2_DataReceived);
can_dw2.ErrorReceived += new GTM.GHIElectronics.CAN_DW.ErrorReceivedEventHandler(can_dw2_ErrorReceived);
can_dw2.PostDone += new GTM.GHIElectronics.CAN_DW.PostMessagesDoneEventHandler(can_dw2_PostDone);
//creat ten CAN messages
Debug.Print("All created CAN messages are:");
can_dw2.msgList = new CAN.Message[10];
for (int i = 0; i < can_dw2.msgList.Length; i++)
{
can_dw2.msgList[i] = new CAN.Message();
can_dw2.msgList[i].ArbID = 0x14;
can_dw2.msgList[i].DLC = 0x01;
can_dw2.msgList[i].Data[0] = (byte)i;
can_dw2.msgList[i].IsEID = false;
can_dw2.msgList[i].IsRTR = false;
Debug.Print("the number "+ (i+1).ToString()+" message is: "+"ID is 0X"+ can_dw2.msgList[i].ArbID.ToString("X") + " DLC is 0X"+ can_dw2.msgList[i].DLC.ToString("X") +" DATA 0 is 0X"+ can_dw2.msgList[i].Data[0].ToString("X"));
Thread.Sleep(500);
}
//Send all of the messages
int numberOfMsgSent = 0;
while (true)
{
// Post messages
can_dw2.PostMessages(0, can_dw2.msgList.Length - numberOfMsgSent);
// Record how many were sent.
numberOfMsgSent += can_dw2.NumMessagesSent;
Debug.Print("number of messages posted "+numberOfMsgSent.ToString());
// If we have sent all of the messgaes, break out of the loop.
if (numberOfMsgSent == can_dw2.msgList.Length)
break;
// Sleep to allow the messages time to transmit.
System.Threading.Thread.Sleep(500);
}
Thread.Sleep(Timeout.Infinite);
}
void can_dw2_PostDone(int numPosted)
{
Debug.Print(numPosted.ToString() + " messages were posted");
}
void can_dw2_ErrorReceived(GHI.Premium.Hardware.CAN sender, GHI.Premium.Hardware.CANErrorReceivedEventArgs args)
{
Debug.Print("CAN error received: " + args.Error.ToString());
}
void can_dw2_DataReceived(GHI.Premium.Hardware.CAN sender, GHI.Premium.Hardware.CANDataReceivedEventArgs args)
{
Debug.Print("nice");
}
}
}