//************************ //************************ // create a new com connection private void connect(spp_COMPorts cport, spp_BaudRates brate) { comport.BaudRate = baud_rate_array[(int)brate]; comport.DataBits = spp_DataBits; comport.StopBits = (StopBits)stop_bits_array[(int)spp_StopBits.STOPBIT_ONE]; comport.Parity = (Parity)parity_array[(int)spp_Parity.PARITY_NONE]; comport.PortName = portname_array[(int)cport]; comport.ReadBufferSize = MAX_RS232_BUFFER_SZ; comport.WriteBufferSize = MAX_RS232_BUFFER_SZ; // set up the latch comport.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived); try { comport.Open(); } catch { // debug MessageBox.Show("Cannot open comport."); } //debug_frm.display_string("CONNECT\n\r\n\r"); }
//************************ //************************ // create a new com connection private void connect( spp_COMPorts cport, spp_BaudRates brate) { comport.BaudRate = baud_rate_array[(int)brate]; comport.DataBits = spp_DataBits; comport.StopBits = (StopBits)stop_bits_array[(int)spp_StopBits.STOPBIT_ONE]; comport.Parity = (Parity)parity_array[(int)spp_Parity.PARITY_NONE]; comport.PortName = portname_array[(int)cport]; comport.ReadBufferSize = MAX_RS232_BUFFER_SZ; comport.WriteBufferSize = MAX_RS232_BUFFER_SZ; // set up the latch comport.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived); try { comport.Open(); } catch { // debug MessageBox.Show("Cannot open comport."); } //debug_frm.display_string("CONNECT\n\r\n\r"); }
//protocol_test.Form1 frm1) //************************ //************************ // default constructor // arguments: // PORT NAME: spp_COMPorts.PORT_COM3 (example) // BAUD RATE: spp_BaudRates.BAUD_9600 (example) public packet_protocol( spp_COMPorts cport, spp_BaudRates brate) { //******************************** // Queue to store incoming packets from XMega rx_packet_queue = new Queue(MAX_QUEUE_SZ); //******************************** // set up for DEBUG //debug_frm = frm1; //debug_frm.display_string("DEBUG MODE.\n\r\n\r"); //******************************** // set up the baud rates int BaudRate_count = Enum.GetValues(typeof(spp_BaudRates)).Length; baud_rate_array = new int[BaudRate_count]; //******************************** // clean the buffer that stores the // incoming packet clean_gen_buffer(); baud_rate_array[(int)spp_BaudRates.BAUD_2400] = 2400; baud_rate_array[(int)spp_BaudRates.BAUD_4800] = 4800; baud_rate_array[(int)spp_BaudRates.BAUD_9600] = 9600; baud_rate_array[(int)spp_BaudRates.BAUD_19200] = 19200; baud_rate_array[(int)spp_BaudRates.BAUD_28800] = 28800; baud_rate_array[(int)spp_BaudRates.BAUD_57600] = 57600; baud_rate_array[(int)spp_BaudRates.BAUD_115200] = 115200; baud_rate_array[(int)spp_BaudRates.BAUD_230400] = 230400; //******************************** // set up the stop bits int StopBits_count = Enum.GetValues(typeof(spp_StopBits)).Length; stop_bits_array = new int[StopBits_count]; stop_bits_array[(int)spp_StopBits.STOPBIT_NONE] = (int)spp_StopBits.STOPBIT_NONE; stop_bits_array[(int)spp_StopBits.STOPBIT_ONE] = (int)spp_StopBits.STOPBIT_ONE; stop_bits_array[(int)spp_StopBits.STOPBIT_TWO] = (int)spp_StopBits.STOPBIT_TWO; stop_bits_array[(int)spp_StopBits.STOPBIT_ONEPOINTFIVE] = (int)spp_StopBits.STOPBIT_ONEPOINTFIVE; //******************************** // set up the parity int Parity_count = Enum.GetValues(typeof(spp_Parity)).Length; parity_array = new int[Parity_count]; parity_array[(int)spp_Parity.PARITY_NONE] = (int)spp_Parity.PARITY_NONE; parity_array[(int)spp_Parity.PARITY_ODD] = (int)spp_Parity.PARITY_ODD; parity_array[(int)spp_Parity.PARITY_EVEN] = (int)spp_Parity.PARITY_EVEN; parity_array[(int)spp_Parity.PARITY_MARK] = (int)spp_Parity.PARITY_MARK; parity_array[(int)spp_Parity.PARITY_SPACE] = (int)spp_Parity.PARITY_SPACE; //******************************** // set up the portname int PortName_count = Enum.GetValues(typeof(spp_COMPorts)).Length; portname_array = new string[PortName_count]; portname_array[(int)spp_COMPorts.PORT_COM1] = "COM1"; portname_array[(int)spp_COMPorts.PORT_COM2] = "COM2"; portname_array[(int)spp_COMPorts.PORT_COM3] = "COM3"; portname_array[(int)spp_COMPorts.PORT_COM4] = "COM4"; portname_array[(int)spp_COMPorts.PORT_COM5] = "COM5"; portname_array[(int)spp_COMPorts.PORT_COM6] = "COM6"; portname_array[(int)spp_COMPorts.PORT_COM7] = "COM7"; // Connect to the serial port connect(cport, brate); }
//************************ //************************ // default constructor // arguments: // PORT NAME: spp_COMPorts.PORT_COM3 (example) // BAUD RATE: spp_BaudRates.BAUD_9600 (example) public packet_protocol(spp_COMPorts cport, spp_BaudRates brate) //protocol_test.Form1 frm1) { //******************************** // Queue to store incoming packets from XMega rx_packet_queue = new Queue(MAX_QUEUE_SZ); //******************************** // set up for DEBUG //debug_frm = frm1; //debug_frm.display_string("DEBUG MODE.\n\r\n\r"); //******************************** // set up the baud rates int BaudRate_count = Enum.GetValues(typeof(spp_BaudRates)).Length; baud_rate_array = new int[BaudRate_count]; //******************************** // clean the buffer that stores the // incoming packet clean_gen_buffer(); baud_rate_array[(int)spp_BaudRates.BAUD_2400] = 2400; baud_rate_array[(int)spp_BaudRates.BAUD_4800] = 4800; baud_rate_array[(int)spp_BaudRates.BAUD_9600] = 9600; baud_rate_array[(int)spp_BaudRates.BAUD_19200] = 19200; baud_rate_array[(int)spp_BaudRates.BAUD_28800] = 28800; baud_rate_array[(int)spp_BaudRates.BAUD_57600] = 57600; baud_rate_array[(int)spp_BaudRates.BAUD_115200] = 115200; baud_rate_array[(int)spp_BaudRates.BAUD_230400] = 230400; //******************************** // set up the stop bits int StopBits_count = Enum.GetValues(typeof(spp_StopBits)).Length; stop_bits_array = new int[StopBits_count]; stop_bits_array[(int)spp_StopBits.STOPBIT_NONE] = (int)spp_StopBits.STOPBIT_NONE; stop_bits_array[(int)spp_StopBits.STOPBIT_ONE] = (int)spp_StopBits.STOPBIT_ONE; stop_bits_array[(int)spp_StopBits.STOPBIT_TWO] = (int)spp_StopBits.STOPBIT_TWO; stop_bits_array[(int)spp_StopBits.STOPBIT_ONEPOINTFIVE] = (int)spp_StopBits.STOPBIT_ONEPOINTFIVE; //******************************** // set up the parity int Parity_count = Enum.GetValues(typeof(spp_Parity)).Length; parity_array = new int[Parity_count]; parity_array[(int)spp_Parity.PARITY_NONE] = (int)spp_Parity.PARITY_NONE; parity_array[(int)spp_Parity.PARITY_ODD] = (int)spp_Parity.PARITY_ODD; parity_array[(int)spp_Parity.PARITY_EVEN] = (int)spp_Parity.PARITY_EVEN; parity_array[(int)spp_Parity.PARITY_MARK] = (int)spp_Parity.PARITY_MARK; parity_array[(int)spp_Parity.PARITY_SPACE] = (int)spp_Parity.PARITY_SPACE; //******************************** // set up the portname int PortName_count = Enum.GetValues(typeof(spp_COMPorts)).Length; portname_array = new string[PortName_count]; portname_array[(int)spp_COMPorts.PORT_COM1] = "COM1"; portname_array[(int)spp_COMPorts.PORT_COM2] = "COM2"; portname_array[(int)spp_COMPorts.PORT_COM3] = "COM3"; portname_array[(int)spp_COMPorts.PORT_COM4] = "COM4"; portname_array[(int)spp_COMPorts.PORT_COM5] = "COM5"; portname_array[(int)spp_COMPorts.PORT_COM6] = "COM6"; portname_array[(int)spp_COMPorts.PORT_COM7] = "COM7"; // Connect to the serial port connect(cport, brate); }