Ejemplo n.º 1
0
        private void button3_Click(object sender, EventArgs e)
        {
            C4UFX.CANMessage   mess = new C4UFX.CANMessage();
            CANControls.FndTnd nd   = new CANControls.FndTnd();

            nd.Fn = 0x7F;   // highest possible 7 bit value as this node. Doesn't really matter from who
            nd.Fd = 1;      // also doesn't really matter from which device
            nd.Tn = 2;      // To Node 2
            nd.Td = 1;      // To Device 1 (1st output)

            mess.ID      = CANControls.ConvNDID(nd);
            mess.Data[0] = 0x30;   // toggle on/off
            mess.DLC     = 1;      // send one byte
            CANControls.SendCANMessage(mess);
        }
Ejemplo n.º 2
0
        // ####################################################################
        // called from the timer service on the CANForm every 10ms
        private void CANService()
        {
            CheckForIncomingCANMessages();

            if (--CANStatus <= 0)
            {
                CANCheckStatus(false);
                CANStatus = 100;        // every second
            }
            if (CANSendQueue.Count > 0) // send any messages in the queue
            {
                int error             = 0;
                C4UFX.CANMessage mess = CANSendQueue.Dequeue();
                C4UFX.SendCANMess(0, 0, mess, out error);
                DisplayCANData(mess);
            }
        }
Ejemplo n.º 3
0
        public void IncomingCANMessages(C4UFX.CANMessage mess)
        {
            CANControls.FndTnd nd;
            string             data = "";

            nd = CANControls.ConvIDND(mess.ID);  // convert 29 bit ID to seperates


            for (int i = 0; i < mess.DLC; i++)
            {
                data += mess.Data[i].ToString("x") + " ";
            }

            listBox1.Items.Add(nd.Fn.ToString() + "," +
                               nd.Fd.ToString() + "," +
                               nd.Tn.ToString() + "," +
                               nd.Td.ToString() + ":" + data);
        }
Ejemplo n.º 4
0
        // ####################################################################
        private void CheckForIncomingCANMessages()
        {
            int Result = C4UFX.Resp_Ack;

            C4UFX.CANMessage CANMess = new C4UFX.CANMessage();

            while (Result == C4UFX.Resp_Ack)
            {
                Result = C4UFX.GetCANMess(0, 0, ref CANMess);

                if (Result == C4UFX.Resp_Ack)
                {
                    DisplayCANData(CANMess);
                    if (inCANMessage != null)
                    {
                        inCANMessage(CANMess);   // call our delegate
                    }
                }
                MIBText.Text = C4UFX.GetNumCANMess(0, 0).ToString();
            }
        }
Ejemplo n.º 5
0
        private void button2_Click(object sender, EventArgs e)
        {
            // this test assumes the light switch is node 1 and will program switch 3
            // (middle left button)
            C4UFX.CANMessage   mess = new C4UFX.CANMessage();
            CANControls.FndTnd nd   = new CANControls.FndTnd();

            nd.Fn = 0x7F;   // highest possible 7 bit value as this node. Doesn't really matter from who
            nd.Fd = 0;      // device
            nd.Tn = 1;      // To Node 1
            nd.Td = 0;      // To Device 0 (node itself)

            mess.ID      = CANControls.ConvNDID(nd);
            mess.Data[0] = 0x1A;              // unlock code from protocol overview doc
            mess.Data[1] = 0x01;              // unlock code from protocol overview doc
            mess.Data[2] = 0xFE;              // unlock code from protocol overview doc
            mess.Data[3] = 0x00;              // unlock code from protocol overview doc

            mess.DLC = 4;                     // send 4 bytes
            CANControls.SendCANMessage(mess); // unlocks node for programming



            // ######## set new address for switch itself
            nd.Fn = 0x7F;   // highest possible 7 bit value as this node. Doesn't really matter from who
            nd.Fd = 0;      // device
            nd.Tn = 1;      // To Node 1
            nd.Td = 3;      // To Device 3 (switch 3)

            mess.ID      = CANControls.ConvNDID(nd);
            mess.Data[0] = 0x21;   // CmdSysPPar command - see "Smart switch protocol details.doc"
            mess.Data[1] = 0x01;   // mode = enabled
            mess.Data[2] = 0x05;   // double click time = 5*50ms
            mess.Data[3] = 0x06;   // hold time = 6*50ms

            mess.DLC = 4;          // send 4 bytes
            //CANControls.SendCANMessage(mess);  // unlocks node for programming

            //// ######## we can reuse the same address for next commands
            //mess.Data[0] = 0x22;   // CmdSysPPar2 command - see "Smart switch protocol details.doc"
            //mess.Data[1] = 0x01;   // sub command 1
            //mess.Data[2] = 0x01;   // first click event goes to node 1
            //mess.Data[3] = 0x01;   // first click event goes to device 1
            //mess.Data[4] = 0x01;   // send one additional command byte
            //mess.Data[5] = 0x30;   // command 30 is on/off toggle (from "device description for dimming output")
            //mess.DLC = 6;           // send 6 bytes
            //CANControls.SendCANMessage(mess);  // unlocks node for programming

            //// ######## now repeat for sub commands 2-7
            //mess.Data[0] = 0x22;   // CmdSysPPar2 command - see "Smart switch protocol details.doc"
            //mess.Data[1] = 0x02;   // sub command 2
            //mess.Data[2] = 0x01;   // second click event goes to node 1
            //mess.Data[3] = 0x01;   // second click event goes to device 1
            //mess.Data[4] = 0x01;   // send one additional command byte
            //mess.Data[5] = 0x30;   // command 30 is on/off toggle (from "device description for dimming output")
            //mess.DLC = 6;           // send 6 bytes
            //CANControls.SendCANMessage(mess);  // unlocks node for programming

            //// ######## sub 3
            //mess.Data[0] = 0x22;   // CmdSysPPar2 command - see "Smart switch protocol details.doc"
            //mess.Data[1] = 0x03;   // sub command 3
            //mess.Data[2] = 0x01;   // double click event goes to node 1
            //mess.Data[3] = 0x01;   // double click event goes to device 1
            //mess.Data[4] = 0x01;   // send one additional command byte
            //mess.Data[5] = 0x31;   // command 31 is full on (from "device description for dimming output")
            //mess.DLC = 6;           // send 6 bytes
            //CANControls.SendCANMessage(mess);  // unlocks node for programming

            //// ######## sub 4
            //mess.Data[0] = 0x22;   // CmdSysPPar2 command - see "Smart switch protocol details.doc"
            //mess.Data[1] = 0x04;   // sub command 4
            //mess.Data[2] = 0x01;   // 1st hold event goes to node 1
            //mess.Data[3] = 0x01;   // 1st hold click event goes to device 1
            //mess.Data[4] = 0x01;   // send one additional command byte
            //mess.Data[5] = 0x32;   // command 32 is fade continous (from "device description for dimming output")
            //mess.DLC = 6;           // send 6 bytes
            //CANControls.SendCANMessage(mess);  // unlocks node for programming

            //// ######## sub 5
            //mess.Data[0] = 0x22;   // CmdSysPPar2 command - see "Smart switch protocol details.doc"
            //mess.Data[1] = 0x05;   // sub command 5
            //mess.Data[2] = 0x01;   // 2nd hold event goes to node 1
            //mess.Data[3] = 0x01;   // 2nd hold click event goes to device 1
            //mess.Data[4] = 0x01;   // send one additional command byte
            //mess.Data[5] = 0x32;   // command 32 is fade continous (from "device description for dimming output")
            //mess.DLC = 6;           // send 6 bytes
            //CANControls.SendCANMessage(mess);  // unlocks node for programming

            //// ######## sub 6
            //mess.Data[0] = 0x22;   // CmdSysPPar2 command - see "Smart switch protocol details.doc"
            //mess.Data[1] = 0x06;   // sub command 6 -
            //mess.Data[2] = 0x01;   // release event goes to node 1
            //mess.Data[3] = 0x01;   // release click event goes to device 1
            //mess.Data[4] = 0x01;   // send one additional command byte
            //mess.Data[5] = 0x33;   // command 33 is release (from "device description for dimming output")
            //mess.DLC = 6;           // send 6 bytes
            //CANControls.SendCANMessage(mess);  // unlocks node for programming

            //// ######## sub 7
            //mess.Data[0] = 0x22;   // CmdSysPPar2 command - see "Smart switch protocol details.doc"
            //mess.Data[1] = 0x07;   // sub command 7 -
            //mess.Data[2] = 0xFF;   // 1st press event is not used and set to 255
            //mess.Data[3] = 0xFF;   // 1st press event is not used and set to 255
            //mess.Data[4] = 0x01;   // send one additional command byte
            //mess.Data[5] = 0x00;   // no command (from "device description for dimming output")
            //mess.DLC = 6;           // send 6 bytes
            //CANControls.SendCANMessage(mess);  // unlocks node for programming
        }
Ejemplo n.º 6
0
 // ####################################################################
 public static void SendCANMessage(C4UFX.CANMessage mess)
 {
     CANSendQueue.Enqueue(mess);
 }
Ejemplo n.º 7
0
        // ########################################################################################
        private void CANCheckStatus(bool ForceErr)
        {
            int Result;

            if ((CANInterfaceStatus != CANSTAT.OK) | (ForceErr == true))
            {
                C4UFX.CANMessage CANMess = new C4UFX.CANMessage();
                int Error;

                CANMess.ID  = 0;
                CANMess.DLC = 0;
                for (int c = 0; c < 8; c++)
                {
                    CANMess.Data[c] = 0;
                }
                CANMess.EID        = true;
                CANMess.RTR        = false;
                CANMess.MO         = 0;
                CANMess.SendOption = 7;

                Result = C4UFX.SendCANMess(0, 0, CANMess, out Error);

                if (Result != C4UFX.Resp_Ack)
                {
                    switch (Result)
                    {
                    case C4UFX.Resp_NAck:                       // message was transmitted but there was an error, so reset
                        CANInit();
                        SetCANInterfaceError(CANSTAT.SENDERR);
                        break;

                    case C4UFX.Resp_ErrImproperResponse:
                        SetCANInterfaceError(CANSTAT.NOINT);
                        break;

                    default:
                        SetCANInterfaceError(CANSTAT.ERROR);
                        break;
                    }
                }
                else
                {
                    SetCANInterfaceError(CANSTAT.OK);
                }
            }
            else                           // we're connected and working so display status register
            {
                byte[] DataBuf = new byte[10];

                Result = C4UFX.ReadReg(0, 0, 0x2D, 1, ref DataBuf);       // EFLG
                if (Result == C4UFX.Resp_Ack)
                {
                    if (DataBuf[0] == 0)
                    {
                        SetInterfaceStatusLabelVisible(0, true);
                    }
                    else
                    {
                        SetInterfaceStatusLabelVisible(0, false);
                    }

                    if ((DataBuf[0] & 0x80) > 0)
                    {
                        SetInterfaceStatusLabelVisible(7, true);
                        SetCANErrorTimerState(true);
                    }
                    else
                    {
                        SetInterfaceStatusLabelVisible(7, false);
                    }

                    if ((DataBuf[0] & 0x40) > 0)
                    {
                        SetInterfaceStatusLabelVisible(6, true);
                        SetCANErrorTimerState(true);
                    }
                    else
                    {
                        SetInterfaceStatusLabelVisible(6, false);
                    }

                    if ((DataBuf[0] & 0x20) > 0)
                    {
                        SetInterfaceStatusLabelVisible(5, true);
                    }
                    else
                    {
                        SetInterfaceStatusLabelVisible(5, false);
                    }

                    if ((DataBuf[0] & 0x10) > 0)
                    {
                        SetInterfaceStatusLabelVisible(4, true);
                    }
                    else
                    {
                        SetInterfaceStatusLabelVisible(4, false);
                    }

                    if ((DataBuf[0] & 0x08) > 0)
                    {
                        SetInterfaceStatusLabelVisible(3, true);
                    }
                    else
                    {
                        SetInterfaceStatusLabelVisible(3, false);
                    }

                    if ((DataBuf[0] & 0x04) > 0)
                    {
                        SetInterfaceStatusLabelVisible(2, true);
                    }
                    else
                    {
                        SetInterfaceStatusLabelVisible(2, false);
                    }

                    if ((DataBuf[0] & 0x02) > 0)
                    {
                        SetInterfaceStatusLabelVisible(1, true);
                    }
                    else
                    {
                        SetInterfaceStatusLabelVisible(1, false);
                    }
                }
                else
                {
                }
            }
        }