private void buttonGetMeasurements_Click(object sender, EventArgs e) { #warning Update to use CommandFormerClass uartReceiver.Reset(); processFunction = ProcessGetMeasurementInfo; // Send command to get measurement header List <byte> sb = new List <byte>(); sb.Add(startSeq); sb.Add(deviceAddr); // Append message length sb.Add(0); sb.Add(9); // Append command sb.Add(commandRead); // Get and append address byte[] bAddress = CustomConvertorClass.ConvertIntTo4Bytes(MEASURE_INFO_BASE); sb.AddRange(bAddress); // Get and append length byte[] bLen = CustomConvertorClass.ConvertIntTo2Bytes(MEASURE_INFO_LEN); sb.AddRange(bLen); // Debug checksum test //sb.Add(0x1); //sb.Add(0x2); // Now calculate and append checksum UInt16 csum = ChecksumClass.CalculateChecksum(sb.ToArray()); byte[] bcsum = CustomConvertorClass.ConvertIntTo2BytesBE(csum); sb.AddRange(bcsum); // 2B serial.Write(sb.ToArray(), 0, sb.Count); }
private void buttonRead_Click(object sender, EventArgs e) { #warning Update to use CommandFormerClass uartReceiver.Reset(); processFunction = DebugRead; List <byte> sb = new List <byte>(); sb.Add(startSeq); sb.Add(deviceAddr); // Append message length, include shecksum sb.Add(0); sb.Add(9); // Append command sb.Add(commandRead); // 1B // Get and append address int temp = Convert.ToInt32(this.textBoxAddress.Text); byte[] bAddress = CustomConvertorClass.ConvertIntTo4Bytes(temp); sb.AddRange(bAddress); // 4B // Get and append length temp = Convert.ToInt32(this.textBoxLen.Text); byte[] bLen = CustomConvertorClass.ConvertIntTo2Bytes(temp); sb.AddRange(bLen); // 2B // Now calculate and append checksum UInt16 csum = ChecksumClass.CalculateChecksum(sb.ToArray()); byte[] bcsum = CustomConvertorClass.ConvertIntTo2BytesBE(csum); sb.AddRange(bcsum); // 2B serial.Write(sb.ToArray(), 0, sb.Count); }
/// <summary> /// Data recorder task /// </summary> /// <param name="channel"> CH0 = 0 , CH1 = 1, CH0 & CH1 = 2</param> /// <param name="opMode"> 1- continuous , 2 - target points </param> /// <param name="prescaler"> (prescaler - 1) * 10ms</param> /// <param name="targetPoints"> How much points should be recorder (not used in continuous mode)</param> public void AppendDataRecorderTask(byte channel, byte opMode, UInt32 prescaler, UInt32 targetPoints, DateTime time) { bl.Add(4); bl.Add(channel); bl.Add(opMode); bl.AddRange(CustomConvertorClass.ConvertIntTo4Bytes(prescaler)); bl.AddRange(CustomConvertorClass.ConvertIntTo4Bytes(targetPoints)); // Now append transformed time bl.Add((byte)(time.Year - 2000)); bl.Add((byte)(time.Month)); bl.Add((byte)(time.Day)); bl.Add((byte)(time.Hour)); bl.Add((byte)(time.Minute)); bl.Add((byte)(time.Second)); }
private void ReadAndDisplayData(int index) { MeasurementHeaderClass header; try { header = headers[index]; } catch (Exception) { MessageBox.Show("Header not present"); return; } uartReceiver.Reset(); processFunction = DebugRead; #warning Update to use CommandFormerClass List <byte> sb = new List <byte>(); sb.Add(startSeq); sb.Add(deviceAddr); // Append message length, include checksum sb.Add(0); sb.Add(9); // Append command sb.Add(commandRead); //1 // Append address byte[] bAddress = CustomConvertorClass.ConvertIntTo4Bytes(header.dataAddress); //5 sb.AddRange(bAddress); // Get and append length byte[] bLen = CustomConvertorClass.ConvertIntTo2Bytes(header.numOfPoints * 2); //7 1 measure is 2 bytes sb.AddRange(bLen); // Now calculate and append checksum UInt16 csum = ChecksumClass.CalculateChecksum(sb.ToArray()); byte[] bcsum = CustomConvertorClass.ConvertIntTo2BytesBE(csum); sb.AddRange(bcsum); // 2B serial.Write(sb.ToArray(), 0, sb.Count); }
private void FetchHeaders(byte[] b) { // Check checksum and remove from message ChecksumClass cs = new ChecksumClass(); if (cs.VerifyChecksumFromReceivedMessage(b)) { Console.WriteLine("CHECKSUM MATCH"); } else { Console.WriteLine("CHECKSUM DONT MATCH"); return; } var newArr = UARTHelperClass.RemoveChecksumFromMessage(b); ByteArrayDecoderClass decoder = new ByteArrayDecoderClass(newArr); decoder.Get2BytesAsInt(); // Remove first 2 values (number of data transmited) int[] timestamp = decoder.Get6BytesAsTimestamp(); int prescaler = decoder.Get4BytesAsInt(); int numOfPoints = decoder.Get2BytesAsInt(); int operatingMode = decoder.Get1ByteAsInt(); int channelMode = decoder.Get1ByteAsInt(); // Fill header with remaining data headers[currentHeader].timestamp = timestamp; headers[currentHeader].prescaler = prescaler; headers[currentHeader].numOfPoints = numOfPoints; headers[currentHeader].operatingMode = operatingMode; headers[currentHeader].channel = channelMode; headers[currentHeader].ready = true; // Fill labels FillLabelGroup(currentHeader, headers[currentHeader].headerAddress, timestamp, prescaler, numOfPoints, operatingMode, channelMode); uartReceiver.Reset(); currentHeader++; if (currentHeader == headers.Count) // Last time in here, reset everything { processFunction = Dummy; return; } #warning Update to use CommandFormerClass // Send command to get measurement header List <byte> sb = new List <byte>(); sb.Add(startSeq); sb.Add(deviceAddr); // Append message length and include checksum sb.Add(0); sb.Add(9); // Append command sb.Add(commandRead); // Get and append address byte[] bAddress = CustomConvertorClass.ConvertIntTo4Bytes(headers[currentHeader].headerAddress); sb.AddRange(bAddress); // Get and append length byte[] bLen = CustomConvertorClass.ConvertIntTo2Bytes(HEADER_LENGTH); sb.AddRange(bLen); Thread.Sleep(50); //Console.WriteLine("FetchHeaders -- sending " + sb.Count); // Now calculate and append checksum UInt16 csum = ChecksumClass.CalculateChecksum(sb.ToArray()); byte[] bcsum = CustomConvertorClass.ConvertIntTo2BytesBE(csum); sb.AddRange(bcsum); // 2B serial.Write(sb.ToArray(), 0, sb.Count); }
/// <summary> /// Measurement info is received, decode data and send requests to read measurement headers /// </summary> /// <param name="b"></param> private void ProcessGetMeasurementInfo(byte[] b) { // Check checksum and remove from message ChecksumClass cs = new ChecksumClass(); if (cs.VerifyChecksumFromReceivedMessage(b)) { Console.WriteLine("CHECKSUM MATCH"); } else { Console.WriteLine("CHECKSUM DONT MATCH"); return; } var newArr = UARTHelperClass.RemoveChecksumFromMessage(b); ByteArrayDecoderClass decoder = new ByteArrayDecoderClass(newArr); decoder.Get2BytesAsInt(); // Remove first 2 values (number of data transmited) EraseLabels(); // Get number of measurements and their header starting addresses int numOfMeasurements = decoder.Get2BytesAsInt(); Console.WriteLine("Number of measurements: " + numOfMeasurements); if (numOfMeasurements == 0) { // if no measurements leave it as it is processFunction = Dummy; return; } headers = new List <MeasurementHeaderClass>(); // Reset headers list for (int i = 0; i < numOfMeasurements; i++) { headers.Add(new MeasurementHeaderClass(decoder.Get4BytesAsInt())); } // Reset UART receiver and set new method for data processing uartReceiver.Reset(); processFunction = FetchHeaders; currentHeader = 0; // Reset header index // Bootstrap #warning Update to use CommandFormerClass // Send command to get measurement header List <byte> sb = new List <byte>(); sb.Add(startSeq); sb.Add(deviceAddr); // Append message length sb.Add(0); sb.Add(9); // Append command sb.Add(commandRead); // Get and append address byte[] bAddress = CustomConvertorClass.ConvertIntTo4Bytes(headers[0].headerAddress); sb.AddRange(bAddress); // Get and append length byte[] bLen = CustomConvertorClass.ConvertIntTo2Bytes(HEADER_LENGTH); sb.AddRange(bLen); //Thread.Sleep(200); //Console.WriteLine("ProcessGetMeasurementInfo --sending " + sb.Count); // Now calculate and append checksum UInt16 csum = ChecksumClass.CalculateChecksum(sb.ToArray()); byte[] bcsum = CustomConvertorClass.ConvertIntTo2BytesBE(csum); sb.AddRange(bcsum); // 2B serial.Write(sb.ToArray(), 0, sb.Count); }
public void AppendWaitForMs(UInt32 ms) { bl.Add(3); bl.AddRange(CustomConvertorClass.ConvertIntTo4Bytes(ms)); }