Example #1
0
        static void Main(string[] args)
        {
            Log.SetGlobalOutputLevel(Log.Severity.INFO);
            Log.SetSingleOutputLevel(Log.Source.NETWORK, Log.Severity.DEBUG);
            Log.ErrorCodes  = ScienceErrors.ERROR_CODES;
            Log.SystemNames = ScienceErrors.SYSTEMS;
            Log.Begin();
            Log.ForceOutput(Log.Severity.INFO, Log.Source.OTHER, "Science Station - Base Side");

            byte[] StrB    = UtilData.ToBytes("Erza-{}'");
            byte[] Fail    = new byte[] { 0x8C };
            bool   Success = UtilData.TryToString(Fail, out string Str);

            if (Success)
            {
                Console.WriteLine(Str);
            }
            else
            {
                Console.WriteLine(UtilMain.BytesToNiceString(StrB, true));
            }

            MainWindow Main = new MainWindow();

            Application.EnableVisualStyles();
            Server.ClientConnectionChange += Main.UpdateClientList;
            Application.Run(Main);
        }
Example #2
0
 /// <summary> Checks if the device is responding by querying a known, constant register value. </summary>
 public bool Test()
 {
     byte[] DeviceData = Read((byte)Register.DEV_ID, 1);
     if (this.TraceLogging)
     {
         Log.Trace(this, "Testing returned " + UtilMain.BytesToNiceString(DeviceData, false) + ", expected 0x60.");
     }
     return((DeviceData != null) && (DeviceData.Length > 0) && (DeviceData[0] == 0x60));
 }
Example #3
0
 private void DataTextbox_TextChanged(object sender, EventArgs e)
 {
     try
     {
         byte[] Data = InterpretInput(this.DataTextbox.Text.ToCharArray());
         this.InterpretationData.Text = "0x" + UtilMain.BytesToNiceString(Data, true);
     }
     catch { this.InterpretationData.Text = "Unknown"; }
 }
Example #4
0
 private void IDTextbox_TextChanged(object sender, EventArgs e)
 {
     try
     {
         byte[] ID = UtilMain.StringToBytes(this.IDTextbox.Text);
         this.InterpretationID.Text = "0x" + UtilMain.BytesToNiceString(new byte[] { ID.Last() }, false);
     }
     catch { this.InterpretationID.Text = "Unknown"; }
 }
Example #5
0
        /// <summary> Formats the Messages's contents to be human-readable. </summary>
        public override string ToString()
        {
            StringBuilder Str = new StringBuilder();

            Str.Append("Packet = Time:(0x");
            Str.Append(UtilMain.BytesToNiceString(this.Timestamp, false));
            Str.Append(") ID:(0x");
            Str.Append(this.ID.ToString("X2"));
            Str.Append(") Data:(0x");
            Str.Append(UtilMain.BytesToNiceString(this.Payload, true));
            Str.Append(')');
            return(Str.ToString());
        }
Example #6
0
        /// <summary> Does a 12b read/write with the specified command. </summary>
        /// <param name="Command"> The command (4 MSb) to send. </param>
        /// <param name="Data"> The data (12 LSb) to send. </param>
        /// <param name="Long"> Whether to send out additional SCLK pulses for the ADC to do sampling. </param>
        /// <returns> The 12b data returned by the device. </returns>
        private ushort DoCommand(Command Command, ushort Data = 0x000, bool Long = false)
        {
            byte[] DataOut;
            if (!Long)
            {
                DataOut = new byte[2];
            }                                     // Regular command, no sampling.
            else
            {
                switch (this.Config.ConversionClockSrc) // We are doing sampling, determine the correct number of SCLKs.
                {
                case ConversionClockSrc.SCLK:
                    DataOut = (this.Config.UseLongSample ? new byte[2 + 4] : new byte[2 + 2]);
                    break;

                case ConversionClockSrc.SCLK_HALF:
                    DataOut = (this.Config.UseLongSample ? new byte[2 + 7] : new byte[2 + 4]);
                    break;

                case ConversionClockSrc.SCLK_QUARTER:
                    DataOut = (this.Config.UseLongSample ? new byte[2 + 14] : new byte[2 + 7]);
                    break;

                case ConversionClockSrc.INTERNAL: // We are assuming the time between The two SPI transactions is at least 4us for short, or 8us for long sampling. This seems to always be true on the Pi, but is not guaranteed.
                    DataOut = new byte[2];        // No need for additional SCLKs.
                    break;

                default:
                    DataOut = new byte[2];
                    break;
                }
            }

            DataOut[0] = (byte)((((byte)Command << 4) & 0b1111_0000) | ((Data >> 8) & 0b0000_1111));
            DataOut[1] = (byte)(Data & 0b1111_1111);
            if (this.TraceLogging)
            {
                Log.Trace(this, "Sending command: " + UtilMain.BytesToNiceString(DataOut, true));
            }
            byte[] DataIn = this.Bus.Write(this.CS, DataOut, DataOut.Length);
            if (this.TraceLogging)
            {
                Log.Trace(this, "Received: " + UtilMain.BytesToNiceString(DataIn, true));
            }
            return((ushort)(Command == Command.READ_CONF ?
                            (((DataIn[0] & 0b0000_1111) << 8) | (DataIn[1])) :
                            (DataIn[0] << 4) | ((DataIn[1] & 0b1111_0000) >> 4)));
        }
Example #7
0
 private void UpdateTime()
 {
     this.TimestampTextbox.Text = UtilMain.BytesToNiceString(Packet.GetCurrentTime(), true);
 }