Example #1
0
File: Form1.cs Project: mc01104/CTR
        private void timerRead_Tick(object sender, EventArgs e)
        {
            byte[] msg = { 0, 0, 0, 0, 0, 0, 0, 0 };
            int dlc;
            int flag, id;
            long time;

            stat = canlibCLSNET.Canlib.canRead(handle2, out id, msg, out dlc, out flag, out time);
            while (stat == Canlib.canStatus.canOK)
            {

                if ((flag & canlibCLSNET.Canlib.canMSGERR_OVERRUN) != 0)
                {
                    radioButtonOverRun.Checked = true;
                }

                if ((flag & canlibCLSNET.Canlib.canMSG_ERROR_FRAME) != 0)
                {
                    textBoxIncommingFrames.Text = "ERROR FRAME\r\n" + textBoxIncommingFrames.Text;
                }
                else
                    textBoxIncommingFrames.Text = printMessage(id, msg, dlc, flag, time) + "\r\n" + textBoxIncommingFrames.Text;

                stat = canlibCLSNET.Canlib.canRead(handle2, out id, msg, out dlc, out flag, out time);

            }
        }
Example #2
0
File: Form1.cs Project: mc01104/CTR
        private void buttonTestAutoBuffers_Click(object sender, EventArgs e)
        {
            /* Set up an auto response buffer

            int autoBufIndex = (int)(canlibCLSNET.Canlib.canObjBufAllocate(handle1, canlibCLSNET.Canlib.canOBJBUF_TYPE_AUTO_RESPONSE));
            stat = canlibCLSNET.Canlib.canObjBufWrite(handle1, autoBufIndex, 123, msg, 6, 0);
            //stat = canlibCLSNET.Canlib.canObjBufSetPeriod(handle1, autoBufIndex, 1000);
            stat = canlibCLSNET.Canlib.canObjBufEnable(handle1, autoBufIndex);
             */

            if (!periodicActive)
            {
                textBoxResult.Text += "\r\nStarting periodic sending..";
                byte[] msg = { 1, 2, 3, 4, 5, 6 };
                int autoBufIndex1 = (int)(canlibCLSNET.Canlib.canObjBufAllocate(handle1, canlibCLSNET.Canlib.canOBJBUF_TYPE_PERIODIC_TX));
                if (autoBufIndex1 > 0)
                {
                    stat = canlibCLSNET.Canlib.canObjBufWrite(handle1, autoBufIndex1, 1, msg, 0, 0);
                    stat = canlibCLSNET.Canlib.canObjBufSetPeriod(handle1, autoBufIndex1, 1000);
                    stat = canlibCLSNET.Canlib.canObjBufEnable(handle1, autoBufIndex1);
                    periodicActive = !periodicActive;
                }
                else
                {
                    textBoxResult.Text += "\r\n" + (canlibCLSNET.Canlib.canStatus)(autoBufIndex1);
                }
            }
            else
            {
                textBoxResult.Text += "\r\nStopping periodic sending..";
                canlibCLSNET.Canlib.canObjBufDisable(handle1, 0);
                periodicActive = !periodicActive;
            }
        }
Example #3
0
File: Form1.cs Project: mc01104/CTR
        private void buttonWaitForPingPong_Click(object sender, EventArgs e)
        {
            byte[] msg = { 1, 2, 3, 4, 5, 6, 7, 8 };

            int dlc;
            int flag, id = 123;
            long time;
            stat = canlibCLSNET.Canlib.canReadWait(handle1, out id, msg, out dlc, out flag, out time,10000);
            stat = Canlib.canStatus.canOK;
            if (stat == Canlib.canStatus.canOK)
            {
                while (stat == Canlib.canStatus.canOK)
                {
                    Canlib.canWrite(handle1, 1, msg, 8, 0);
                    stat = Canlib.canReadWait(handle1, out id, msg, out dlc, out flag, out time, 250);
                }
                textBoxResult.Text += "\r\nTimed out waiting for message";
                stat = Canlib.canReadWait(handle1, out id, msg, out dlc, out flag, out time, 1000);
                if (stat == Canlib.canStatus.canOK)
                    textBoxResult.Text += "\r\nMissing message arrived.";
            }
            else
            {
                textBoxResult.Text += "\r\nTimed out waiting for starting message";
            }
        }
Example #4
0
File: Form1.cs Project: mc01104/CTR
 private void buttonSendWakeUp_Click(object sender, EventArgs e)
 {
     byte[] msg = { 0, 0, 0, 0, 0, 0, 0, 0 };
     stat = canlibCLSNET.Canlib.canWrite(handle1, 0x100, msg, 8, canlibCLSNET.Canlib.canMSG_WAKEUP);
     /*
     while (true)
     {
         stat = canlibCLSNET.Canlib.canWrite(handle1, 0x100, msg, 8, canlibCLSNET.Canlib.canMSG_WAKEUP);
         System.Threading.Thread.Sleep(50);
     }
     */
 }
Example #5
0
File: Form1.cs Project: mc01104/CTR
 private void buttonSendMessage_Click(object sender, EventArgs e)
 {
     byte[] msg = { 8, 7, 6, 5, 4, 3, 2, 1 };
     stat = canlibCLSNET.Canlib.canWrite(handle1, 0x100, msg, 8, 0);
 }
Example #6
0
File: Form1.cs Project: mc01104/CTR
 private void buttonSendRemoteFrame_Click(object sender, EventArgs e)
 {
     byte[] msg = { 0, 0, 0, 0, 0, 0, 0, 0 };
     stat = 0;
     stat = canlibCLSNET.Canlib.canWrite(handle1, 0x551, msg, 8, canlibCLSNET.Canlib.canMSG_RTR);
 }
Example #7
0
File: Form1.cs Project: mc01104/CTR
        private void buttonReadOne_Click(object sender, EventArgs e)
        {
            byte[] msg = { 1, 2, 3, 4, 5, 6, 7, 8 };

            int dlc;
            int flag, id = 123;
            long time;
            stat = canlibCLSNET.Canlib.canRead(handle2, out id, msg, out dlc, out flag, out time);
            if (stat == 0)
            {
                if ((flag & canlibCLSNET.Canlib.canMSGERR_OVERRUN) != 0)
                {
                    radioButtonOverRun.Checked = true;
                }

                if ((flag & canlibCLSNET.Canlib.canMSG_ERROR_FRAME) != 0)
                {
                    textBoxIncommingFrames.Text = "ERROR FRAME\r\n" + textBoxIncommingFrames.Text;
                }
                else
                    textBoxIncommingFrames.Text = printMessage(id, msg, dlc, flag, time) + "\r\n" + textBoxIncommingFrames.Text;

            }
            else
                textBoxResult.Text = stat.ToString();
        }
Example #8
0
File: Form1.cs Project: mc01104/CTR
        private void buttonReadSpecific_Click(object sender, EventArgs e)
        {
            byte[] msg = { 0, 0, 0, 0, 0, 0, 0, 0 };
            int dlc;
            int flag;
            long time;
            int id = int.Parse(textBoxSpecificID.Text);
            stat = canlibCLSNET.Canlib.canReadSpecific(handle2, id, msg, out dlc, out flag, out time);
            if (stat == 0)
            {
                if ((flag & canlibCLSNET.Canlib.canMSGERR_OVERRUN) != 0)
                {
                    radioButtonOverRun.Checked = true;
                }

                if ((flag & canlibCLSNET.Canlib.canMSG_ERROR_FRAME) != 0)
                {
                    textBoxIncommingFrames.Text = "ERROR FRAME\r\n" + textBoxIncommingFrames.Text;
                }
                else
                    textBoxIncommingFrames.Text = printMessage(id, msg, dlc, flag, time) + "\r\n" + textBoxIncommingFrames.Text;

            }
            else
                textBoxResult.Text = stat.ToString();
        }
Example #9
0
File: Form1.cs Project: mc01104/CTR
 private void buttonInterface2GoOnBus_Click(object sender, EventArgs e)
 {
     canlibCLSNET.Canlib.canSetBusParams(handle2, canlibCLSNET.Canlib.canBITRATE_250K, 0, 0, 0, 0, 0);
     stat = canlibCLSNET.Canlib.canBusOn(handle2);
 }
Example #10
0
File: Form1.cs Project: mc01104/CTR
 private void ButtonInterface1GoOnBus_Click(object sender, EventArgs e)
 {
     textBoxResult.Text = canlibCLSNET.Canlib.canSetBusParams(handle1, canlibCLSNET.Canlib.canBITRATE_250K, 0, 0, 0, 0, 0).ToString(); ;
     stat = canlibCLSNET.Canlib.canBusOn(handle1);
     //canlibCLSNET.Canlib.canBusOn(readHandle);
 }
Example #11
0
        private void button6_Click(object sender, System.EventArgs e)
        {
            byte[] msg = {0, 0, 0, 0, 0, 0};
              int dlc, flag, i=0, id = 123;
              long time;

              can_status = canlibCLSNET.Canlib.canStatus.canOK;
              while (can_status == canlibCLSNET.Canlib.canStatus.canOK)
              {
            can_status = canlibCLSNET.Canlib.canRead(hnd1, out id, msg, out dlc, out flag, out time);
            if(can_status == canlibCLSNET.Canlib.canStatus.canOK)
            {
              i= i +1;
            }
              }
              this.radioButton1.Checked = false;
              this.textBox3.Text = i.ToString();
        }
Example #12
0
        private void button5_Click(object sender, System.EventArgs e)
        {
            byte[] msg = {1,2,3,4,5,6};
              int i;

              for (i =0; i<100; i++)
              {
            can_status = canlibCLSNET.Canlib.canWrite(hnd0, 123, msg, 6, 0);
              }
              if (can_status != canlibCLSNET.Canlib.canStatus.canOK)
              {
            MessageBox.Show("Error sending messages");
              }
              else
              {
            this.radioButton1.Checked = true;
              }
        }
Example #13
0
        private void button3_Click(object sender, System.EventArgs e)
        {
            long freq;
              int tseg1, tseg2, sjw, nosamp, syncmode;
              can_status = canlibCLSNET.Canlib.canGetBusParams(hnd0, out freq, out tseg1, out tseg2, out sjw, out nosamp, out syncmode);
              this.textBox2.Text =  freq.ToString();

              // This is pointless in this context - it's here just to
              // demonstrate how to call canIoCtl..
              //
              // By the way, a customer reports that the following code:
              // canlibCLSNET.Canlib.canIoCtl(intHdlCanCh0,
              //   canlibCLSNET.Canlib.canIOCTL_SET_TIMER_SCALE,
              //   Convert.ToUInt32(100))
              // works fine in VB.NET.
              //

              object tmp = (UInt32) 100;
              canlibCLSNET.Canlib.canIoCtl(hnd0,
                                   canlibCLSNET.Canlib.canIOCTL_SET_TIMER_SCALE,
                                   ref tmp);
        }
Example #14
-1
File: Form1.cs Project: mc01104/CTR
 private void buttonSetFilter_Click(object sender, EventArgs e)
 {
     stat = canlibCLSNET.Canlib.canSetAcceptanceFilter(handle2, int.Parse(textBoxCode.Text), int.Parse(textBoxMask.Text), 0);
 }