public DataJson ReadJson(ISerialPort port) { // "{ \"sensNr\":1,\"instNr\":13,\"bRet\":20,\"data\":[48756080,2302038]}" return(JsonConvert.DeserializeObject <DataJson>(port.ReadLine())); //File.ReadAllText(@"D:\HBO\Semester 4\PTT\jsontekst2.json") //// deserialize JSON directly from a file //using (StreamReader file = File.OpenText(@"D:\HBO\Semester 4\PTT\jsontekst.json")) //{ // JsonSerializer serializer = new JsonSerializer(); // return (Sent)serializer.Deserialize(file, typeof(Sent)); //} }
public void SetVoltage(double voltageInVolt) { if (voltageInVolt < 0.0 || voltageInVolt > 30.0) { throw new ArgumentOutOfRangeException(nameof(voltageInVolt), $"Voltage must be between {0.0} and {30.0}V."); } string sendText = string.Format("SV{000}", voltageInVolt * 10); _serialPort.WriteLine(string.Format(sendText)); string receivedText = _serialPort.ReadLine(); int status = int.Parse(receivedText); if (status != 0) { throw new ErrorNumberException(status); } }
public void SerialInputWork(string file) { string serialLine = serialPort.ReadLine(); if (serialLine.StartsWith("I2C")) { if (Properties.Settings.Default.RawInput) { AddInfo(serialLine); File.AppendAllText(Properties.Settings.Default.MockSerialData, serialLine); } string[] splittedRow = serialLine.Split(' '); int pos = int.Parse(serialLine.ElementAt(3).ToString()); pos = pos ^ 1; // IC2 no 1 is on left side for (int i = 0; i < SENSOR_COLUMS; i++) { for (int j = 0; j < SENSOR_COLUMS; j++) { int l = (((i + 1) * SENSOR_COLUMS - 1 - j) << 1) + 3; serialInputRow[((i << 1) + pos) * SENSOR_COLUMS + j] = int.Parse(splittedRow[l], NumberStyles.AllowHexSpecifier) + (int.Parse(splittedRow[l + 1], NumberStyles.AllowHexSpecifier) << 8); } } if (pos == 0) { if (Properties.Settings.Default.OpenInput) { AddInfo(string.Join(",", serialInputRow)); } DateTime dtNow = DateTime.Now; if (dtNow.Second != secondCounter) { secondCounter = dtNow.Second; if (IsTraining()) { DoMachineLearning(serialInputRow, file, false); } if (IsPredicting()) { DoMachineLearning(serialInputRow, string.Empty, true); } if (sleepMonitoring) { SleepMonitoring(); } if (temperatureToolStripMenuItem.Checked) { GetTemperatures(serialInputRow); } for (int i = 0; i < SENSOR_COLUMS; i++) { for (int j = 0; j < (SENSOR_COLUMS * 2); j++) { UpdateMatrix(MatrixType.BlackAndWhite, j, i, serialInputRow[i * 8 + j]); UpdateMatrix(MatrixType.Colored, j, i, serialInputRow[i * 8 + j]); UpdateMatrix(MatrixType.Numeric, j, i, serialInputRow[i * 8 + j]); } } } } } }
public string ReadPort() { return(_serialPort.ReadLine()); }