unsafe protected bool TransmitData(string Data, uint deviceType, uint deviceIndex, uint cANIndex, uint frameid)
        {
            bool IsTransmitSuccess = false;

            if (IsOpen)
            {
                VCI_CAN_OBJ sendobj = new VCI_CAN_OBJ()
                {
                    SendType   = 2,       //=0时为正常发送,=1时为单次发送,=2时为自发自收,=3时为单次自发自收,只在此帧为发送帧时有意义。
                    ID         = frameid, //帧ID
                    DataLen    = 8,       //数据长度
                    RemoteFlag = 0,       //是否是远程帧
                    ExternFlag = 0,       //是否是扩展帧。
                    TimeFlag   = 1        //是否使用时间标识,为 1 时 TimeStamp 有效,TimeFlag 和 TimeStamp 只在此帧为接收帧时有意义
                };

                string      strdata  = Data;
                int         len      = (strdata.Length + 1) / 3;
                List <byte> bytelist = new List <byte>();
                for (int t = 0; t < len; t++)
                {
                    //bytelist.Add(Convert.ToByte("0x" + strdata.Substring(t * 3, 2), 16));
                    bytelist        = ConvertFrom.HexstringToBytesArray(Data);
                    sendobj.Data[t] = bytelist[t];
                }
                if (VCI_Transmit(deviceType, deviceIndex, cANIndex, ref sendobj, 2) == 1)
                {
                    IsTransmitSuccess = true;
                }
                return(IsTransmitSuccess);
            }
            return(IsTransmitSuccess);
        }
Beispiel #2
0
 public override void WriteCommand(SerialPort serialPort, string command)
 {
     if (serialPort.IsOpen)
     {
         List <byte> list = ConvertFrom.HexstringToBytesArray(command);
         serialPort.Write(list.ToArray(), 0, list.Count);
     }
 }
Beispiel #3
0
 public void writesp(string data)
 {
     if (mySerialPort.IsOpen)
     {
         List <byte> bytelist = ConvertFrom.HexstringToBytesArray(data);
         mySerialPort.Write(bytelist.ToArray(), 0, bytelist.Count);
     }
     else
     {
         MessageBox.Show("串口未打开!");
     }
 }
        private static bool Satellite(string value)
        {
            List <byte> listvar        = ConvertFrom.HexstringToBytesArray(value);
            List <byte> Satelliteindex = new List <byte>();
            List <int>  Strength       = new List <int>();
            var         newlist        = listvar.Select((b, index) => new { index, b });//投影出index

            foreach (var item in newlist)
            {
                if (item.index % 2 == 1)
                {
                    Strength.Add(item.b);
                }
                else
                {
                    Satelliteindex.Add(item.b);
                }
            }
            return(Strength.Where(i => i > 21).Count() >= 7);
        }