//private static void workerSEND_DoWork(object sender, DoWorkEventArgs e) private static void workerSEND_DoWork() { C_Packet thisInstructionPacket; lock (spiSent_locker) { if (spi.IsOpen == true) { //spi.DiscardInBuffer(); // spi.DiscardOutBuffer(); } lock (queueToSent_locker) { if (queueToSent.Count > 0) { thisInstructionPacket = queueToSent.Dequeue(); if (C_SPI.WRITE_instructionPacket(thisInstructionPacket) == false) { LOG_err(string.Format( "Cannot open the serial port {0}. Tried [{1}]-times", spi.PortName, openConnection.ValDef )); return; } } else { return; } spi.DiscardOutBuffer(); } } }
public static void ACTUALIZE_motorRegistersFromStatusPacket(C_Packet received, C_Packet pairedLastSent) { try { if (received.byteId == pairedLastSent.byteId) { // we have no error in statusPacket if (pairedLastSent.byteInstructionOrError == C_DynAdd.INS_WRITE) { // actualize the parameters which were written into motors - and we know they were written good C_MotorControl.ACTUALIZE_motorRegister( pairedLastSent.rotMotor, e_regByteType.seenValue, // as we received statusMessage after we written the value pairedLastSent.Par); } else if (pairedLastSent.byteInstructionOrError == C_DynAdd.INS_READ) { // actualize the parameters which were read from motors C_MotorControl.ACTUALIZE_motorRegister( pairedLastSent.rotMotor, e_regByteType.seenValue, C_CONV.listOfObjects2listOfBytes(new List <object>() { pairedLastSent.Par[0], received.Par }) ); } else { C_SPI.LOG_debug(string.Format( "lastSent packet: {0}\nPaired with: {1}\n{2}", pairedLastSent.PacketBytes_toString, received.PacketBytes_toString, "wasn't read neither write and yet still it was supposed to be processed as a statusPacket. Not processing!" )); } } else { LOG_statusPacket(string.Format( "The received status packet :\t{0}\nDoes not belong to the lastSent: \t{1}", received.PacketBytes_toString, pairedLastSent.PacketBytes_toString )); } } catch (Exception e) { C_SPI.LOG_debug("tak tady to padá! " + e.Message); } }
public static void ACTUALIZE_queueCounts(List <Queue <C_Packet> > queueSent) { foreach (C_Motor mot in M) { //queueSent_Count[rotMot] = listSent.Count; mot.packetsInLastSent = C_SPI.queueSent_Count[(int)mot.rotMotor]; } C_SPI.LOG_debug(string.Format( "queueSent[ yaw=[{0}]; pitch=[{1}]; roll=[{2}] ]", GET_M(e_rot.yaw).packetsInLastSent, GET_M(e_rot.pitch).packetsInLastSent, GET_M(e_rot.roll).packetsInLastSent )); MainWindow.REFRESH_motorData(); }
public static bool PROCESS_statusPacket(C_Packet status, C_Packet pairedLastSent) { // no echo should get here (FIND_bestPairInQueue) sort it out if (status.IS_error() == true) // status is consistent and correct, but may have error { C_SPI.LOG_debug("The processed package has an error! : " + status.PacketBytes_toString); } else { C_SPI.LOG_debug("The processed package does not contain any error, going to process statusPacket"); ACTUALIZE_motorRegistersFromStatusPacket(status, pairedLastSent); C_SPI.LOG_debug("Status packet processing ended"); } return(true); }
public static void ACTUALIZE_motorRegister(e_rot rot, e_regByteType type, List <byte> pars) { if (pars.Count > 0) { byte addressByte = pars[0]; byte[] parValues = pars.Skip(1).ToArray(); C_Packet.LOG_statusPacket(string.Format( "Status OK - actualizing mot[{0}] register type[{1}]: From address[{2}]=[{3}], these values[{4}]", rot, type, addressByte, MainWindow.Ms[rot].Reg.GET_name(addressByte), C_CONV.byteArray2strHex_space(parValues))); foreach (byte byteValue in parValues) { C_SPI.LOG_unimportant(string.Format( "going to acualize mot[{0}] register on address [{1}]", rot, addressByte )); MainWindow.Ms[rot].ACTUALIZE_register(addressByte, byteValue, type); addressByte++; } } }
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% #endregion RESET //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% #region static functions //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% public static void SEND_packet(C_Packet packet) { C_SPI.SEND_data(packet); }
private void btnSPIClose_Click(object sender, RoutedEventArgs e) { C_SPI.CLOSE_connection(); }
private void btnSPIConnect_Click(object sender, RoutedEventArgs e) { C_SPI.OPEN_connection(); //System.Windows.MessageBox.Show(C_State.Spi.ToString()); }