/* * Initiates the channel */ public void initChannel(int channel, string bitrate) { Canlib.canStatus status; Canlib.canInitializeLibrary(); int hnd = Canlib.canOpenChannel(channel, Canlib.canOPEN_ACCEPT_VIRTUAL); if (hnd >= 0) { chanHandle = hnd; Dictionary <string, int> dicBitRates = new Dictionary <string, int>() { { "125 kb/s", Canlib.canBITRATE_125K }, { "250 kb/s", Canlib.canBITRATE_250K }, { "500 kb/s", Canlib.canBITRATE_500K }, { "1 Mb/s", Canlib.BAUD_1M } }; status = Canlib.canSetBusParams(chanHandle, dicBitRates[bitrate], 0, 0, 0, 0, 0); status = Canlib.canBusOn(chanHandle); if (status == Canlib.canStatus.canOK) { channelOn = true; } } }
} // End KvaserCanRateReturn // *************************************** // DetectCanInterfaces // Pulls all of the available adapters for the CAN bus // *************************************** public static void DetectCanInterfaces() { // Detect Process for Kvaser CAN devices try { int nrOfChannels; object o = new object(); Canlib.canInitializeLibrary(); //List available channels Canlib.canGetNumberOfChannels(out nrOfChannels); for (int i = 0; i < nrOfChannels; i++) { Canlib.canGetChannelData(i, Canlib.canCHANNELDATA_CHANNEL_NAME, out o); // Display of data in ListView as follows // Network; Type; Mfg; Channel; Status; canHandle BusInterface.AddInterface("CAN;" + o.ToString() + ";" + "Kvaser" + ";" + i, -1); ErrorLog.NewLogEntry("CAN", "Detect CAN: " + o.ToString()); } } catch (Exception) { ErrorLog.NewLogEntry("Adapter", "Kvaser library not found"); } } // End DetectCanInterfaces
public static new string[] GetAdapterNames() { Canlib.canInitializeLibrary(); int nrOfChannels; Canlib.canGetNumberOfChannels(out nrOfChannels); List <string> names = new List <string>(); object channelName = new object(); object channelCapabilities = new object(); for (int i = 0; i < nrOfChannels; i++) { Canlib.canGetChannelData(i, Canlib.canCHANNELDATA_CHANNEL_NAME, out channelName); Canlib.canGetChannelData(i, Canlib.canCHANNELDATA_CHANNEL_CAP, out channelCapabilities); uint capability = (uint)channelCapabilities; if ((capability & Canlib.canCHANNEL_CAP_VIRTUAL) != Canlib.canCHANNEL_CAP_VIRTUAL) { names.Add(channelName.ToString()); logger.Debug(String.Format("Found channel {0}", channelName)); } else { logger.Debug(String.Format("Skipped channel {0}", channelName)); } } return(names.ToArray()); }
//Initializes Canlib void initButton_Click(object sender, RoutedEventArgs e) { Canlib.canInitializeLibrary(); statusText.Text = "CAN channel initialized"; initButton.IsEnabled = false; openChannelButton.IsEnabled = true; //channelBox.IsEnabled = true; channelComboBox.IsEnabled = true; }
/// <summary> /// The open method tries to connect to both busses to see if one of them is connected and /// active. The first strategy is to listen for any CAN message. If this fails there is a /// check to see if the application is started after an interrupted flash session. This is /// done by sending a message to set address and length (only for P-bus). /// </summary> /// <returns>OpenResult.OK is returned on success. Otherwise OpenResult.OpenError is /// returned.</returns> override public OpenResult open() { Canlib.canInitializeLibrary(); //Check if bus is connected if (isOpen()) { close(); } Thread.Sleep(200); m_readThread = new Thread(readMessages) { Name = "KvaserCANDevice.m_readThread" }; m_endThread = false; // Take first adapter... string[] adapters = GetAdapterNames(); if (adapters.Length == 0) { return(OpenResult.OpenError); } SetSelectedAdapter(adapters[0]); //Check if P bus is connected logger.Debug("handle1 = canlibCLSNET.Canlib.canOpenChannel()"); handleWrite = Canlib.canOpenChannel(ChannelNumber, 0); logger.Debug("canlibCLSNET.Canlib.canSetBusParams(handleWrite)"); Canlib.canStatus statusSetParamWrite = Canlib.canSetBusParamsC200(handleWrite, 0x40, 0x37); logger.Debug("canlibCLSNET.Canlib.canBusOn(handleWrite)"); Canlib.canStatus statusOnWrite = Canlib.canBusOn(handleWrite); Canlib.canIoCtl(handleWrite, Canlib.canIOCTL_SET_LOCAL_TXECHO, 0); // logger.Debug("handle2 = canlibCLSNET.Canlib.canOpenChannel()"); handleRead = Canlib.canOpenChannel(ChannelNumber, 0); logger.Debug("canlibCLSNET.Canlib.canSetBusParams(handleRead)"); Canlib.canStatus statusSetParamRead = Canlib.canSetBusParamsC200(handleRead, 0x40, 0x37); logger.Debug("canlibCLSNET.Canlib.canBusOn(handleRead)"); Canlib.canStatus statusOnRead = Canlib.canBusOn(handleRead); Canlib.canIoCtl(handleRead, Canlib.canIOCTL_SET_LOCAL_TXECHO, 0); if (handleWrite < 0 || handleRead < 0) { return(OpenResult.OpenError); } logger.Debug("P bus connected"); if (m_readThread.ThreadState == ThreadState.Unstarted) { m_readThread.Start(); } return(OpenResult.OK); }
public bool CAN_LIB_Init() { bool _chk = false; try { Canlib.canInitializeLibrary(); _chk = true; } catch (Exception e1) { string _errmsg = e1.Message; _chk = false; return(_chk); } return(_chk); }
// Pulls all of the available adapters for the CAN bus public static void DetectLinInterfaces(BusInterface busInterface) { int nrOfChannels; Canlib.canInitializeLibrary(); //List available channels Canlib.canGetNumberOfChannels(out nrOfChannels); object o = new object(); for (int i = 0; i < nrOfChannels; i++) { Canlib.canGetChannelData(i, Canlib.canCHANNELDATA_CHANNEL_NAME, out o); // Display of data in ListView as follows // Network; Type; Mfg; Channel; Status BusInterface.AddInterface("CAN" + ";" + o.ToString() + ";" + "Kvasier" + ";" + i + ";" + "Pending", -1); } }
public static new string[] GetAdapterNames() { Canlib.canInitializeLibrary(); //List available channels int nrOfChannels; Canlib.canGetNumberOfChannels(out nrOfChannels); string[] names = new string[nrOfChannels]; object o = new object(); for (int i = 0; i < nrOfChannels; i++) { Canlib.canGetChannelData(i, Canlib.canCHANNELDATA_CHANNEL_NAME, out o); names[i] = o.ToString(); logger.Debug(string.Format("canlibCLSNET.Canlib.canGetChannelData({0}, canlibCLSNET.Canlib.canCHANNELDATA_CHANNEL_NAME, {1})", i, o)); } return(names); }
/// <summary> /// 获取CAN通道 /// </summary> /// <returns></returns> public string[] GetChannel() { int channel_num = 0x00; Canlib.canInitializeLibrary(); if (Canlib.canStatus.canOK == Canlib.canGetNumberOfChannels(out channel_num)) { channel = new string[channel_num]; for (int i = 0; i < channel_num; i++) { object canChannelType = new Object(); object canChannelName = new Object(); Canlib.canGetChannelData(i, Canlib.canCHANNELDATA_TRANS_TYPE, out canChannelType); /* get channel type */ Canlib.canGetChannelData(i, Canlib.canCHANNELDATA_CHANNEL_NAME, out canChannelName); /* get channel name */ channel[i] = Convert.ToString(canChannelName); } } return(channel); }
public KvaserCAN(MainWindow wnd) //public constructor { this.wnd = wnd; Canlib.canInitializeLibrary(); hcan = Canlib.canOpenChannel(channel, Canlib.canOPEN_REQUIRE_INIT_ACCESS); if (hcan < 0) { string error; Canlib.canGetErrorText((Canlib.canStatus)hcan, out error); send2Terminal(error); } else { Canlib.canSetBusParams(hcan, bitr, 0, 0, 0, 0, 0); //parameters set by dafault based on bitr Canlib.canBusOn(hcan); send2Terminal("Can liin avatud"); //DumpMessageLoop(hcan); } }
public override void SetSelectedAdapter(string adapter) { Canlib.canInitializeLibrary(); int nrOfChannels; Canlib.canGetNumberOfChannels(out nrOfChannels); object o = new object(); for (int i = 0; i < nrOfChannels; i++) { Canlib.canGetChannelData(i, Canlib.canCHANNELDATA_CHANNEL_NAME, out o); if (adapter.Equals(o.ToString())) { ChannelNumber = i; logger.Debug(string.Format("canlibCLSNET.Canlib.canGetChannelData({0}, canlibCLSNET.Canlib.canCHANNELDATA_CHANNEL_NAME, {1})", i, o)); return; } } throw new Exception(String.Format("Channel {0} cannot be selected", adapter)); }
public void SetSelectedAdapter(string adapter) { Canlib.canInitializeLibrary(); int nrOfChannels; Canlib.canGetNumberOfChannels(out nrOfChannels); object o = new object(); for (int i = 0; i < nrOfChannels; i++) { Canlib.canGetChannelData(i, Canlib.canCHANNELDATA_CHANNEL_NAME, out o); if (adapter.Equals(o.ToString())) { ChannelNumber = i; logger.Debug(string.Format("canlibCLSNET.Canlib.canGetChannelData({0}, canlibCLSNET.Canlib.canCHANNELDATA_CHANNEL_NAME, {1})", i, o)); return; } } // Default to channel 0 ChannelNumber = 0; }
//Initializes Canlib private void initButtonClick(object sender, RoutedEventArgs e) { Canlib.canInitializeLibrary(); statusText.Text = "Canlib initialized"; }
private static void GenericLinInitilize() { //Intilize the Kvasier Can Library Canlib.canInitializeLibrary(); }
private void canThreadFunct() { int canHandle; Canlib.canStatus status; int channel_number = 0; int id; byte[] msg = new byte[8]; int dlc; int flag; long time; long timeout; int val0 = 0; int val1 = 0; int val2 = 0; int val3 = 0; long count0 = 1; long count1 = 2; long count2 = 3; long count3 = 4; Canlib.canInitializeLibrary(); canHandle = Canlib.canOpenChannel(channel_number, Canlib.canOPEN_NO_INIT_ACCESS); CheckStatus((Canlib.canStatus)canHandle, "canOpenChannel"); // Next, take the channel on bus using the canBusOn method. This // needs to be done before we can send a message. status = Canlib.canBusOn(canHandle); CheckStatus(status, "canBusOn"); timeout = 1000; while (!exit_request) { status = Canlib.canReadWait(canHandle, out id, msg, out dlc, out flag, out time, timeout); CheckStatus(status, "canReadWait"); if (id == 0x700) { val0 = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(msg, 0)); count0 = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(msg, 4)); } if (id == 0x701) { val1 = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(msg, 0)); count1 = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(msg, 4)); } if (id == 0x702) { val2 = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(msg, 0)); count2 = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(msg, 4)); } if (id == 0x703) { val3 = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(msg, 0)); count3 = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(msg, 4)); } if (count0 == count1 && count0 == count2 && count0 == count3) { realtimeChart.DataSample genValue = new realtimeChart.DataSample(); genValue.value[0] = val0; genValue.value[1] = val1; genValue.value[2] = val2; genValue.value[3] = val3; mainChart.AddValue(genValue); } } status = Canlib.canBusOff(canHandle); CheckStatus(status, "canBusOff"); }
public void _OpenAllConnections() { if (ActiveCanDriver == Consts.INTERFACE_RS232) { if (PortConnection.OpenPort()) { dic_CanChanels.Clear(); foreach (var entry in Globals.Vm_scis) { dic_CanChanels[entry.VM_UC_Main.NodeId] = 0; } Task.Factory.StartNew(() => { int i = 0; do { Globals.Vm_scis[0].HighFrequencyOn = true; FrequencyManager.SendCCComand(vm_sci: Globals.Vm_scis[0]); Thread.Sleep(5); } while (!graphStarted && i < 500);//max 25 seconds }); } } else if (ActiveCanDriver == Consts.CAN_DRIVER_KVASER) { lock (LockCanIdsDic) { hasChangeInNodesList = true; Canlib.canInitializeLibrary(); foreach (var value in dic_CanChanels.Where(x => x.Value >= 0).Select(x => x.Value)) { Canlib.canBusOff(value); Canlib.canClose(value); } //lastOpenedChanel = 0; dic_CanChanels.Clear(); foreach (var entry in Globals.Vm_scis.Where(entry => entry.VM_UC_Main != null)) { dic_CanChanels[entry.VM_UC_Main.NodeId] = -1; } foreach (var key in dic_CanChanels.Select(x => x.Key).ToList()) { int openedChanel = Canlib.canOpenChannel(lastOpenedChanel + 1, key); if (openedChanel >= 0) { dic_CanChanels[key] = openedChanel; } } foreach (var entry in dic_CanChanels.Where(x => x.Value >= 0)) { Canlib.canSetBusParams( handle: entry.Value, freq: CANDesiredBitRate, tseg2: 0, tseg1: 0, sjw: 0, noSamp: 0, syncmode: 0 ); Canlib.canBusOn(entry.Value); //if (!setCanCardName() || !getCanBitRate()) { // CANStatus = Consts.BOOL_FAILED; // CANHandle = -1; //} //initialize the node Canlib.canWrite( handle: entry.Value, id: 0, msg: new byte[] { 1, (byte)entry.Key }, dlc: 2, //size of msg flag: 2 //we have defined this as const ); } } //get multiply value WriteToAll("AD", 0, true, true); //get ISR WriteToAll("AE", 0, true, true); graphStarted = false; //start Graph //todo fix for each nodeId Task.Factory.StartNew(() => { int i = 0; do { if (Globals.Vm_scis.Count > 0) { Globals.Vm_scis[0].HighFrequencyOn = true; FrequencyManager.SendCCComand(1, vm_sci: Globals.Vm_scis[0]); // start graph plot with 6k frequency. Thread.Sleep(5); } else { Debugger.Break(); } } while (!graphStarted && i < 500 && Globals.Vm_scis.Count > 0);//max 25 seconds }); //_can_status = RoundBoolLed.DISABLED; } }
//initialise the usb interface library based on which interface was selected public static void initialiseCAN() { for (int i = 0; i < CAN_Channel.numOfChan; i++) { switch (CAN_Channel._INTERFACEs[i]) { case CAN_Channel.CAN_INTERFACE.KVASER: if (!KvaserInit) { Canlib.canInitializeLibrary(); } if (CanInit) { Close(); } numOfKvaser++; canHandle[i] = Canlib.canOpenChannel(numOfKvaser - 1, Canlib.canOPEN_ACCEPT_VIRTUAL); KvaserInit = true; //check whether handle was gotten successfully ErrorControl(handle: canHandle[i], location: "canOpenChannel: initialise()"); switch (CAN_Channel._BAUDRATEs[i]) { case CAN_Channel.CAN_BAUDRATE._250K: status = Canlib.canSetBusParams(canHandle[i], Canlib.canBITRATE_250K, 0, 0, 0, 0, 0); break; case CAN_Channel.CAN_BAUDRATE._500K: status = Canlib.canSetBusParams(canHandle[i], Canlib.canBITRATE_500K, 0, 0, 0, 0, 0); break; case CAN_Channel.CAN_BAUDRATE._1M: status = Canlib.canSetBusParams(canHandle[i], Canlib.canBITRATE_1M, 0, 0, 0, 0, 0); break; } ErrorControl(status: status, location: "canSetBusParams: initialise()"); Canlib.canSetBusOutputControl(canHandle[i], Canlib.canDRIVER_NORMAL); //turn the bus on with a handle to the open channel to write data Canlib.canBusOn(canHandle[i]); break; case CAN_Channel.CAN_INTERFACE.PEAK: if (CanInit) { Close(); } numOfPeak++; if (numOfPeak == 1) { canHandle[i] = PCANBasic.PCAN_USBBUS1; } if (numOfPeak == 2) { canHandle[i] = PCANBasic.PCAN_USBBUS2; } switch (CAN_Channel._BAUDRATEs[i]) { case CAN_Channel.CAN_BAUDRATE._250K: pCANBaudrate[numOfPeak - 1] = TPCANBaudrate.PCAN_BAUD_250K; break; case CAN_Channel.CAN_BAUDRATE._500K: pCANBaudrate[numOfPeak - 1] = TPCANBaudrate.PCAN_BAUD_500K; break; case CAN_Channel.CAN_BAUDRATE._1M: pCANBaudrate[numOfPeak - 1] = TPCANBaudrate.PCAN_BAUD_1M; break; } if (PCANBasic.Initialize((ushort)canHandle[i], pCANBaudrate[numOfPeak - 1]) == TPCANStatus.PCAN_ERROR_INITIALIZE) { ErrorControl(-1, location: "PCANBasic.initialize: initialise()"); return; } break; } } CanInit = true; numOfPeak = 0; numOfKvaser = 0; }
//Initializes Canlib public void init() { Canlib.canInitializeLibrary(); }
/// <summary> /// The open method tries to connect to both busses to see if one of them is connected and /// active. The first strategy is to listen for any CAN message. If this fails there is a /// check to see if the application is started after an interrupted flash session. This is /// done by sending a message to set address and length (only for P-bus). /// </summary> /// <returns>OpenResult.OK is returned on success. Otherwise OpenResult.OpenError is /// returned.</returns> override public OpenResult open() { Canlib.canInitializeLibrary(); if (isOpen()) { close(); } // Default to "Allow all" uint code = 0xFFF; uint mask = 0x000; // ID 0x000 will thrash the filter calculation so bypass the whole filter if it's found foreach (var id in AcceptOnlyMessageIds) { if (id == 0) { m_filterBypass = true; } } if (m_filterBypass == false) { foreach (var id in AcceptOnlyMessageIds) { code &= id; mask |= id; } mask = (~mask & 0x7FF) | code; logger.Debug("code: " + code.ToString("X8")); logger.Debug("mask: " + mask.ToString("X8")); } VerifyFilterIntegrity(code, mask); Thread.Sleep(200); m_readThread = new Thread(readMessages) { Name = "KvaserCANDevice.m_readThread" }; if (TrionicECU == ECU.TRIONIC5) { OpenChannelWithParamsC200(out handleWrite, CAN_BAUD_BTR_615K_btr0, CAN_BAUD_BTR_615K_btr1); OpenChannelWithParamsC200(out handleRead, CAN_BAUD_BTR_615K_btr0, CAN_BAUD_BTR_615K_btr1); Canlib.canSetAcceptanceFilter(handleRead, (int)code, (int)mask, 0); if (handleWrite < 0 || handleRead < 0) { return(OpenResult.OpenError); } logger.Debug("P bus connected"); m_endThread = false; if (m_readThread.ThreadState == ThreadState.Unstarted) { m_readThread.Start(); } return(OpenResult.OK); } if (!UseOnlyPBus) { if (TrionicECU == ECU.TRIONIC7) { OpenChannelWithParamsC200(out handleWrite, CAN_BAUD_BTR_47K_btr0, CAN_BAUD_BTR_47K_btr1); OpenChannelWithParamsC200(out handleRead, CAN_BAUD_BTR_47K_btr0, CAN_BAUD_BTR_47K_btr1); Canlib.canSetAcceptanceFilter(handleRead, (int)code, (int)mask, 0); } else if (TrionicECU == ECU.TRIONIC8) { OpenChannelWithParamsC200(out handleWrite, CAN_BAUD_BTR_33K_btr0, CAN_BAUD_BTR_33K_btr1); OpenChannelWithParamsC200(out handleRead, CAN_BAUD_BTR_33K_btr0, CAN_BAUD_BTR_33K_btr1); Canlib.canSetAcceptanceFilter(handleRead, (int)code, (int)mask, 0); } if (handleWrite < 0 || handleRead < 0) { return(OpenResult.OpenError); } logger.Debug("I bus connected"); m_endThread = false; if (m_readThread.ThreadState == ThreadState.Unstarted) { m_readThread.Start(); } return(OpenResult.OK); } OpenChannel(out handleWrite, Canlib.canBITRATE_500K); OpenChannel(out handleRead, Canlib.canBITRATE_500K); Canlib.canSetAcceptanceFilter(handleRead, (int)code, (int)mask, 0); if (handleWrite < 0 || handleRead < 0) { return(OpenResult.OpenError); } logger.Debug("P bus connected"); m_endThread = false; if (m_readThread.ThreadState == ThreadState.Unstarted) { m_readThread.Start(); } return(OpenResult.OK); }
/// <summary> /// The open method tries to connect to both busses to see if one of them is connected and /// active. The first strategy is to listen for any CAN message. If this fails there is a /// check to see if the application is started after an interrupted flash session. This is /// done by sending a message to set address and length (only for P-bus). /// </summary> /// <returns>OpenResult.OK is returned on success. Otherwise OpenResult.OpenError is /// returned.</returns> override public OpenResult open() { Canlib.canInitializeLibrary(); //Check if bus is connected if (isOpen()) { close(); } Thread.Sleep(200); m_readThread = new Thread(readMessages) { Name = "KvaserCANDevice.m_readThread" }; if (!UseOnlyPBus) { if (TrionicECU == ECU.TRIONIC7) { logger.Debug("handle1 = canlibCLSNET.Canlib.canOpenChannel()"); handleWrite = Canlib.canOpenChannel(ChannelNumber, Canlib.canOPEN_ACCEPT_VIRTUAL); logger.Debug("canlibCLSNET.Canlib.canSetBusParams(handleWrite)"); Canlib.canStatus statusSetParam1 = Canlib.canSetBusParamsC200(handleWrite, CAN_BAUD_BTR_47K_btr0, CAN_BAUD_BTR_47K_btr1); logger.Debug("canlibCLSNET.Canlib.canBusOn(handleWrite)"); Canlib.canStatus statusOn1 = Canlib.canBusOn(handleWrite); Canlib.canIoCtl(handleWrite, Canlib.canIOCTL_SET_LOCAL_TXECHO, 0); // logger.Debug("handle2 = canlibCLSNET.Canlib.canOpenChannel()"); handleRead = Canlib.canOpenChannel(ChannelNumber, Canlib.canOPEN_ACCEPT_VIRTUAL); logger.Debug("canlibCLSNET.Canlib.canSetBusParams(handleRead)"); Canlib.canStatus statusSetParam2 = Canlib.canSetBusParamsC200(handleWrite, CAN_BAUD_BTR_47K_btr0, CAN_BAUD_BTR_47K_btr1); logger.Debug("canlibCLSNET.Canlib.canBusOn(handleRead)"); Canlib.canStatus statusOn2 = Canlib.canBusOn(handleRead); Canlib.canIoCtl(handleRead, Canlib.canIOCTL_SET_LOCAL_TXECHO, 0); } else if (TrionicECU == ECU.TRIONIC8) { logger.Debug("handle1 = canlibCLSNET.Canlib.canOpenChannel()"); handleWrite = Canlib.canOpenChannel(ChannelNumber, Canlib.canOPEN_ACCEPT_VIRTUAL); logger.Debug("canlibCLSNET.Canlib.canSetBusParams(handleWrite)"); Canlib.canStatus statusSetParam1 = Canlib.canSetBusParamsC200(handleWrite, CAN_BAUD_BTR_33K_btr0, CAN_BAUD_BTR_33K_btr1); logger.Debug("canlibCLSNET.Canlib.canBusOn(handleWrite)"); Canlib.canStatus statusOn1 = Canlib.canBusOn(handleWrite); Canlib.canIoCtl(handleWrite, Canlib.canIOCTL_SET_LOCAL_TXECHO, 0); // logger.Debug("handle2 = canlibCLSNET.Canlib.canOpenChannel()"); handleRead = Canlib.canOpenChannel(ChannelNumber, Canlib.canOPEN_ACCEPT_VIRTUAL); logger.Debug("canlibCLSNET.Canlib.canSetBusParams(handleRead)"); Canlib.canStatus statusSetParam2 = Canlib.canSetBusParamsC200(handleWrite, CAN_BAUD_BTR_33K_btr0, CAN_BAUD_BTR_33K_btr1); logger.Debug("canlibCLSNET.Canlib.canBusOn(handleRead)"); Canlib.canStatus statusOn2 = Canlib.canBusOn(handleRead); Canlib.canIoCtl(handleRead, Canlib.canIOCTL_SET_LOCAL_TXECHO, 0); } if (handleWrite < 0 || handleRead < 0) { return(OpenResult.OpenError); } logger.Debug("I bus connected"); if (m_readThread.ThreadState == ThreadState.Unstarted) { m_readThread.Start(); } return(OpenResult.OK); } m_endThread = false; //Check if P bus is connected logger.Debug("handle1 = canlibCLSNET.Canlib.canOpenChannel()"); handleWrite = Canlib.canOpenChannel(ChannelNumber, Canlib.canOPEN_ACCEPT_VIRTUAL); logger.Debug("canlibCLSNET.Canlib.canSetBusParams(handleWrite)"); Canlib.canStatus statusSetParamWrite = Canlib.canSetBusParams(handleWrite, Canlib.canBITRATE_500K, 0, 0, 0, 0, 0); logger.Debug("canlibCLSNET.Canlib.canBusOn(handleWrite)"); Canlib.canStatus statusOnWrite = Canlib.canBusOn(handleWrite); Canlib.canIoCtl(handleWrite, Canlib.canIOCTL_SET_LOCAL_TXECHO, 0); // logger.Debug("handle2 = canlibCLSNET.Canlib.canOpenChannel()"); handleRead = Canlib.canOpenChannel(ChannelNumber, Canlib.canOPEN_ACCEPT_VIRTUAL); logger.Debug("canlibCLSNET.Canlib.canSetBusParams(handleRead)"); Canlib.canStatus statusSetParamRead = Canlib.canSetBusParams(handleRead, Canlib.canBITRATE_500K, 0, 0, 0, 0, 0); logger.Debug("canlibCLSNET.Canlib.canBusOn(handleRead)"); Canlib.canStatus statusOnRead = Canlib.canBusOn(handleRead); Canlib.canIoCtl(handleRead, Canlib.canIOCTL_SET_LOCAL_TXECHO, 0); if (handleWrite < 0 || handleRead < 0) { return(OpenResult.OpenError); } logger.Debug("P bus connected"); if (m_readThread.ThreadState == ThreadState.Unstarted) { m_readThread.Start(); } return(OpenResult.OK); }