Beispiel #1
0
 public IEnumerable <SerialStatus> SendData([FromBody] TxData data)
 {
     Console.WriteLine("Write data: \"{0}\"", data.Data);
     if (Global.MyPort != null && Global.MyPort.CanWrite)
     {
         Global.MyPort.Write(data.Data);
     }
     Global.RxData += Global.MyPort.ReadExisting();
     return(Enumerable.Repeat(new SerialStatus
     {
         Connected = Global.MyPort.CanWrite,
         StrError = "Send Data",
         StrRxData = "",
         StrTxData = data.Data
     }, 1));
 }
Beispiel #2
0
        public override void OnSlaveReceived()
        {
            if (Request.Length > 0)
            {
                TxData.Clear();

                for (int n = 0; n < Request.Length; ++n)
                {
                    TxData.Add(Request.GetByte(n));
                }
            }
            else
            {
                TxData.Clear();
            }
        }
Beispiel #3
0
        public TxInfo(walletViewModel model, TxData tx)
        {
            Tx    = tx;
            Model = model;

            if (Tx.lockTime < 1)
            {
                Confirmations = 0;
            }
            else
            {
                Confirmations = Model.height - Tx.lockTime + 1;
            }

            InitializeComponent();

            DataContext = this;
        }
Beispiel #4
0
 public SPITestFunction(List <byte> data) :
     base(requestLength: data.Count, responseLength: data.Count)
 {
     TxData.Clear();
     TxData.AddRange(data);
 }
Beispiel #5
0
 public void Exec(TxData txdata)
 {
     Log4NetHelper.Info(LoggerType.ServiceExceptionLog, txdata.GetMsg(), null);
 }
        public int ComPort( 
            string                      PortName,
            System.IO.Ports.StopBits    Stop_Bit,
            byte                        DataBits,
            int                         BaudRate,
            System.IO.Ports.Parity      Parity
            )
        {
            //Create new serial communication port component.
                serialComPort = new System.IO.Ports.SerialPort();
                // create a Receiver structure.
                currentReceivedData = new ReceivedData();
                SendData = new TxData();
                // Create round  Rx buffer.
                round_rx_buf = new byte[ROUND_BUFFER_SIZE];

                //Set init value of round buffer server variables.
                round_rx_buf_head = 0;
                round_rx_buf_tail = 0;
                round_rx_buf_size = 0;

                //open com port and connect
                try
                {
                    if (PortName == "")
                    {
                        // "PortName" error.
                        return 1;
                    }
                    // Setup port parameters.
                    serialComPort.StopBits = Stop_Bit;
                    serialComPort.DataBits = DataBits;
                    serialComPort.BaudRate = BaudRate;
                    serialComPort.PortName = PortName;
                    serialComPort.Parity   = Parity.None;
                    //Set DataReceived event function.
                    serialComPort.DataReceived += new SerialDataReceivedEventHandler(PortDataReceived);
                    // Opening port.
                    serialComPort.Open();
                    if (serialComPort.IsOpen)
                    {
                        // Port opened OK.
                        return 0;
                    }
                }
                catch (Exception e1)
                {
                    MessageBox.Show(e1.Message);
                    // Some error happend.
                    return 2;
                }
                // Just return :) .
                return 3;
        }
        private UInt16 CalcTxCRC(TxData RData)
        {
            const UInt16 polinom = 0xa001;
                UInt16 code = 0xffff;
                byte ml;
                byte tmp;

                //amount of byte in ReceivedData structure.
                //After size of ReceivedData reached 70, Marshal.SizeOf() return 72,
                //so,just work around is change 2 to 4.
                int length = Marshal.SizeOf(RData) - 2;// 2 is sizeof CRC in ReceivedData
                for (int i = 0; i < length; i++)
                {
                    //For each byte from array

                    /* Put LSB of 16 bit code(in the future a СRС16) to ml. */
                    ml = (byte)(code);

                    /* Do m1 XOR msg[i] and put result to m1. */
                    tmp = Marshal.ReadByte(RData, i);
                    ml ^= tmp;

                    /* Set LSB of code to zero. */
                    code &= 0xff00;
                    code += ml;
                    for (int j = 0; j < 8; j++)
                    {
                        /* Check LSB bit of code. */
                        if ((code & 0x0001) == 1)
                        {   /* LSB bit is 1. */
                            code >>= 1;
                            /* Do code XOR polinom and put result to code. */
                            code ^= polinom;
                        }
                        else
                        {   /* LSB bit is 0*/
                            code >>= 1;
                        }
                    }
                }
                return code;
        }