Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            TPCANMsg    CANMsg;
            TPCANStatus stsResult;

            //创建一帧信息
            CANMsg         = new TPCANMsg();
            CANMsg.ID      = 0x183;
            CANMsg.LEN     = Convert.ToByte(8);
            CANMsg.MSGTYPE = TPCANMessageType.PCAN_MESSAGE_STANDARD;
            CANMsg.DATA    = new byte[8];
            for (int i = 0; i < 6; i++)
            {
                CANMsg.DATA[i] = 0;
            }
            CANMsg.DATA[6] = 0;
            CANMsg.DATA[7] = 0;

            TPCANMsg msg = new TPCANMsg();

            msg.ID      = 0x183;
            msg.LEN     = Convert.ToByte(8);
            msg.MSGTYPE = TPCANMessageType.PCAN_MESSAGE_STANDARD;
            msg.DATA    = new byte[8];
            msg.DATA[0] = 1;
            msg.DATA[1] = 0;
            peakHelperer.write(msg);
            peakHelperer.write(CANMsg);
        }
Beispiel #2
0
        public IMessage CreateMessage(MessageType type, uint id, byte[] data)
        {
            TPCANMessageType t = TPCANMessageType.PCAN_MESSAGE_STANDARD;

            switch (type)
            {
            case MessageType.Standard:
                t = TPCANMessageType.PCAN_MESSAGE_STANDARD;
                break;

            case MessageType.Extended:
                t = TPCANMessageType.PCAN_MESSAGE_EXTENDED;
                break;

            case MessageType.Status:
                t = TPCANMessageType.PCAN_MESSAGE_STATUS;
                break;

            case MessageType.Special:
                throw new NotSupportedException("It is not possible to create a CAN message with the \"Special\" type.");
            }
            TPCANMsg msg = new TPCANMsg();

            msg.MSGTYPE = t;
            msg.ID      = id;
            msg.DATA    = (data != null) ? data : new byte[] { };
            msg.LEN     = (data != null) ? (byte)data.Length : (byte)0;
            return(new PCANMessage(msg));
        }
        /// <summary>
        /// 试验发送参数。
        /// </summary>
        public void writeTest()
        {
            TPCANMsg canmsg183;

            canmsg183         = new TPCANMsg();
            canmsg183.ID      = 0x183;
            canmsg183.LEN     = Convert.ToByte(8);
            canmsg183.MSGTYPE = TPCANMessageType.PCAN_MESSAGE_STANDARD;
            canmsg183.DATA    = new byte[8];
            int mainP;
            int mediumtime;
            int steerTime;

            int.TryParse(txtMainP.Text.Trim(), out mainP);
            int.TryParse(txtMediumPTime.Text.Trim(), out mediumtime);
            int.TryParse(txtSteerTestTime.Text.Trim(), out steerTime);
            for (int i = 0; i < 8; i++)
            {
                canmsg183.DATA[i] = 0;
            }
            //   canmsg183.DATA[1] = 1;
            canmsg183.DATA[0] = Convert.ToByte(mainP);
            canmsg183.DATA[4] = Convert.ToByte(20);
            canmsg183.DATA[6] = Convert.ToByte(20);
            TPCANStatus sts = peakhelper.write(canmsg183);
        }
Beispiel #4
0
 public CanMsg(TPCANMsg msg, TPCANTimestamp timestamp, int index)
 {
     this.msg          = msg;
     this.timestamp    = timestamp;
     this.index        = index;
     this.recieveCount = 0;
 }
Beispiel #5
0
        /// <summary>
        /// Inserts a new entry for a new message in the Message-ListView
        /// </summary>
        /// <param name="newMsg">The messasge to be inserted</param>
        /// <param name="timeStamp">The Timesamp of the new message</param>
        private void InsertMsgEntry(TPCANMsg newMsg, TPCANTimestamp timeStamp)
        {
            MessageStatus msgStsCurrentMsg;
            ListViewItem  lviCurrentItem;

            lock (m_LastMsgsList.SyncRoot)
            {
                // We add this status in the last message list
                //
                msgStsCurrentMsg = new MessageStatus(newMsg, timeStamp, lstMessages.Items.Count);
                m_LastMsgsList.Add(msgStsCurrentMsg);

                // Add the new ListView Item with the Type of the message
                //
                lviCurrentItem = lstMessages.Items.Add(msgStsCurrentMsg.TypeString);
                // We set the ID of the message
                //
                lviCurrentItem.SubItems.Add(msgStsCurrentMsg.IdString);
                // We set the length of the Message
                //
                lviCurrentItem.SubItems.Add(newMsg.LEN.ToString());
                // We set the data of the message.
                //
                lviCurrentItem.SubItems.Add(msgStsCurrentMsg.DataString);
                // we set the message count message (this is the First, so count is 1)
                //
                lviCurrentItem.SubItems.Add(msgStsCurrentMsg.Count.ToString());
                // Add time stamp information if needed
                //
                lviCurrentItem.SubItems.Add(msgStsCurrentMsg.TimeString);
            }
        }
Beispiel #6
0
        private TPCANStatus WriteFrame(uint nCAN_ID, byte byLen, bool isRemote, byte[] arrData)
        {
            TPCANMsg CANMsg;

            //TextBox txtbCurrentTextBox;

            // We create a TPCANMsg message structure
            //
            CANMsg      = new TPCANMsg();
            CANMsg.DATA = new byte[8];

            // We configurate the Message.  The ID,
            // Length of the Data, Message Type
            // and the data
            //
            CANMsg.ID      = nCAN_ID;                                // Convert.ToUInt32(txtID.Text, 16);
            CANMsg.LEN     = byLen;                                  // Convert.ToByte(nudLength.Value);
            CANMsg.MSGTYPE = TPCANMessageType.PCAN_MESSAGE_EXTENDED; // (chbExtended.Checked) ? TPCANMessageType.PCAN_MESSAGE_EXTENDED : TPCANMessageType.PCAN_MESSAGE_STANDARD;
            // If a remote frame will be sent, the data bytes are not important.
            //
            if (isRemote)
            {
                CANMsg.MSGTYPE |= TPCANMessageType.PCAN_MESSAGE_RTR;
            }
            else
            {
                Buffer.BlockCopy(arrData, 0, CANMsg.DATA, 0, byLen);
            }

            // The message is sent to the configured hardware
            //
            return(PCANBasic.Write(m_PcanHandle, ref CANMsg));
        }
        private void btnRetest_Click(object sender, EventArgs e)
        {
            TPCANMsg canmsg183;

            canmsg183         = new TPCANMsg();
            canmsg183.ID      = 0x183;
            canmsg183.LEN     = Convert.ToByte(8);
            canmsg183.MSGTYPE = TPCANMessageType.PCAN_MESSAGE_STANDARD;
            canmsg183.DATA    = new byte[8];
            for (int i = 0; i < 8; i++)
            {
                canmsg183.DATA[i] = 0;
            }
            canmsg183.DATA[0] = 50;
            canmsg183.DATA[2] = 0;
            canmsg183.DATA[3] = 0;
            canmsg183.DATA[5] = 0;
            TPCANStatus sts = peakhelper.write(canmsg183);

            if (sts == TPCANStatus.PCAN_ERROR_OK)
            {
                MessageBox.Show("置0发送成功");
            }
            this.Close();
            ManualNumberInput win = ManualNumberInput.getInstance();

            win.Show();
        }
Beispiel #8
0
        public void Write(string id, byte[] data)
        {
            TPCANStatus result;
            TPCANMsg    msg;

            msg = new TPCANMsg();

            msg.ID      = Convert.ToUInt32(id, 16);
            msg.LEN     = Convert.ToByte(data.Length);
            msg.DATA    = new byte[8];
            msg.MSGTYPE = TPCANMessageType.PCAN_MESSAGE_STANDARD;

            for (int i = 0; i < msg.LEN; i++)
            {
                msg.DATA[i] = data[i];
            }

            PCANBasic.Write(mChannel, ref msg);

            result = PCANBasic.Write(mChannel, ref msg);

            if (result != TPCANStatus.PCAN_ERROR_OK)
            {
                StringBuilder strMsg = new StringBuilder(256);
                PCANBasic.GetErrorText(result, 0, strMsg);
                //Console.WriteLine(strMsg.ToString());
            }
        }
        private void btnSinglePoint_Click(object sender, EventArgs e)
        {
            TPCANMsg canmsg108;

            canmsg108         = new TPCANMsg();
            canmsg108.ID      = 0x108;
            canmsg108.LEN     = Convert.ToByte(8);
            canmsg108.MSGTYPE = TPCANMessageType.PCAN_MESSAGE_STANDARD;
            canmsg108.DATA    = new byte[8];
            canmsg108.DATA[6] = 1;
            try
            {
                TPCANStatus res1 = peakHelperer.write(canmsg108);
                if (res1 == TPCANStatus.PCAN_ERROR_OK)
                {
                    MessageBox.Show("进入单点模式");
                    SinglePointDebuggingWin win = new SinglePointDebuggingWin();
                    win.Show();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("进入单点模式失败" + ex.Message);
            }
        }
Beispiel #10
0
        private void btnSaveSettings_Click(object sender, EventArgs e)
        {
            TPCANMsg    CANMsg;
            TPCANStatus stsResult;

            CANMsg      = new TPCANMsg();
            CANMsg.DATA = new byte[8];


            //get ID from BOX
            byte MasterUnitId, NewMasterId = 0;

            try
            {
                MasterUnitId = (byte)((Convert.ToUInt16(MasterID.Text)));
                NewMasterId  = (byte)((Convert.ToUInt16(boxNewMasterId.Text)));
            }
            catch {
                MessageBox.Show("Wrong ID. Please fill in value 1-255");
                return;
            }


            //construct can ID
            byte[] bytes = { 0x18, 0x00, MasterUnitId, 0x00 };
            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(bytes);
            }
            uint id = BitConverter.ToUInt32(bytes, 0);

            // If the system architecture is little-endian (that is, little end first),
            // reverse the byte array.



            ////////////////////////////////////////////
            //create and send settings message
            ////////////////////////////////////////////
            //Max avaliable current we read from textbox  -boxAvailCurrent

            CANMsg.ID      = id;
            CANMsg.LEN     = 8;
            CANMsg.MSGTYPE = (TPCANMessageType.PCAN_MESSAGE_EXTENDED);
            CANMsg.DATA[0] = 0;                               //CAN adress Hi
            CANMsg.DATA[1] = 0;                               //CAN address LO
            CANMsg.DATA[2] = (byte)boxBaudRate.SelectedIndex; //baudrate
            CANMsg.DATA[3] = NewMasterId;                     //ID
            CANMsg.DATA[4] = 0;
            CANMsg.DATA[5] = 0;
            CANMsg.DATA[6] = 0;
            CANMsg.DATA[7] = 0;
            stsResult      = PCANBasic.Write(m_PcanHandle, ref CANMsg);
            // The message was successfully sent
            if (stsResult != TPCANStatus.PCAN_ERROR_OK)
            {
                MessageBox.Show(GetFormatedError(stsResult));
            }
        }
Beispiel #11
0
        public static void sendInstruction(byte[] trame)
        {
            TPCANMsg CANMsg = new TPCANMsg();

            CANMsg.DATA = trame;                         //new byte[8];
            CANMsg.ID   = CANDevice.HARDWARE_FILTER_TAC; //  physical filtering address
            PCANCom.Instance.send(CANMsg);
        }
Beispiel #12
0
 public void Update(TPCANMsg canMsg, TPCANTimestamp canTimestamp)
 {
     m_Msg          = canMsg;
     m_oldTimeStamp = m_TimeStamp;
     m_TimeStamp    = canTimestamp;
     m_bWasChanged  = true;
     m_Count       += 1;
 }
Beispiel #13
0
 public MessageStatus(TPCANMsg canMsg, TPCANTimestamp canTimestamp, int listIndex)
 {
     m_Msg          = canMsg;
     m_TimeStamp    = canTimestamp;
     m_oldTimeStamp = canTimestamp;
     m_iIndex       = listIndex;
     m_Count        = 1;
     m_bShowPeriod  = true;
     m_bWasChanged  = false;
 }
Beispiel #14
0
 public static void printReceivedPacket(TPCANMsg msg)
 {
     Console.WriteLine(" ");
     Console.WriteLine("---------------------------------------");
     Console.Write("R: ");
     for (int n = 0; n < 8; n++)
     {
         Console.Write("[{0:X}] ", msg.DATA[n]);
     }
 }
Beispiel #15
0
        public static void homeTool()
        {
            TPCANMsg CANMsg = new TPCANMsg();

            CANMsg.DATA = new byte[8];

            CANMsg.DATA[INSTRUCTION_BYTE] = (byte)InstructionSet.Home;
            CANMsg.ID = CANDevice.HARDWARE_FILTER_GRIPPER;

            PCANCom.Instance.send(CANMsg);
        }
Beispiel #16
0
        public static void sendInstruction(byte instruction, UInt16 data)
        {
            TPCANMsg CANMsg = new TPCANMsg();

            CANMsg.DATA = new byte[8];
            CANMsg.DATA[INSTRUCTION_BYTE] = instruction;
            CANMsg.DATA[1] = (byte)(data);
            CANMsg.DATA[2] = (byte)(data >> 8);
            CANMsg.ID      = CANDevice.HARDWARE_FILTER_GRIPPER;
            PCANCom.Instance.send(CANMsg);
        }
Beispiel #17
0
 /// <summary>
 /// Sends the PCAN data.
 /// </summary>
 /// <param name="msg">The MSG.</param>
 /// <returns>TPCANStatus.</returns>
 public TPCANStatus sendPCANData(ref TPCANMsg msg)
 {
     if (this.isDisposed)
     {
         return(TPCANStatus.PCAN_ERROR_BUSOFF);
     }
     else
     {
         return(this.manager.sendPCANData(ref msg));
     }
 }
Beispiel #18
0
        public static void addGetMotorType(byte treatingFunction, byte id)
        {
            TPCANMsg CANMsg = new TPCANMsg();

            CANMsg.DATA    = new byte[8];
            CANMsg.DATA[0] = DynamixelCANInstruction.GET_MOTOR_TYPE;
            CANMsg.DATA[1] = id;
            CANMsg.DATA[2] = treatingFunction;
            CANMsg.ID      = CANDeviceConstant.HARDWARE_FILTER_GRIPPER;
            CANQueue.Instance.add(CANMsg);
        }
        public FmiCanFrame(TPCANMsg p_raw_frame)
        {
            m_can_id = p_raw_frame.ID;

            m_data8 = new byte[8];

            for (int i = 0; i < p_raw_frame.LEN; i++)
            {
                m_data64  |= (ulong)p_raw_frame.DATA[i] << (i * 8);
                m_data8[i] = p_raw_frame.DATA[i];
            }
        }
        public static void sendPositionToMoveTo(Int16 position)
        {
            TPCANMsg CANMsg = new TPCANMsg();

            CANMsg.DATA = new byte[8];

            CANMsg.DATA[INSTRUCTION_BYTE] = (byte)InstructionSet.GoTo;
            CANMsg.DATA[6] = (byte)(position >> 8);
            CANMsg.DATA[7] = (byte)(position);
            CANMsg.ID      = CANDevice.HARDWARE_FILTER_MUTLI_CHANNEL_PIPETTE;
            PCANCom.Instance.send(CANMsg);
        }
Beispiel #21
0
        public static void sendInstruction(byte instruction, byte id, UInt16 data)
        {
            TPCANMsg CANMsg = new TPCANMsg();

            CANMsg.DATA    = new byte[8];
            CANMsg.DATA[0] = instruction;
            CANMsg.DATA[1] = id;
            CANMsg.DATA[2] = (byte)data;
            CANMsg.DATA[3] = (byte)(data >> 8);
            CANMsg.ID      = CANDeviceConstant.HARDWARE_FILTER_GRIPPER;
            CANQueue.Instance.add(CANMsg);
        }
Beispiel #22
0
        public static void addGetInstruction(byte treatingFunction, byte id, byte adress, byte nbOfByte)
        {
            TPCANMsg CANMsg = new TPCANMsg();

            CANMsg.DATA    = new byte[8];
            CANMsg.DATA[0] = DynamixelCANInstruction.GET_DATA;
            CANMsg.DATA[1] = id;
            CANMsg.DATA[2] = adress;
            CANMsg.DATA[3] = (byte)(nbOfByte % 5);
            CANMsg.ID      = CANDeviceConstant.HARDWARE_FILTER_GRIPPER;
            CANQueue.Instance.add(CANMsg);
        }
        public static void dispense(Int16 volume)
        {
            TPCANMsg CANMsg = new TPCANMsg();

            CANMsg.DATA = new byte[8];

            CANMsg.DATA[INSTRUCTION_BYTE] = (byte)InstructionSet.Dispense;
            CANMsg.DATA[6] = (byte)(volume >> 8);
            CANMsg.DATA[7] = (byte)(volume);
            CANMsg.ID      = CANDevice.HARDWARE_FILTER_MUTLI_CHANNEL_PIPETTE;

            PCANCom.Instance.send(CANMsg);
        }
Beispiel #24
0
        public void SendFrame(Frame frame)
        {
            var msg = new TPCANMsg()
            {
                DATA    = frame.Data,
                ID      = (uint)frame.Id,
                LEN     = (byte)frame.Data.Length,
                MSGTYPE = frame.Type == FrameType.Standard ? TPCANMessageType.PCAN_MESSAGE_STANDARD : TPCANMessageType.PCAN_MESSAGE_EXTENDED
            };
            var ret = PCANBasic.Write(Channel, ref msg);

            CheckError(ret);
        }
Beispiel #25
0
        public static void sendInstruction(byte instruction)
        {
            TPCANMsg CANMsg = new TPCANMsg();

            CANMsg.DATA = new byte[8];
            CANMsg.DATA[INSTRUCTION_BYTE] = instruction;
            CANMsg.ID = CANDevice.HARDWARE_FILTER_GRIPPER;
            PCANCom.Instance.send(CANMsg);

            /*Console.WriteLine(" ");
             * Console.WriteLine("---------------------------------------");
             * Console.Write("T: ");
             * printPacket(CANMsg.DATA);//*/
        }
Beispiel #26
0
        public static void addSetInstruction(byte id, byte adress, byte nbOfByte, UInt16 data)
        {
            TPCANMsg CANMsg = new TPCANMsg();

            CANMsg.DATA    = new byte[8];
            CANMsg.DATA[0] = DynamixelCANInstruction.SET_DATA;
            CANMsg.DATA[1] = id;
            CANMsg.DATA[2] = adress;
            CANMsg.DATA[3] = (byte)(nbOfByte % 3);
            CANMsg.DATA[4] = (byte)data;
            CANMsg.DATA[5] = (byte)(data >> 8);
            CANMsg.ID      = CANDeviceConstant.HARDWARE_FILTER_GRIPPER;
            CANQueue.Instance.add(CANMsg);
        }
Beispiel #27
0
        /// <summary>
        /// Sends the PCAN data.
        /// </summary>
        /// <param name="msg">The MSG.</param>
        /// <returns>TPCANStatus.</returns>
        public TPCANStatus sendPCANData(ref TPCANMsg msg)
        {
            TPCANStatus stsResult = TPCANStatus.PCAN_ERROR_BUSOFF;

            if (this.isRunning)
            {
                stsResult = PCANBasic.Write(this._canChannel, ref msg);
                if (sleepTime > 0)
                {
                    Thread.Sleep(sleepTime);
                }
            }
            return(stsResult);
        }
        public static void sendInstruction(byte direction, String volume)
        {
            TPCANMsg CANMsg = new TPCANMsg();

            CANMsg.DATA = new byte[8];
            Int16 aaa;

            Int16.TryParse(volume, out aaa);
            CANMsg.DATA[4] = (byte)(aaa >> 8);
            CANMsg.DATA[5] = (byte)(aaa);
            CANMsg.DATA[6] = direction;
            CANMsg.ID      = CANDevice.HARDWARE_FILTER_MUTLI_CHANNEL_PIPETTE;

            PCANCom.Instance.send(CANMsg);
        }
Beispiel #29
0
        public static void sendMessage(byte instruction, byte byte1, byte byte2, byte byte3, byte byte4, byte byte5, byte byte6, byte byte7)
        {
            TPCANMsg CANMsg = new TPCANMsg();

            CANMsg.DATA    = new byte[8];
            CANMsg.DATA[0] = instruction;
            CANMsg.DATA[1] = byte1;
            CANMsg.DATA[2] = byte2;
            CANMsg.DATA[3] = byte3;
            CANMsg.DATA[4] = byte4;
            CANMsg.DATA[5] = byte5;
            CANMsg.DATA[6] = byte6;
            CANMsg.DATA[7] = byte7;
            CANMsg.ID      = CANDeviceConstant.HARDWARE_FILTER_GRIPPER;
            PCANCom.Instance.send(CANMsg);
        }
Beispiel #30
0
        /// <summary>Converts a Frame into a TPCANMsg</summary>
        public static TPCANMsg Frame(Frame f)
        {
            var m = new TPCANMsg();

            m.ID   = (uint)f.ID;
            m.DATA = new byte[8];               // needs to be the full 8 bytes
            for (int i = 0; i < f.Length; i++)
            {
                m.DATA[i] = f[i];
            }
            m.LEN      = f.Length;
            m.MSGTYPE  = TPCANMessageType.PCAN_MESSAGE_STANDARD;
            m.MSGTYPE |= f.Extended ? TPCANMessageType.PCAN_MESSAGE_EXTENDED : 0;
            m.MSGTYPE |= f.Remote ? TPCANMessageType.PCAN_MESSAGE_RTR : 0;
            return(m);
        }
Beispiel #31
0
 public static extern uint Write(ref TPCANMsg msg);
Beispiel #32
0
 public static extern uint Read(out TPCANMsg msg);
Beispiel #33
0
 public static extern uint ReadEx(out TPCANMsg msg, out TPCANTimestamp timestamp);