Well this is what I did .. i might look into a struct though ..
then i'm using it like soCode:public class Dw // dont write { // basic defines public const int RX_PacketSZ = 15; // rx packet size 15 for 16 public const int TX_PacketSZ = 15; // packet size we transmit public const string RXHeader = "11"; // receiverID,senderID // indexes of rx packet hence 'i' public const int RXi_ServerID = 0; public const int RXi_JinxID = 1; public const int RXi_Flags = 2; public const int RXi_Number = 3; // indexes of tx packet hence 'i' public const int TXi_JinxID = 0; public const int TXi_ServerID = 1; public const int TXi_Flags = 2; public const int TXi_Number = 3; public const int TXi_Direction = 4; public const int TXi_Speed = 5; public const int TXi_Reserved = 6; // masks for the flags public const byte Mask_Battery = 0x01; public const byte Mask_Accel = 0x02; public const byte Mask_Sonar = 0x04; public const byte Mask_Line = 0x08; public const byte Mask_Gps = 0x10; public const byte Mask_Move = 0x20; public const byte Mask_Test = 0x33; // bytes for movement public const byte Move_Forward = 0x01; public const byte Move_Backward = 0x02; public const byte Move_Left = 0x03; public const byte Move_Right = 0x04; }
seems to be working pretty well ... no casting at leastCode:public void sendTXPacket() { if (_serialPort != null && _serialPort.IsOpen) { if(currentTXPacket[Dw.TXi_Number] < 255){ currentTXPacket[Dw.TXi_Number]++; _serialPort.Write(currentTXPacket,0,Dw.TX_PacketSZ); }else{ currentTXPacket[Dw.TXi_Number] = 0x00; currentTXPacket[Dw.TXi_Number]++; _serialPort.Write(currentTXPacket, 0, Dw.TX_PacketSZ); } } else { Console.WriteLine("serial port not ready"); } }




Reply With Quote