Exemple #1
0
        private void btnReceiveCANMsgs_Click(object sender, EventArgs e)
        {
            TLIBCAN[] canBuffer = new TLIBCAN[100];
            int       revCnt    = 0;

            revCnt = TsMasterApi.tsfifo_receive_can_message_list(ref canBuffer, 100, APP_CHANNEL.CHN1, READ_TX_RX_DEF.TX_RX_MESSAGES);  //如果执行失败,请检查是否通过TsMasterApi.tsapp_enable_receive_fifo();开启了内部Buffer
            if (revCnt == 0)
            {
                //Log("No Message Received!");
                return;
            }
            msgcount     += revCnt;
            lblCount.Text = msgcount.ToString();
            for (int i = 0; i < revCnt; i++)
            {
                string msg = "CAN Msg: ";
                if (canBuffer[i].FIsTx)
                {
                    msg += "Tx ";
                }
                else
                {
                    msg += "Rx ";
                }
                msg += canBuffer[i].FIdentifier.ToString("X8");
                Log(msg);
            }
        }
Exemple #2
0
        private void btnSetCANSignalValue_Click(object sender, EventArgs e)
        {
            //输入原始的CAN报文,报文名称,信号名称,直接提取出对应的信号名称
            TLIBCAN canObj = new TLIBCAN(0, 0x123, true, false, false, 8); //也可以创建一个全局的CAN报文,每次只修改信号值

            srcSignalValue += 1;
            if (CheckResultOK(TsMasterApi.tsdb_set_signal_value_can(ref canObj, tBMessageName.Text, tBSignalName.Text, srcSignalValue)))
            {
                Log("Set SignalValue:" + srcSignalValue.ToString("F2") + " Success!");
            }
            TsMasterApi.tsapp_add_cyclic_msg_can(ref canObj, 10);
        }
Exemple #3
0
        private void btnTransmitCANSync_Click(object sender, EventArgs e)
        {
            TLIBCAN canMsg = new TLIBCAN(0, 0x456, true, false, false, 8);

            if (TsMasterApi.tsapp_transmit_can_sync(ref canMsg, 100) == 0)
            {
                Log("Sync Send CAN Message Success!");
            }
            else
            {
                Log("Sync Send CAN Message Failed");
            }
        }
Exemple #4
0
 private void btnDeleteCANPeridicMessage_Click(object sender, EventArgs e)
 {
     try
     {
         byte    canid  = Convert.ToByte(tbDelPeriodCANID.Text, 16);
         TLIBCAN canObj = new TLIBCAN(0, canid, true, false, false, 0);
         if (TsMasterApi.tsapp_delete_cyclic_msg_can(ref canObj) == 0)
         {
             Log("Delete Period CAN Message Success!");
         }
     }
     catch
     {
     }
 }
Exemple #5
0
 private void btnAddCANPerodicMessage_Click(object sender, EventArgs e)
 {
     try
     {
         byte    canid  = Convert.ToByte(tbAddPeriodCANID.Text, 16);
         TLIBCAN canObj = new TLIBCAN(0, canid, true, false, false, 0);
         canObj.FDLC     = 8;
         canObj.FData[0] = 0xAA;
         canObj.FData[1] = 0xBB;
         Single intervalTime = Convert.ToSingle(tbAddPeriodCANIntervalTime.Text);
         if (TsMasterApi.tsapp_add_cyclic_msg_can(ref canObj, intervalTime) == 0)
         {
             Log("Add Period CAN Message Success!");
         }
     }
     catch
     {
     }
 }
Exemple #6
0
        private void btnReadCANSignalValue_Click(object sender, EventArgs e)
        {
            //输入原始的CAN报文,报文名称,信号名称,直接提取出对应的信号名称
            if (cbbDBCChannel.SelectedIndex < 0)
            {
                Log("Please Select DBC Channel First!");
                return;
            }
            TLIBCAN canObj = new TLIBCAN((APP_CHANNEL)cbbDBCChannel.SelectedIndex, 0x551, true, false, false, 8);

            for (int i = 0; i < 8; i++)
            {
                canObj.FData[i] = 0xFF;
            }
            double sigValue = 0;

            if (CheckResultOK(TsMasterApi.tsdb_get_signal_value_can(ref canObj, "Wheel_Speed", "FL_Speed", ref sigValue)))
            {
                Log("SignalValue is:" + sigValue.ToString());
            }
        }
Exemple #7
0
 private void OnCANRxEvent(IntPtr AObj, ref TLIBCAN AData)
 {
     if (AData.FIsTx)
     {
         byte canid = Convert.ToByte(tbAddPeriodCANID.Text, 16);
         if (AData.FIdentifier == canid)
         {
             AData.FData[0]++;
             AData.FData[1]--;
             //更新数据还是采用tsapp_add_cyclic_msg_can函数,不新增API
             if (TsMasterApi.tsapp_add_cyclic_msg_can(ref AData, Convert.ToSingle(tbAddPeriodCANIntervalTime.Text)) == 0)
             {
                 //避免直接跨线程操作界面控件!
             }
         }
     }
     if (AData.FIdentifier == 0x123)
     {
         if (TsMasterApi.tsdb_get_signal_value_can(ref AData, tBMessageName.Text, tBSignalName.Text, ref testSignalValue) == 0x00)
         {
             //ReadData Success
         }
     }
 }