예제 #1
0
 private void CANBUStransmitSetup()
 {
     setCANBUSparameters = false;
     if (button125.Checked)
     {
         CANBUSspeed = 125;                           // setup canbus speed
     }
     else
     if (button250.Checked)
     {
         CANBUSspeed = 250;
     }
     else
     {
         CANBUSspeed = 500;
     }
     if (RFX0checkBox.Checked)
     {
         Rx0extended = 1;
     }
     else
     {
         Rx0extended = 0;
     }
     if (RFX1checkBox.Checked)
     {
         Rx1extended = 1;
     }
     else
     {
         Rx1extended = 0;
     }
     //Console.WriteLine("CANBUStransmitSetup filter {0:X} mask {1:X} speed {2}", canbusMask, canbusFilter, CANBUSspeed);
     Arduino_Canbus_interface.CANBUSsetup(serialPort1, Rx0extended, Rx0mask, Rx0filter, Rx1extended, Rx1mask, Rx1filter, CANBUSspeed);
 }
예제 #2
0
        // transmit an 8 byte canbus message from TextBox canbusMessageTextBox canbus ID is in transmitIDtextBox
        private void CANBUStransmitMessageNow()
        {
            transmitCANBUSmessage = false;
            Console.WriteLine("CANBUStransmitMessageNow()");
            // right justify hex digits filling with 0's from right
            StringBuilder s = new StringBuilder("0000000000000000", 25);

            for (int ii = 0; ii <= canbusMessageTextBox.Text.Length - 1; ii++)
            {
                s[ii] = canbusMessageTextBox.Text[ii];               // copy hex digits to s
            }
            String save = s.ToString();

            canbusMessage = Convert.ToUInt64(save, 16);              // convert s to 64 bit unsigned number
            int[] message = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            int   i       = 7;

            while (i >= 0)      // convert 64bit number into 8 byte values
            {
                UInt64 x = 0xFF;
                try
                { message[i] = Convert.ToInt16(canbusMessage & x); }  // get rightmost byte
                catch (Exception) { }
                canbusMessage = canbusMessage >> 8;                     // shift right one byte
                i             = i - 1;                                  // get next byte
            }
            read29bitHexNumber(canbusIDtextBox, ref canbusTranmitID);   // get the can ID
            if (RTRcheckBox.Checked)
            {
                RTR = 1;
            }
            else
            {
                RTR = 0;
            }
            if (extended29bitIDcheckBox.Checked)
            {
                extendedID = 1;
            }
            else
            {
                extendedID = 0;
            }
            Arduino_Canbus_interface.CANBUStransmit(serialPort1, extendedID, canbusTranmitID, RTR, message);            // transmit message
        }